pdfdancer-client-typescript 1.0.1

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.
Files changed (52) hide show
  1. package/.eslintrc.js +19 -0
  2. package/README.md +267 -0
  3. package/dist/__tests__/e2e/test-helpers.d.ts +32 -0
  4. package/dist/__tests__/e2e/test-helpers.d.ts.map +1 -0
  5. package/dist/__tests__/e2e/test-helpers.js +157 -0
  6. package/dist/__tests__/e2e/test-helpers.js.map +1 -0
  7. package/dist/client-v1.d.ts +169 -0
  8. package/dist/client-v1.d.ts.map +1 -0
  9. package/dist/client-v1.js +558 -0
  10. package/dist/client-v1.js.map +1 -0
  11. package/dist/exceptions.d.ts +43 -0
  12. package/dist/exceptions.d.ts.map +1 -0
  13. package/dist/exceptions.js +66 -0
  14. package/dist/exceptions.js.map +1 -0
  15. package/dist/index.d.ts +13 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +33 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/models.d.ts +216 -0
  20. package/dist/models.d.ts.map +1 -0
  21. package/dist/models.js +427 -0
  22. package/dist/models.js.map +1 -0
  23. package/dist/paragraph-builder.d.ts +67 -0
  24. package/dist/paragraph-builder.d.ts.map +1 -0
  25. package/dist/paragraph-builder.js +160 -0
  26. package/dist/paragraph-builder.js.map +1 -0
  27. package/example.ts +103 -0
  28. package/fixtures/DancingScript-Regular.ttf +0 -0
  29. package/fixtures/JetBrainsMono-Regular.ttf +0 -0
  30. package/fixtures/ObviouslyAwesome.pdf +0 -0
  31. package/fixtures/README.md +25 -0
  32. package/fixtures/basic-paths.pdf +0 -0
  33. package/fixtures/logo-80.png +0 -0
  34. package/fixtures/mixed-form-types.pdf +0 -0
  35. package/jest.config.js +26 -0
  36. package/package.json +38 -0
  37. package/scripts/release.js +91 -0
  38. package/scripts/test-release.js +59 -0
  39. package/src/__tests__/client-v1.test.ts +111 -0
  40. package/src/__tests__/e2e/form.test.ts +51 -0
  41. package/src/__tests__/e2e/image.test.ts +108 -0
  42. package/src/__tests__/e2e/line.test.ts +134 -0
  43. package/src/__tests__/e2e/page.test.ts +45 -0
  44. package/src/__tests__/e2e/paragraph.test.ts +210 -0
  45. package/src/__tests__/e2e/path.test.ts +72 -0
  46. package/src/__tests__/e2e/test-helpers.ts +132 -0
  47. package/src/client-v1.ts +673 -0
  48. package/src/exceptions.ts +67 -0
  49. package/src/index.ts +34 -0
  50. package/src/models.ts +476 -0
  51. package/src/paragraph-builder.ts +184 -0
  52. package/tsconfig.json +20 -0
