@hussmartinez/pdf-sdk 0.1.0 → 0.2.0
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/README.md +40 -5
- package/dist/assets/processing/processing.worker.js +21 -21
- package/dist/index.d.ts +18 -0
- package/dist/index.js +1 -1
- package/dist/lazy/processing-worker-DU8GEYFs.js +30 -0
- package/dist/lazy/{processing-worker-CxoVSxEZ.js.map → processing-worker-DU8GEYFs.js.map} +1 -1
- package/dist/react.d.ts +256 -1
- package/dist/react.js +287 -29
- package/dist/react.js.map +1 -1
- package/dist/shared/{en-B0u26URn.js → en-BYB_GHqG.js} +53 -32
- package/dist/shared/en-BYB_GHqG.js.map +1 -0
- package/dist/styles.css +10 -8
- package/package.json +11 -7
- package/dist/lazy/processing-worker-CxoVSxEZ.js +0 -30
- package/dist/shared/en-B0u26URn.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processing-worker-
|
|
1
|
+
{"version":3,"file":"processing-worker-DU8GEYFs.js","names":["ProcessingWorker"],"sources":["../../src/adapters/qpdf/processing-worker.ts"],"sourcesContent":["import ProcessingWorker from \"../../workers/processing.worker.ts?worker&inline\";\n\n/** Starts the inlined processing worker, from its own lazy chunk. */\nexport function createInlineWorker(): Worker {\n return new ProcessingWorker({ name: \"hm-pdf-processing\" });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAgB,qBAA6B;CAC3C,OAAO,IAAIA,cAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC3D"}
|
package/dist/react.d.ts
CHANGED
|
@@ -11,12 +11,16 @@
|
|
|
11
11
|
|
|
12
12
|
import { FilePolicyOverrides } from '@hussmartinez/sdk-core';
|
|
13
13
|
import { ForwardRefExoticComponent } from 'react';
|
|
14
|
+
import { IconComponent } from '@hussmartinez/ui/react';
|
|
14
15
|
import { MessageOverrides } from '@hussmartinez/sdk-core';
|
|
15
16
|
import type { Messages } from '@hussmartinez/sdk-core';
|
|
16
17
|
import { ReactNode } from 'react';
|
|
17
18
|
import { RefAttributes } from 'react';
|
|
18
19
|
import { SdkCoreErrorCode } from '@hussmartinez/sdk-core';
|
|
19
20
|
import { SdkError } from '@hussmartinez/sdk-core';
|
|
21
|
+
import type { ShortcutRegistry } from '@hussmartinez/sdk-core';
|
|
22
|
+
import type { Tool } from '@hussmartinez/sdk-core';
|
|
23
|
+
import type { ToolRegistry } from '@hussmartinez/sdk-core';
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Adds an annotation to a page.
|
|
@@ -229,6 +233,13 @@ declare interface PdfDocumentHandle {
|
|
|
229
233
|
* closing are announced, and focus moves to the document once it opens, or
|
|
230
234
|
* to the button to try again if it couldn't.
|
|
231
235
|
*
|
|
236
|
+
* Its toolbar is built from {@link pdfTools}: choose them with `tools` and
|
|
237
|
+
* arrange them with `toolbar`. Each tool's shortcut works while focus is in
|
|
238
|
+
* the editor, and undoing, redoing and rotating are announced.
|
|
239
|
+
*
|
|
240
|
+
* Load `@hussmartinez/ui/styles.css` once, before the SDK's stylesheet: the
|
|
241
|
+
* toolbar's focus rings and target sizes are in it (sdk-core ADR 0036).
|
|
242
|
+
*
|
|
232
243
|
* Give the editor a bounded height, such as a grid row or a fixed height:
|
|
233
244
|
* its viewer and thumbnails scroll within it.
|
|
234
245
|
*
|
|
@@ -279,6 +290,137 @@ export declare interface PdfEditorHandle {
|
|
|
279
290
|
close(): Promise<void>;
|
|
280
291
|
}
|
|
281
292
|
|
|
293
|
+
/**
|
|
294
|
+
* The type of {@link pdfEditorMessages}, for typing the editor's `messages`
|
|
295
|
+
* overrides with `MessageOverrides<PdfEditorMessageCatalogue>`.
|
|
296
|
+
*
|
|
297
|
+
* @public
|
|
298
|
+
*/
|
|
299
|
+
export declare type PdfEditorMessageCatalogue = typeof pdfEditorMessages;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* The editor's English message catalogue: the SDK's own, which includes
|
|
303
|
+
* sdk-core's, and `@hussmartinez/ui`'s, for the ui components the editor
|
|
304
|
+
* renders (sdk-core ADR 0046). The editor builds one `Messages` object from
|
|
305
|
+
* it, with the host's locale and overrides, and gives the same object to
|
|
306
|
+
* its own components and to ui's.
|
|
307
|
+
*
|
|
308
|
+
* It's defined in the React entry, so the headless `.` entry and its
|
|
309
|
+
* `pdfMessages` don't carry ui's text.
|
|
310
|
+
*
|
|
311
|
+
* @public
|
|
312
|
+
*/
|
|
313
|
+
export declare const pdfEditorMessages: {
|
|
314
|
+
readonly "dialog.close": "Close";
|
|
315
|
+
readonly "fileDropZone.choose": "Choose a file";
|
|
316
|
+
readonly "fileDropZone.chooseMultiple": "Choose files";
|
|
317
|
+
readonly "fileDropZone.hint": "or drop it here";
|
|
318
|
+
readonly "fileDropZone.hintMultiple": "or drop them here";
|
|
319
|
+
readonly "progress.label": "Progress";
|
|
320
|
+
readonly "spinner.label": "Loading";
|
|
321
|
+
readonly "errors.INVALID_THEME_TOKEN": "The theme setting {token} has a value that can't be used.";
|
|
322
|
+
readonly "errors.INVALID_THEME_SELECTOR": "The theme can't be applied to the selector {selector}.";
|
|
323
|
+
readonly "errors.INVALID_PDF": "This file isn't a PDF, or it's too damaged to open.";
|
|
324
|
+
readonly "errors.PASSWORD_REQUIRED": "This PDF is protected with a password.";
|
|
325
|
+
readonly "errors.PROCESSING_FAILED": "Something went wrong while processing this PDF. Please try again.";
|
|
326
|
+
readonly "errors.TOO_MANY_PAGES": "This document has {actual, number} pages, which is over the {maximum, number}-page limit.";
|
|
327
|
+
readonly "errors.SESSION_TOO_LARGE": "The open documents would use {actual, fileSize}, which is over the {maximum, fileSize} limit. Close a document, or clear the undo history, and try again.";
|
|
328
|
+
readonly "errors.IMAGE_TOO_LARGE": "Some images are too large to show. They're kept unchanged in the document.";
|
|
329
|
+
readonly "warnings.maxPages": {
|
|
330
|
+
readonly $plural: "actual";
|
|
331
|
+
} & {
|
|
332
|
+
readonly one: "This document has {actual} page. Large documents may be slow.";
|
|
333
|
+
readonly other: "This document has {actual} pages. Large documents may be slow.";
|
|
334
|
+
};
|
|
335
|
+
readonly "warnings.maxSessionSize": "The open documents use {actual, fileSize}. Clearing the undo history frees memory.";
|
|
336
|
+
readonly "warnings.maxImagePixels": "Some images are very large and may be slow to show.";
|
|
337
|
+
readonly "viewer.label": "Document";
|
|
338
|
+
readonly "viewer.empty": "No document is open.";
|
|
339
|
+
readonly "viewer.page": "Page {page} of {count}";
|
|
340
|
+
readonly "viewer.webLink": "Link to {destination}, opens in a new tab";
|
|
341
|
+
readonly "viewer.emailLink": "Email {destination}";
|
|
342
|
+
readonly "thumbnails.label": "Pages";
|
|
343
|
+
readonly "thumbnails.page": "Page {page} of {count}";
|
|
344
|
+
readonly "thumbnails.number": "{page}";
|
|
345
|
+
readonly "editor.label": "PDF editor";
|
|
346
|
+
readonly "editor.start.title": "Open a PDF to get started";
|
|
347
|
+
readonly "editor.start.retryTitle": "Try another PDF";
|
|
348
|
+
readonly "editor.start.choose": "Choose a PDF";
|
|
349
|
+
readonly "editor.start.retry": "Choose another PDF";
|
|
350
|
+
readonly "editor.start.hint": "Or drop one here. Your file stays on this device and is never uploaded.";
|
|
351
|
+
readonly "editor.opening": "Opening the PDF…";
|
|
352
|
+
readonly "editor.opened": {
|
|
353
|
+
readonly $plural: "count";
|
|
354
|
+
} & {
|
|
355
|
+
readonly one: "Opened a PDF with {count} page.";
|
|
356
|
+
readonly other: "Opened a PDF with {count} pages.";
|
|
357
|
+
};
|
|
358
|
+
readonly "editor.closed": "The PDF was closed.";
|
|
359
|
+
readonly "editor.undone": "Undone.";
|
|
360
|
+
readonly "editor.redone": "Redone.";
|
|
361
|
+
readonly "editor.rotated": {
|
|
362
|
+
readonly $plural: "count";
|
|
363
|
+
} & {
|
|
364
|
+
readonly one: "Rotated {count} page.";
|
|
365
|
+
readonly other: "Rotated {count} pages.";
|
|
366
|
+
};
|
|
367
|
+
readonly "toolbar.label": "PDF tools";
|
|
368
|
+
readonly "toolbar.groups.file": "File";
|
|
369
|
+
readonly "toolbar.groups.history": "History";
|
|
370
|
+
readonly "toolbar.groups.pages": "Pages";
|
|
371
|
+
readonly "toolbar.groups.other": "More tools";
|
|
372
|
+
readonly "tools.open": "Open a PDF";
|
|
373
|
+
readonly "tools.undo": "Undo";
|
|
374
|
+
readonly "tools.redo": "Redo";
|
|
375
|
+
readonly "tools.rotate-left": "Rotate left";
|
|
376
|
+
readonly "tools.rotate-right": "Rotate right";
|
|
377
|
+
readonly "errors.UNKNOWN": "Something went wrong. Please try again.";
|
|
378
|
+
readonly "errors.ABORTED": "The operation was cancelled.";
|
|
379
|
+
readonly "errors.TIMEOUT": "The operation took too long and was stopped.";
|
|
380
|
+
readonly "errors.WORKER_START_FAILED": "The file processor couldn't start. Reload the page and try again.";
|
|
381
|
+
readonly "errors.WORKER_PROTOCOL_MISMATCH": "The file processor is out of date. Reload the page to update it.";
|
|
382
|
+
readonly "errors.WORKER_CRASHED": "The file processor stopped unexpectedly. Please try again.";
|
|
383
|
+
readonly "errors.WORKER_TERMINATED": "The operation was stopped before it finished. Please try again.";
|
|
384
|
+
readonly "errors.WORKER_METHOD_NOT_FOUND": "This operation isn't available. Reload the page and try again.";
|
|
385
|
+
readonly "errors.WORKER_DATA_NOT_CLONEABLE": "Something went wrong while processing the file. Please try again.";
|
|
386
|
+
readonly "errors.UNSUPPORTED_ENVIRONMENT": "This browser doesn't support a feature this tool needs. Update your browser, or try another one.";
|
|
387
|
+
readonly "errors.FILE_TOO_LARGE": "This file is {actual, fileSize}, which is over the {maximum, fileSize} limit.";
|
|
388
|
+
readonly "errors.TOO_MANY_FILES": {
|
|
389
|
+
readonly $plural: "maximum";
|
|
390
|
+
} & {
|
|
391
|
+
readonly one: "You can add {maximum} file at a time.";
|
|
392
|
+
readonly other: "You can add up to {maximum} files at a time.";
|
|
393
|
+
};
|
|
394
|
+
readonly "errors.DECODED_SIZE_TOO_LARGE": "This file expands to more than {maximum, fileSize} when opened, which is over the limit.";
|
|
395
|
+
readonly "errors.PROCESSING_TIME_EXCEEDED": "Processing this file took too long and was stopped.";
|
|
396
|
+
readonly "warnings.maxFileSize": "This file is {actual, fileSize}. Large files may be slow to process.";
|
|
397
|
+
readonly "warnings.maxFiles": "Adding {actual} files at once may be slow.";
|
|
398
|
+
readonly "warnings.maxDecodedSize": "This file is very large once opened and may be slow to process.";
|
|
399
|
+
readonly "warnings.maxProcessingTime": "This is taking longer than usual.";
|
|
400
|
+
readonly "keys.control": "Ctrl";
|
|
401
|
+
readonly "keys.alt": "Alt";
|
|
402
|
+
readonly "keys.shift": "Shift";
|
|
403
|
+
readonly "keys.meta": "Meta";
|
|
404
|
+
readonly "keys.apple.control": "\u2303";
|
|
405
|
+
readonly "keys.apple.alt": "\u2325";
|
|
406
|
+
readonly "keys.apple.shift": "\u21E7";
|
|
407
|
+
readonly "keys.apple.meta": "\u2318";
|
|
408
|
+
readonly "keys.space": "Space";
|
|
409
|
+
readonly "keys.enter": "Enter";
|
|
410
|
+
readonly "keys.escape": "Esc";
|
|
411
|
+
readonly "keys.tab": "Tab";
|
|
412
|
+
readonly "keys.delete": "Delete";
|
|
413
|
+
readonly "keys.backspace": "Backspace";
|
|
414
|
+
readonly "keys.arrowUp": "\u2191";
|
|
415
|
+
readonly "keys.arrowDown": "\u2193";
|
|
416
|
+
readonly "keys.arrowLeft": "\u2190";
|
|
417
|
+
readonly "keys.arrowRight": "\u2192";
|
|
418
|
+
readonly "keys.home": "Home";
|
|
419
|
+
readonly "keys.end": "End";
|
|
420
|
+
readonly "keys.pageUp": "Page Up";
|
|
421
|
+
readonly "keys.pageDown": "Page Down";
|
|
422
|
+
};
|
|
423
|
+
|
|
282
424
|
/**
|
|
283
425
|
* The parts of `PdfEditor` that take extra classes through `classNames`.
|
|
284
426
|
*
|
|
@@ -293,7 +435,12 @@ export declare type PdfEditorPart = "root" | "header" | "toolbar" | "body" | "si
|
|
|
293
435
|
*
|
|
294
436
|
* @public
|
|
295
437
|
*/
|
|
296
|
-
export declare interface PdfEditorProps extends Omit<PdfSessionProviderProps, "children"> {
|
|
438
|
+
export declare interface PdfEditorProps extends Omit<PdfSessionProviderProps, "children" | "messages"> {
|
|
439
|
+
/**
|
|
440
|
+
* Text overrides, typed against the editor's English catalogue, which
|
|
441
|
+
* includes ui's text for the ui components it renders (sdk-core ADR 0046).
|
|
442
|
+
*/
|
|
443
|
+
readonly messages?: MessageOverrides<PdfEditorMessageCatalogue>;
|
|
297
444
|
/**
|
|
298
445
|
* A document to open. The editor opens it on mount, and again whenever a
|
|
299
446
|
* different file or buffer is passed; `null` closes the document. Files
|
|
@@ -302,6 +449,21 @@ export declare interface PdfEditorProps extends Omit<PdfSessionProviderProps, "c
|
|
|
302
449
|
readonly file?: Blob | PdfBytes | null;
|
|
303
450
|
/** Called after the document opens, changes or closes. */
|
|
304
451
|
readonly onChange?: (change: PdfEditorChange) => void;
|
|
452
|
+
/**
|
|
453
|
+
* Which tools are present, by id, in order, such as
|
|
454
|
+
* `["pdf.undo", "pdf.redo"]`. All of {@link pdfTools} by default. Their
|
|
455
|
+
* shortcuts work only while they're present.
|
|
456
|
+
*/
|
|
457
|
+
readonly tools?: readonly string[];
|
|
458
|
+
/**
|
|
459
|
+
* The toolbar's groups, as tool ids, such as
|
|
460
|
+
* `[["pdf.undo", "pdf.redo"], ["pdf.rotate-left", "pdf.rotate-right"]]`.
|
|
461
|
+
* Defaults to the present tools in their usual groups; `[]` hides the
|
|
462
|
+
* toolbar, keeping the shortcuts. An unknown id throws.
|
|
463
|
+
*/
|
|
464
|
+
readonly toolbar?: readonly (readonly string[])[];
|
|
465
|
+
/** Icon components by name, over the SDK's own from ui. */
|
|
466
|
+
readonly icons?: Readonly<Record<string, IconComponent>>;
|
|
305
467
|
/** Extra classes on the root. */
|
|
306
468
|
readonly className?: string;
|
|
307
469
|
/** Extra classes on each part. */
|
|
@@ -451,6 +613,14 @@ declare interface PdfFormField {
|
|
|
451
613
|
readonly readOnly: boolean;
|
|
452
614
|
}
|
|
453
615
|
|
|
616
|
+
/**
|
|
617
|
+
* The components of the icons the editor's tools name, from ui's set
|
|
618
|
+
* (sdk-core ADR 0030). A host's `icons` prop overrides any of them.
|
|
619
|
+
*
|
|
620
|
+
* @public
|
|
621
|
+
*/
|
|
622
|
+
export declare const pdfIcons: Readonly<Record<string, IconComponent>>;
|
|
623
|
+
|
|
454
624
|
/**
|
|
455
625
|
* A drawn signature, or another image, placed on the page.
|
|
456
626
|
*
|
|
@@ -661,6 +831,24 @@ declare const pdfMessages: {
|
|
|
661
831
|
readonly other: "Opened a PDF with {count} pages.";
|
|
662
832
|
};
|
|
663
833
|
readonly "editor.closed": "The PDF was closed.";
|
|
834
|
+
readonly "editor.undone": "Undone.";
|
|
835
|
+
readonly "editor.redone": "Redone.";
|
|
836
|
+
readonly "editor.rotated": {
|
|
837
|
+
readonly $plural: "count";
|
|
838
|
+
} & {
|
|
839
|
+
readonly one: "Rotated {count} page.";
|
|
840
|
+
readonly other: "Rotated {count} pages.";
|
|
841
|
+
};
|
|
842
|
+
readonly "toolbar.label": "PDF tools";
|
|
843
|
+
readonly "toolbar.groups.file": "File";
|
|
844
|
+
readonly "toolbar.groups.history": "History";
|
|
845
|
+
readonly "toolbar.groups.pages": "Pages";
|
|
846
|
+
readonly "toolbar.groups.other": "More tools";
|
|
847
|
+
readonly "tools.open": "Open a PDF";
|
|
848
|
+
readonly "tools.undo": "Undo";
|
|
849
|
+
readonly "tools.redo": "Redo";
|
|
850
|
+
readonly "tools.rotate-left": "Rotate left";
|
|
851
|
+
readonly "tools.rotate-right": "Rotate right";
|
|
664
852
|
readonly "errors.UNKNOWN": "Something went wrong. Please try again.";
|
|
665
853
|
readonly "errors.ABORTED": "The operation was cancelled.";
|
|
666
854
|
readonly "errors.TIMEOUT": "The operation took too long and was stopped.";
|
|
@@ -1232,6 +1420,73 @@ export declare interface PdfThumbnailsProps {
|
|
|
1232
1420
|
readonly concurrency?: number;
|
|
1233
1421
|
}
|
|
1234
1422
|
|
|
1423
|
+
/**
|
|
1424
|
+
* One of the editor's tools (sdk-core ADR 0009 and ADR 0030): headless, so
|
|
1425
|
+
* the React editor and the custom element share it.
|
|
1426
|
+
*
|
|
1427
|
+
* @public
|
|
1428
|
+
*/
|
|
1429
|
+
export declare type PdfTool = Tool<PdfToolState, PdfToolContext, undefined>;
|
|
1430
|
+
|
|
1431
|
+
/**
|
|
1432
|
+
* The editor's toolbar: ui's `Toolbar`, one labelled group per toolbar group
|
|
1433
|
+
* of the registry and one button per tool, disabled when the tool can't
|
|
1434
|
+
* run, with the tool's shortcuts as `aria-keyshortcuts`. Arrow keys move
|
|
1435
|
+
* between the buttons, as ui's toolbar does, so it's one tab stop.
|
|
1436
|
+
*
|
|
1437
|
+
* @public
|
|
1438
|
+
*/
|
|
1439
|
+
export declare function PdfToolbar(props: PdfToolbarProps): ReactNode;
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* Props for {@link PdfToolbar}.
|
|
1443
|
+
*
|
|
1444
|
+
* @public
|
|
1445
|
+
*/
|
|
1446
|
+
export declare interface PdfToolbarProps {
|
|
1447
|
+
/** The editor's tools, from `createToolRegistry`. */
|
|
1448
|
+
readonly registry: ToolRegistry<PdfTool>;
|
|
1449
|
+
/** The editor's shortcuts, for each button's `aria-keyshortcuts`. */
|
|
1450
|
+
readonly shortcuts?: ShortcutRegistry;
|
|
1451
|
+
/** What the tools run against. */
|
|
1452
|
+
readonly context: PdfToolContext;
|
|
1453
|
+
/** Icon components by name. */
|
|
1454
|
+
readonly icons: Readonly<Record<string, IconComponent>>;
|
|
1455
|
+
/** Runs a tool. Defaults to running it against `context`. */
|
|
1456
|
+
readonly onRun?: (tool: PdfTool) => void;
|
|
1457
|
+
/** Extra classes on the root. */
|
|
1458
|
+
readonly className?: string;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/**
|
|
1462
|
+
* What a tool runs against.
|
|
1463
|
+
*
|
|
1464
|
+
* @public
|
|
1465
|
+
*/
|
|
1466
|
+
export declare interface PdfToolContext {
|
|
1467
|
+
/** The session the tool edits. */
|
|
1468
|
+
readonly session: PdfSession;
|
|
1469
|
+
/** Asks the user for a PDF and opens it, as the open tool does. */
|
|
1470
|
+
readonly chooseFile: () => void;
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
/**
|
|
1474
|
+
* Every tool the editor knows, in their default order (sdk-core ADR 0030).
|
|
1475
|
+
*
|
|
1476
|
+
* @public
|
|
1477
|
+
*/
|
|
1478
|
+
export declare const pdfTools: readonly PdfTool[];
|
|
1479
|
+
|
|
1480
|
+
/**
|
|
1481
|
+
* What a tool reads to decide whether it's available, enabled or active.
|
|
1482
|
+
*
|
|
1483
|
+
* @public
|
|
1484
|
+
*/
|
|
1485
|
+
export declare interface PdfToolState {
|
|
1486
|
+
/** The session's current snapshot. */
|
|
1487
|
+
readonly snapshot: PdfSessionSnapshot;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1235
1490
|
/**
|
|
1236
1491
|
* Options for calls that take PDF bytes.
|
|
1237
1492
|
*
|