pdfdancer-client-typescript 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.
- package/.claude/commands/discuss.md +4 -0
- package/.github/workflows/ci.yml +2 -2
- package/README.md +2 -2
- package/dist/__tests__/e2e/pdf-assertions.d.ts +1 -0
- package/dist/__tests__/e2e/pdf-assertions.d.ts.map +1 -1
- package/dist/__tests__/e2e/pdf-assertions.js +9 -3
- package/dist/__tests__/e2e/pdf-assertions.js.map +1 -1
- package/dist/fingerprint.d.ts +12 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +196 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/image-builder.d.ts +4 -2
- package/dist/image-builder.d.ts.map +1 -1
- package/dist/image-builder.js +12 -3
- package/dist/image-builder.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +75 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +179 -21
- package/dist/models.js.map +1 -1
- package/dist/page-builder.d.ts +24 -0
- package/dist/page-builder.d.ts.map +1 -0
- package/dist/page-builder.js +107 -0
- package/dist/page-builder.js.map +1 -0
- package/dist/paragraph-builder.d.ts +48 -54
- package/dist/paragraph-builder.d.ts.map +1 -1
- package/dist/paragraph-builder.js +408 -135
- package/dist/paragraph-builder.js.map +1 -1
- package/dist/pdfdancer_v1.d.ts +90 -9
- package/dist/pdfdancer_v1.d.ts.map +1 -1
- package/dist/pdfdancer_v1.js +559 -55
- package/dist/pdfdancer_v1.js.map +1 -1
- package/dist/types.d.ts +24 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +117 -2
- package/dist/types.js.map +1 -1
- package/docs/openapi.yml +2076 -0
- package/fixtures/Showcase.pdf +0 -0
- package/jest.config.js +1 -1
- package/package.json +1 -1
- package/src/__tests__/e2e/acroform.test.ts +5 -5
- package/src/__tests__/e2e/context-manager-showcase.test.ts +267 -0
- package/src/__tests__/e2e/form_x_object.test.ts +1 -1
- package/src/__tests__/e2e/image-showcase.test.ts +133 -0
- package/src/__tests__/e2e/image.test.ts +1 -1
- package/src/__tests__/e2e/line-showcase.test.ts +118 -0
- package/src/__tests__/e2e/line.test.ts +1 -16
- package/src/__tests__/e2e/page-showcase.test.ts +154 -0
- package/src/__tests__/e2e/paragraph-showcase.test.ts +523 -0
- package/src/__tests__/e2e/paragraph.test.ts +8 -8
- package/src/__tests__/e2e/pdf-assertions.ts +10 -3
- package/src/__tests__/e2e/pdfdancer-showcase.test.ts +40 -0
- package/src/__tests__/e2e/snapshot-showcase.test.ts +158 -0
- package/src/__tests__/e2e/snapshot.test.ts +296 -0
- package/src/__tests__/e2e/token_from_env.test.ts +85 -25
- package/src/__tests__/fingerprint.test.ts +36 -0
- package/src/fingerprint.ts +169 -0
- package/src/image-builder.ts +13 -6
- package/src/index.ts +6 -1
- package/src/models.ts +208 -24
- package/src/page-builder.ts +130 -0
- package/src/paragraph-builder.ts +517 -159
- package/src/pdfdancer_v1.ts +662 -58
- package/src/types.ts +145 -2
- package/update-api-spec.sh +3 -0
package/src/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {Color, CommandResult, FormFieldRef, ObjectRef, ObjectType, Position, TextObjectRef} from "./models";
|
|
1
|
+
import {Color, CommandResult, Font, FormFieldRef, ObjectRef, ObjectType, Paragraph, Position, TextObjectRef} from "./models";
|
|
2
2
|
import {PDFDancer} from "./pdfdancer_v1";
|
|
3
3
|
import {ParagraphBuilder} from "./paragraph-builder";
|
|
4
|
+
import {ValidationException} from "./exceptions";
|
|
4
5
|
|
|
5
6
|
// 👇 Internal view of PDFDancer methods, not exported
|
|
6
7
|
interface PDFDancerInternals {
|
|
@@ -11,6 +12,8 @@ interface PDFDancerInternals {
|
|
|
11
12
|
changeFormField(formFieldRef: FormFieldRef, value: string): Promise<boolean>;
|
|
12
13
|
|
|
13
14
|
modifyTextLine(objectRef: ObjectRef, newText: string): Promise<CommandResult>;
|
|
15
|
+
|
|
16
|
+
modifyParagraph(objectRef: ObjectRef, update: Paragraph | string | null): Promise<CommandResult>;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
export class BaseObject<TRef extends ObjectRef = ObjectRef> {
|
|
@@ -109,7 +112,7 @@ export class ParagraphObject extends BaseObject<TextObjectRef> {
|
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
edit() {
|
|
112
|
-
return new
|
|
115
|
+
return new ParagraphEditSession(this._client, this.objectRef());
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
objectRef() {
|
|
@@ -161,6 +164,146 @@ export class ParagraphObject extends BaseObject<TextObjectRef> {
|
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
166
|
|
|
167
|
+
export class ParagraphEditSession {
|
|
168
|
+
private _newText?: string;
|
|
169
|
+
private _fontName?: string;
|
|
170
|
+
private _fontSize?: number;
|
|
171
|
+
private _color?: Color;
|
|
172
|
+
private _lineSpacing?: number;
|
|
173
|
+
private _newPosition?: { x: number; y: number };
|
|
174
|
+
private _hasChanges = false;
|
|
175
|
+
private readonly _internals: PDFDancerInternals;
|
|
176
|
+
|
|
177
|
+
constructor(private readonly _client: PDFDancer, private readonly _objectRef: TextObjectRef) {
|
|
178
|
+
this._internals = this._client as unknown as PDFDancerInternals;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
replace(text: string) {
|
|
182
|
+
if (text === null || text === undefined) {
|
|
183
|
+
throw new ValidationException("Text cannot be null");
|
|
184
|
+
}
|
|
185
|
+
this._newText = text;
|
|
186
|
+
this._hasChanges = true;
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
text(text: string) {
|
|
191
|
+
return this.replace(text);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
font(font: Font): this;
|
|
195
|
+
font(fontName: string, fontSize: number): this;
|
|
196
|
+
font(fontOrName: Font | string, fontSize?: number): this {
|
|
197
|
+
if (fontOrName instanceof Font) {
|
|
198
|
+
this._fontName = fontOrName.name;
|
|
199
|
+
this._fontSize = fontOrName.size;
|
|
200
|
+
} else {
|
|
201
|
+
if (!fontOrName) {
|
|
202
|
+
throw new ValidationException("Font name cannot be null");
|
|
203
|
+
}
|
|
204
|
+
if (fontSize == null) {
|
|
205
|
+
throw new ValidationException("Font size cannot be null");
|
|
206
|
+
}
|
|
207
|
+
this._fontName = fontOrName;
|
|
208
|
+
this._fontSize = fontSize;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
this._hasChanges = true;
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
color(color: Color) {
|
|
216
|
+
if (!color) {
|
|
217
|
+
throw new ValidationException("Color cannot be null");
|
|
218
|
+
}
|
|
219
|
+
this._color = color;
|
|
220
|
+
this._hasChanges = true;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
lineSpacing(spacing: number) {
|
|
225
|
+
if (spacing <= 0) {
|
|
226
|
+
throw new ValidationException(`Line spacing must be positive, got ${spacing}`);
|
|
227
|
+
}
|
|
228
|
+
this._lineSpacing = spacing;
|
|
229
|
+
this._hasChanges = true;
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
moveTo(x: number, y: number) {
|
|
234
|
+
if (x === null || x === undefined || y === null || y === undefined) {
|
|
235
|
+
throw new ValidationException("Coordinates cannot be null or undefined");
|
|
236
|
+
}
|
|
237
|
+
this._newPosition = {x, y};
|
|
238
|
+
this._hasChanges = true;
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async apply(): Promise<CommandResult | boolean> {
|
|
243
|
+
if (!this._hasChanges) {
|
|
244
|
+
return this._internals.modifyParagraph(this._objectRef, null);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const onlyTextChanged = (
|
|
248
|
+
this._newText !== undefined &&
|
|
249
|
+
this._fontName === undefined &&
|
|
250
|
+
this._fontSize === undefined &&
|
|
251
|
+
this._color === undefined &&
|
|
252
|
+
this._lineSpacing === undefined &&
|
|
253
|
+
this._newPosition === undefined
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
if (onlyTextChanged) {
|
|
257
|
+
const result = await this._internals.modifyParagraph(this._objectRef, this._newText ?? '');
|
|
258
|
+
this._hasChanges = false;
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const onlyMove = (
|
|
263
|
+
this._newPosition !== undefined &&
|
|
264
|
+
this._newText === undefined &&
|
|
265
|
+
this._fontName === undefined &&
|
|
266
|
+
this._fontSize === undefined &&
|
|
267
|
+
this._color === undefined &&
|
|
268
|
+
this._lineSpacing === undefined
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
if (onlyMove) {
|
|
272
|
+
const pageIndex = this._objectRef.position.pageIndex;
|
|
273
|
+
if (pageIndex === undefined) {
|
|
274
|
+
throw new ValidationException("Paragraph position must include a page index to move");
|
|
275
|
+
}
|
|
276
|
+
const position = Position.atPageCoordinates(pageIndex, this._newPosition!.x, this._newPosition!.y);
|
|
277
|
+
const result = await this._internals.move(this._objectRef, position);
|
|
278
|
+
this._hasChanges = false;
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const builder = ParagraphBuilder.fromObjectRef(this._client, this._objectRef);
|
|
283
|
+
builder.setFontExplicitlyChanged(false);
|
|
284
|
+
|
|
285
|
+
if (this._newText !== undefined) {
|
|
286
|
+
builder.text(this._newText);
|
|
287
|
+
}
|
|
288
|
+
if (this._fontName !== undefined && this._fontSize !== undefined) {
|
|
289
|
+
builder.font(this._fontName, this._fontSize);
|
|
290
|
+
}
|
|
291
|
+
if (this._color !== undefined) {
|
|
292
|
+
builder.color(this._color);
|
|
293
|
+
}
|
|
294
|
+
if (this._lineSpacing !== undefined) {
|
|
295
|
+
builder.lineSpacing(this._lineSpacing);
|
|
296
|
+
}
|
|
297
|
+
if (this._newPosition !== undefined) {
|
|
298
|
+
builder.moveTo(this._newPosition.x, this._newPosition.y);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const result = await builder.modify(this._objectRef);
|
|
302
|
+
this._hasChanges = false;
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
164
307
|
export class TextLineObject extends BaseObject<TextObjectRef> {
|
|
165
308
|
|
|
166
309
|
private fontName: string | undefined;
|