package/dist/models.js ADDED
@@ -0,0 +1,427 @@
1
+ "use strict";
2
+ /**
3
+ * Model classes for the PDFDancer TypeScript client.
4
+ * Closely mirrors the Python model classes with TypeScript conventions.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ModifyTextRequest = exports.ModifyRequest = exports.AddRequest = exports.MoveRequest = exports.DeleteRequest = exports.FindRequest = exports.Paragraph = exports.Image = exports.Font = exports.Color = exports.ObjectRef = exports.Position = exports.BoundingRect = exports.ShapeType = exports.PositionMode = exports.ObjectType = void 0;
8
+ /**
9
+ * Object type enumeration matching the Python ObjectType.
10
+ */
11
+ var ObjectType;
12
+ (function (ObjectType) {
13
+ ObjectType["IMAGE"] = "IMAGE";
14
+ ObjectType["FORM"] = "FORM";
15
+ ObjectType["PATH"] = "PATH";
16
+ ObjectType["PARAGRAPH"] = "PARAGRAPH";
17
+ ObjectType["TEXT_LINE"] = "TEXT_LINE";
18
+ ObjectType["PAGE"] = "PAGE";
19
+ })(ObjectType || (exports.ObjectType = ObjectType = {}));
20
+ /**
21
+ * Defines how position matching should be performed when searching for objects.
22
+ */
23
+ var PositionMode;
24
+ (function (PositionMode) {
25
+ PositionMode["INTERSECT"] = "INTERSECT";
26
+ PositionMode["CONTAINS"] = "CONTAINS"; // Objects completely contained within the specified position area
27
+ })(PositionMode || (exports.PositionMode = PositionMode = {}));
28
+ /**
29
+ * Defines the geometric shape type used for position specification.
30
+ */
31
+ var ShapeType;
32
+ (function (ShapeType) {
33
+ ShapeType["POINT"] = "POINT";
34
+ ShapeType["LINE"] = "LINE";
35
+ ShapeType["CIRCLE"] = "CIRCLE";
36
+ ShapeType["RECT"] = "RECT"; // Rectangular area with width and height
37
+ })(ShapeType || (exports.ShapeType = ShapeType = {}));
38
+ /**
39
+ * Represents a bounding rectangle with position and dimensions.
40
+ * Matches the Python BoundingRect class.
41
+ */
42
+ class BoundingRect {
43
+ constructor(x, y, width, height) {
44
+ this.x = x;
45
+ this.y = y;
46
+ this.width = width;
47
+ this.height = height;
48
+ }
49
+ getX() {
50
+ return this.x;
51
+ }
52
+ getY() {
53
+ return this.y;
54
+ }
55
+ getWidth() {
56
+ return this.width;
57
+ }
58
+ getHeight() {
59
+ return this.height;
60
+ }
61
+ }
62
+ exports.BoundingRect = BoundingRect;
63
+ /**
64
+ * Represents spatial positioning and location information for PDF objects.
65
+ * Closely mirrors the Python Position class with TypeScript conventions.
66
+ */
67
+ class Position {
68
+ constructor(pageIndex, shape, mode, boundingRect, textStartsWith) {
69
+ this.pageIndex = pageIndex;
70
+ this.shape = shape;
71
+ this.mode = mode;
72
+ this.boundingRect = boundingRect;
73
+ this.textStartsWith = textStartsWith;
74
+ }
75
+ /**
76
+ * Creates a position specification for an entire page.
77
+ * Equivalent to Position.fromPageIndex() in Python.
78
+ */
79
+ static fromPageIndex(pageIndex) {
80
+ return new Position(pageIndex, undefined, PositionMode.CONTAINS);
81
+ }
82
+ /**
83
+ * Creates a position specification for specific coordinates on a page.
84
+ * Equivalent to Position.onPageCoordinates() in Python.
85
+ */
86
+ static onPageCoordinates(pageIndex, x, y) {
87
+ const position = Position.fromPageIndex(pageIndex);
88
+ position.setPoint({ x, y });
89
+ return position;
90
+ }
91
+ /**
92
+ * Sets the position to a specific point location.
93
+ * Equivalent to Position.set() in Python.
94
+ */
95
+ setPoint(point) {
96
+ this.mode = PositionMode.CONTAINS;
97
+ this.shape = ShapeType.POINT;
98
+ this.boundingRect = new BoundingRect(point.x, point.y, 0, 0);
99
+ }
100
+ /**
101
+ * Move the position horizontally by the specified offset.
102
+ */
103
+ moveX(xOffset) {
104
+ if (this.boundingRect) {
105
+ this.setPoint({ x: this.getX() + xOffset, y: this.getY() });
106
+ }
107
+ return this;
108
+ }
109
+ /**
110
+ * Move the position vertically by the specified offset.
111
+ */
112
+ moveY(yOffset) {
113
+ if (this.boundingRect) {
114
+ this.setPoint({ x: this.getX(), y: this.getY() + yOffset });
115
+ }
116
+ return this;
117
+ }
118
+ /**
119
+ * Returns the X coordinate of this position.
120
+ */
121
+ getX() {
122
+ return this.boundingRect?.getX();
123
+ }
124
+ /**
125
+ * Returns the Y coordinate of this position.
126
+ */
127
+ getY() {
128
+ return this.boundingRect?.getY();
129
+ }
130
+ /**
131
+ * Creates a copy of this position.
132
+ */
133
+ copy() {
134
+ let boundingRectCopy;
135
+ if (this.boundingRect) {
136
+ boundingRectCopy = new BoundingRect(this.boundingRect.x, this.boundingRect.y, this.boundingRect.width, this.boundingRect.height);
137
+ }
138
+ return new Position(this.pageIndex, this.shape, this.mode, boundingRectCopy, this.textStartsWith);
139
+ }
140
+ }
141
+ exports.Position = Position;
142
+ /**
143
+ * Lightweight reference to a PDF object providing identity and type information.
144
+ * Mirrors the Python ObjectRef class exactly.
145
+ */
146
+ class ObjectRef {
147
+ constructor(internalId, position, type) {
148
+ this.internalId = internalId;
149
+ this.position = position;
150
+ this.type = type;
151
+ }
152
+ getInternalId() {
153
+ return this.internalId;
154
+ }
155
+ getPosition() {
156
+ return this.position;
157
+ }
158
+ setPosition(position) {
159
+ this.position = position;
160
+ }
161
+ getType() {
162
+ return this.type;
163
+ }
164
+ toDict() {
165
+ return {
166
+ internalId: this.internalId,
167
+ position: positionToDict(this.position),
168
+ type: this.type
169
+ };
170
+ }
171
+ }
172
+ exports.ObjectRef = ObjectRef;
173
+ /**
174
+ * Represents an RGB color with optional alpha channel, values from 0-255.
175
+ */
176
+ class Color {
177
+ constructor(r, g, b, a = 255 // Alpha channel, default fully opaque
178
+ ) {
179
+ this.r = r;
180
+ this.g = g;
181
+ this.b = b;
182
+ this.a = a;
183
+ // Validation similar to Python client
184
+ for (const component of [this.r, this.g, this.b, this.a]) {
185
+ if (component < 0 || component > 255) {
186
+ throw new Error(`Color component must be between 0 and 255, got ${component}`);
187
+ }
188
+ }
189
+ }
190
+ }
191
+ exports.Color = Color;
192
+ /**
193
+ * Represents a font with name and size.
194
+ */
195
+ class Font {
196
+ constructor(name, size) {
197
+ this.name = name;
198
+ this.size = size;
199
+ if (this.size <= 0) {
200
+ throw new Error(`Font size must be positive, got ${this.size}`);
201
+ }
202
+ }
203
+ }
204
+ exports.Font = Font;
205
+ /**
206
+ * Represents an image object in a PDF document.
207
+ * Matches the Python Image class structure.
208
+ */
209
+ class Image {
210
+ constructor(position, format, width, height, data) {
211
+ this.position = position;
212
+ this.format = format;
213
+ this.width = width;
214
+ this.height = height;
215
+ this.data = data;
216
+ }
217
+ getPosition() {
218
+ return this.position;
219
+ }
220
+ setPosition(position) {
221
+ this.position = position;
222
+ }
223
+ }
224
+ exports.Image = Image;
225
+ /**
226
+ * Represents a paragraph of text in a PDF document.
227
+ * Structure mirrors the Python Paragraph class.
228
+ */
229
+ class Paragraph {
230
+ constructor(position, textLines, font, color, lineSpacing = 1.2) {
231
+ this.position = position;
232
+ this.textLines = textLines;
233
+ this.font = font;
234
+ this.color = color;
235
+ this.lineSpacing = lineSpacing;
236
+ }
237
+ getPosition() {
238
+ return this.position;
239
+ }
240
+ setPosition(position) {
241
+ this.position = position;
242
+ }
243
+ }
244
+ exports.Paragraph = Paragraph;
245
+ // Request classes for API communication
246
+ /**
247
+ * Request object for find operations.
248
+ */
249
+ class FindRequest {
250
+ constructor(objectType, position, hint) {
251
+ this.objectType = objectType;
252
+ this.position = position;
253
+ this.hint = hint;
254
+ }
255
+ toDict() {
256
+ return {
257
+ objectType: this.objectType || null,
258
+ position: this.position ? positionToDict(this.position) : null,
259
+ hint: this.hint || null
260
+ };
261
+ }
262
+ }
263
+ exports.FindRequest = FindRequest;
264
+ /**
265
+ * Request object for delete operations.
266
+ */
267
+ class DeleteRequest {
268
+ constructor(objectRef) {
269
+ this.objectRef = objectRef;
270
+ }
271
+ toDict() {
272
+ return {
273
+ objectRef: {
274
+ internalId: this.objectRef.internalId,
275
+ position: positionToDict(this.objectRef.position),
276
+ type: this.objectRef.type
277
+ }
278
+ };
279
+ }
280
+ }
281
+ exports.DeleteRequest = DeleteRequest;
282
+ /**
283
+ * Request object for move operations.
284
+ */
285
+ class MoveRequest {
286
+ constructor(objectRef, position) {
287
+ this.objectRef = objectRef;
288
+ this.position = position;
289
+ }
290
+ toDict() {
291
+ return {
292
+ objectRef: {
293
+ internalId: this.objectRef.internalId,
294
+ position: positionToDict(this.objectRef.position),
295
+ type: this.objectRef.type
296
+ },
297
+ newPosition: positionToDict(this.position)
298
+ };
299
+ }
300
+ }
301
+ exports.MoveRequest = MoveRequest;
302
+ /**
303
+ * Request object for add operations.
304
+ */
305
+ class AddRequest {
306
+ constructor(pdfObject) {
307
+ this.pdfObject = pdfObject;
308
+ }
309
+ toDict() {
310
+ return {
311
+ object: this.objectToDict(this.pdfObject)
312
+ };
313
+ }
314
+ objectToDict(obj) {
315
+ if (obj instanceof Image) {
316
+ const size = obj.width !== undefined && obj.height !== undefined
317
+ ? { width: obj.width, height: obj.height }
318
+ : null;
319
+ const dataB64 = obj.data ? btoa(String.fromCharCode(...obj.data)) : null;
320
+ return {
321
+ type: "IMAGE",
322
+ position: obj.position ? positionToDict(obj.position) : null,
323
+ format: obj.format || null,
324
+ size,
325
+ data: dataB64
326
+ };
327
+ }
328
+ else if (obj instanceof Paragraph) {
329
+ const lines = [];
330
+ if (obj.textLines) {
331
+ for (const line of obj.textLines) {
332
+ const textElement = {
333
+ text: line,
334
+ font: obj.font ? { name: obj.font.name, size: obj.font.size } : null,
335
+ color: obj.color ? { r: obj.color.r, g: obj.color.g, b: obj.color.b } : null,
336
+ position: obj.position ? positionToDict(obj.position) : null
337
+ };
338
+ const textLine = {
339
+ textElements: [textElement]
340
+ };
341
+ if (obj.color) {
342
+ textLine.color = { r: obj.color.r, g: obj.color.g, b: obj.color.b };
343
+ }
344
+ if (obj.position) {
345
+ textLine.position = positionToDict(obj.position);
346
+ }
347
+ lines.push(textLine);
348
+ }
349
+ }
350
+ const lineSpacings = obj.lineSpacing !== undefined ? [obj.lineSpacing] : null;
351
+ return {
352
+ type: "PARAGRAPH",
353
+ position: obj.position ? positionToDict(obj.position) : null,
354
+ lines,
355
+ lineSpacings,
356
+ font: obj.font ? { name: obj.font.name, size: obj.font.size } : null
357
+ };
358
+ }
359
+ else {
360
+ throw new Error(`Unsupported object type: ${typeof obj}`);
361
+ }
362
+ }
363
+ }
364
+ exports.AddRequest = AddRequest;
365
+ /**
366
+ * Request object for modify operations.
367
+ */
368
+ class ModifyRequest {
369
+ constructor(objectRef, newObject) {
370
+ this.objectRef = objectRef;
371
+ this.newObject = newObject;
372
+ }
373
+ toDict() {
374
+ return {
375
+ ref: {
376
+ internalId: this.objectRef.internalId,
377
+ position: positionToDict(this.objectRef.position),
378
+ type: this.objectRef.type
379
+ },
380
+ newObject: new AddRequest(this.newObject).toDict().object
381
+ };
382
+ }
383
+ }
384
+ exports.ModifyRequest = ModifyRequest;
385
+ /**
386
+ * Request object for text modification operations.
387
+ */
388
+ class ModifyTextRequest {
389
+ constructor(objectRef, newText) {
390
+ this.objectRef = objectRef;
391
+ this.newText = newText;
392
+ }
393
+ toDict() {
394
+ return {
395
+ ref: {
396
+ internalId: this.objectRef.internalId,
397
+ position: positionToDict(this.objectRef.position),
398
+ type: this.objectRef.type
399
+ },
400
+ newTextLine: this.newText
401
+ };
402
+ }
403
+ }
404
+ exports.ModifyTextRequest = ModifyTextRequest;
405
+ // Helper function to convert Position to dictionary for JSON serialization
406
+ function positionToDict(position) {
407
+ const result = {
408
+ pageIndex: position.pageIndex,
409
+ textStartsWith: position.textStartsWith
410
+ };
411
+ if (position.shape) {
412
+ result.shape = position.shape;
413
+ }
414
+ if (position.mode) {
415
+ result.mode = position.mode;
416
+ }
417
+ if (position.boundingRect) {
418
+ result.boundingRect = {
419
+ x: position.boundingRect.x,
420
+ y: position.boundingRect.y,
421
+ width: position.boundingRect.width,
422
+ height: position.boundingRect.height
423
+ };
424
+ }
425
+ return result;
426
+ }
427
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;GAEG;AACH,IAAY,UAOX;AAPD,WAAY,UAAU;IACpB,6BAAe,CAAA;IACf,2BAAa,CAAA;IACb,2BAAa,CAAA;IACb,qCAAuB,CAAA;IACvB,qCAAuB,CAAA;IACvB,2BAAa,CAAA;AACf,CAAC,EAPW,UAAU,0BAAV,UAAU,QAOrB;AAED;;GAEG;AACH,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,uCAAuB,CAAA;IACvB,qCAAqB,CAAA,CAAI,kEAAkE;AAC7F,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAED;;GAEG;AACH,IAAY,SAKX;AALD,WAAY,SAAS;IACnB,4BAAe,CAAA;IACf,0BAAa,CAAA;IACb,8BAAiB,CAAA;IACjB,0BAAa,CAAA,CAAM,yCAAyC;AAC9D,CAAC,EALW,SAAS,yBAAT,SAAS,QAKpB;AAUD;;;GAGG;AACH,MAAa,YAAY;IACvB,YACS,CAAS,EACT,CAAS,EACT,KAAa,EACb,MAAc;QAHd,MAAC,GAAD,CAAC,CAAQ;QACT,MAAC,GAAD,CAAC,CAAQ;QACT,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAQ;IACpB,CAAC;IAEJ,IAAI;QACF,OAAO,IAAI,CAAC,CAAC,CAAC;IAChB,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,CAAC,CAAC;IAChB,CAAC;IAED,QAAQ;QACN,OAAO,IA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AAQ,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAChC,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC9B,CAAC;IACD,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;QAC1B,MAAM,CAAC,YAAY,GAAG;YACpB,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC1B,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC1B,KAAK,EAAE,QAAQ,CAAC,YAAY,CAAC,KAAK;YAClC,MAAM,EAAE,QAAQ,CAAC,YAAY,CAAC,MAAM;SACrC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * ParagraphBuilder for the PDFDancer TypeScript client.
3
+ * Closely mirrors the Python ParagraphBuilder class with TypeScript conventions.
4
+ */
5
+ import { Paragraph, Font, Color, Position } from './models';
6
+ import type { ClientV1 } from './client-v1';
7
+ /**
8
+ * Builder class for constructing Paragraph objects with fluent interface.
9
+ * Mirrors the Python ParagraphBuilder class exactly.
10
+ */
11
+ export declare class ParagraphBuilder {
12
+ private _client;
13
+ private _paragraph;
14
+ private _lineSpacing;
15
+ private _textColor;
16
+ private _text?;
17
+ private _font?;
18
+ constructor(_client: ClientV1);
19
+ /**
20
+ * Set the text content for the paragraph.
21
+ * Equivalent to fromString() methods in Python ParagraphBuilder.
22
+ */
23
+ fromString(text: string, color?: Color): ParagraphBuilder;
24
+ /**
25
+ * Set the font for the paragraph using an existing Font object.
26
+ * Equivalent to withFont(Font) in Python ParagraphBuilder.
27
+ */
28
+ withFont(font: Font): ParagraphBuilder;
29
+ /**
30
+ * Set the font for the paragraph using a TTF file.
31
+ * Equivalent to withFont(File, double) in Python ParagraphBuilder.
32
+ */
33
+ withFontFile(ttfFile: Uint8Array | File, fontSize: number): Promise<ParagraphBuilder>;
34
+ /**
35
+ * Set the line spacing for the paragraph.
36
+ * Equivalent to withLineSpacing() in Python ParagraphBuilder.
37
+ */
38
+ withLineSpacing(spacing: number): ParagraphBuilder;
39
+ /**
40
+ * Set the text color for the paragraph.
41
+ * Equivalent to withColor() in Python ParagraphBuilder.
42
+ */
43
+ withColor(color: Color): ParagraphBuilder;
44
+ /**
45
+ * Set the position for the paragraph.
46
+ * Equivalent to withPosition() in Python ParagraphBuilder.
47
+ */
48
+ withPosition(position: Position): ParagraphBuilder;
49
+ /**
50
+ * Build and return the final Paragraph object.
51
+ * Equivalent to build() in Python ParagraphBuilder.
52
+ */
53
+ build(): Paragraph;
54
+ /**
55
+ * Register a TTF font with the client and return a Font object.
56
+ * Equivalent to registerTTF() private method in Python ParagraphBuilder.
57
+ */
58
+ private _registerTtf;
59
+ /**
60
+ * Process text into lines for the paragraph.
61
+ * This is a simplified version - the full implementation would handle
62
+ * word wrapping, line breaks, and other text formatting based on the font
63
+ * and paragraph width.
64
+ */
65
+ private _processTextLines;
66
+ }
67
+ //# sourceMappingURL=paragraph-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paragraph-builder.d.ts","sourceRoot":"","sources":["../src/paragraph-builder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;;GAGG;AACH,qBAAa,gBAAgB;IAOf,OAAO,CAAC,OAAO;IAN3B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,KAAK,CAAC,CAAO;gBAED,OAAO,EAAE,QAAQ;IAQrC;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,gBAAgB;IAgBzD;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,gBAAgB;IAStC;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAa3F;;;OAGG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB;IASlD;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,gBAAgB;IASzC;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,gBAAgB;IASlD;;;OAGG;IACH,KAAK,IAAI,SAAS;IAuBlB;;;OAGG;YACW,YAAY;IAS1B;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;CAoB1B"}
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ /**
3
+ * ParagraphBuilder for the PDFDancer TypeScript client.
4
+ * Closely mirrors the Python ParagraphBuilder class with TypeScript conventions.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ParagraphBuilder = void 0;
8
+ const exceptions_1 = require("./exceptions");
9
+ const models_1 = require("./models");
10
+ /**
11
+ * Builder class for constructing Paragraph objects with fluent interface.
12
+ * Mirrors the Python ParagraphBuilder class exactly.
13
+ */
14
+ class ParagraphBuilder {
15
+ constructor(_client) {
16
+ this._client = _client;
17
+ this._lineSpacing = 1.2;
18
+ this._textColor = new models_1.Color(0, 0, 0); // Black by default
19
+ if (!_client) {
20
+ throw new exceptions_1.ValidationException("Client cannot be null");
21
+ }
22
+ this._paragraph = new models_1.Paragraph();
23
+ }
24
+ /**
25
+ * Set the text content for the paragraph.
26
+ * Equivalent to fromString() methods in Python ParagraphBuilder.
27
+ */
28
+ fromString(text, color) {
29
+ if (text === null || text === undefined) {
30
+ throw new exceptions_1.ValidationException("Text cannot be null");
31
+ }
32
+ if (!text.trim()) {
33
+ throw new exceptions_1.ValidationException("Text cannot be empty");
34
+ }
35
+ this._text = text;
36
+ if (color) {
37
+ this._textColor = color;
38
+ }
39
+ return this;
40
+ }
41
+ /**
42
+ * Set the font for the paragraph using an existing Font object.
43
+ * Equivalent to withFont(Font) in Python ParagraphBuilder.
44
+ */
45
+ withFont(font) {
46
+ if (!font) {
47
+ throw new exceptions_1.ValidationException("Font cannot be null");
48
+ }
49
+ this._font = font;
50
+ return this;
51
+ }
52
+ /**
53
+ * Set the font for the paragraph using a TTF file.
54
+ * Equivalent to withFont(File, double) in Python ParagraphBuilder.
55
+ */
56
+ async withFontFile(ttfFile, fontSize) {
57
+ if (!ttfFile) {
58
+ throw new exceptions_1.ValidationException("TTF file cannot be null");
59
+ }
60
+ if (fontSize <= 0) {
61
+ throw new exceptions_1.ValidationException(`Font size must be positive, got ${fontSize}`);
62
+ }
63
+ // Register font and create Font object
64
+ this._font = await this._registerTtf(ttfFile, fontSize);
65
+ return this;
66
+ }
67
+ /**
68
+ * Set the line spacing for the paragraph.
69
+ * Equivalent to withLineSpacing() in Python ParagraphBuilder.
70
+ */
71
+ withLineSpacing(spacing) {
72
+ if (spacing <= 0) {
73
+ throw new exceptions_1.ValidationException(`Line spacing must be positive, got ${spacing}`);
74
+ }
75
+ this._lineSpacing = spacing;
76
+ return this;
77
+ }
78
+ /**
79
+ * Set the text color for the paragraph.
80
+ * Equivalent to withColor() in Python ParagraphBuilder.
81
+ */
82
+ withColor(color) {
83
+ if (!color) {
84
+ throw new exceptions_1.ValidationException("Color cannot be null");
85
+ }
86
+ this._textColor = color;
87
+ return this;
88
+ }
89
+ /**
90
+ * Set the position for the paragraph.
91
+ * Equivalent to withPosition() in Python ParagraphBuilder.
92
+ */
93
+ withPosition(position) {
94
+ if (!position) {
95
+ throw new exceptions_1.ValidationException("Position cannot be null");
96
+ }
97
+ this._paragraph.setPosition(position);
98
+ return this;
99
+ }
100
+ /**
101
+ * Build and return the final Paragraph object.
102
+ * Equivalent to build() in Python ParagraphBuilder.
103
+ */
104
+ build() {
105
+ // Validate required fields
106
+ if (!this._text) {
107
+ throw new exceptions_1.ValidationException("Text must be set before building paragraph");
108
+ }
109
+ if (!this._font) {
110
+ throw new exceptions_1.ValidationException("Font must be set before building paragraph");
111
+ }
112
+ if (!this._paragraph.getPosition()) {
113
+ throw new exceptions_1.ValidationException("Position must be set before building paragraph");
114
+ }
115
+ // Set paragraph properties
116
+ this._paragraph.font = this._font;
117
+ this._paragraph.color = this._textColor;
118
+ this._paragraph.lineSpacing = this._lineSpacing;
119
+ // Process text into lines
120
+ this._paragraph.textLines = this._processTextLines(this._text);
121
+ return this._paragraph;
122
+ }
123
+ /**
124
+ * Register a TTF font with the client and return a Font object.
125
+ * Equivalent to registerTTF() private method in Python ParagraphBuilder.
126
+ */
127
+ async _registerTtf(ttfFile, fontSize) {
128
+ try {
129
+ const fontName = await this._client.registerFont(ttfFile);
130
+ return new models_1.Font(fontName, fontSize);
131
+ }
132
+ catch (error) {
133
+ throw new exceptions_1.ValidationException(`Failed to register font file: ${error}`);
134
+ }
135
+ }
136
+ /**
137
+ * Process text into lines for the paragraph.
138
+ * This is a simplified version - the full implementation would handle
139
+ * word wrapping, line breaks, and other text formatting based on the font
140
+ * and paragraph width.
141
+ */
142
+ _processTextLines(text) {
143
+ // Handle escaped newlines (\\n) as actual newlines
144
+ const processedText = text.replace(/\\\\n/g, '\n');
145
+ // Simple implementation - split on newlines
146
+ // In the full version, this would implement proper text layout
147
+ let lines = processedText.split('\n');
148
+ // Remove empty lines at the end but preserve intentional line breaks
149
+ while (lines.length > 0 && !lines[lines.length - 1].trim()) {
150
+ lines.pop();
151
+ }
152
+ // Ensure at least one line
153
+ if (lines.length === 0) {
154
+ lines = [''];
155
+ }
156
+ return lines;
157
+ }
158
+ }
159
+ exports.ParagraphBuilder = ParagraphBuilder;
160
+ //# sourceMappingURL=paragraph-builder.js.map
@@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