@embedpdf/plugin-stamp 3.0.0-next.13 → 3.0.0-next.15

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.
@@ -1,384 +0,0 @@
1
- import { EventHook } from "@embedpdf/core";
2
- import { AnnotationRef, BinarySource, Engine, PageObjectNumber, PieceInfoPatch } from "@embedpdf/engine-core/runtime";
3
- import { StampPlacement } from "@embedpdf/plugin-annotation/contract";
4
- //#region src/types.d.ts
5
- /**
6
- * The stamp plugin: a workspace-scoped ASSET substrate.
7
- *
8
- * The design law ("documents have a home; assets ride the wire"): imported
9
- * PDF libraries retain one canonical PDF whose catalog/page `/PieceInfo`
10
- * carries their metadata. Per-asset PDFs and previews are derived caches used
11
- * for placement. Standalone PNG/JPEG assets remain loose because the engine
12
- * intentionally has no raster-to-PDF-page authoring primitive.
13
- */
14
- type StampAssetKind = 'stamp' | 'signature' | 'initials';
15
- /**
16
- * What a library file is FOR — the routing key a surface queries by. Open:
17
- * the plugin defines `stamps` (the default) and `signatures`; an embedder
18
- * may define its own (`toolbar`, `legal-seals`). Persisted in the file.
19
- */
20
- type StampLibraryKind = string;
21
- interface StampLibraryQuery {
22
- /** One kind or several; omitted = every library. */
23
- kind?: StampLibraryKind | readonly StampLibraryKind[];
24
- }
25
- /**
26
- * How a mark is authored: drawn strokes (kept as a vector path), typed text
27
- * in a registered font (embedded by the flatten), a raster image, or a page
28
- * of a PDF. Ink strokes are in points, y-up, any origin — the asset page is
29
- * the mark's bounds.
30
- */
31
- type MarkSource = {
32
- kind: 'ink';
33
- strokes: ReadonlyArray<ReadonlyArray<{
34
- x: number;
35
- y: number;
36
- }>>;
37
- color?: string;
38
- strokeWidth?: number;
39
- } | {
40
- kind: 'text';
41
- text: string;
42
- fontFamily: string;
43
- color?: string;
44
- fontSize?: number;
45
- } | {
46
- kind: 'image';
47
- source: BinarySource;
48
- } | {
49
- kind: 'pdf';
50
- source: BinarySource;
51
- pageIndex?: number;
52
- };
53
- /**
54
- * One asset's SERIALIZABLE descriptor. The bytes and the cached preview are
55
- * deliberately NOT here — the reducer state stays pure/serializable (kernel
56
- * rule 1); binary lives in the capability and crosses only as call
57
- * arguments/returns, mirroring the engine's own BinarySource rule.
58
- */
59
- interface StampAsset {
60
- /** Derived and stable: `${libraryId}:${name}` (never allocated). */
61
- id: string;
62
- libraryId: string;
63
- kind: StampAssetKind;
64
- /**
65
- * The stamp's IDENTIFIER — the text before the first `=` in its library
66
- * key, and the placed annotation's `/Name`: a standard name (`Approved`)
67
- * or a custom one (`#LBGiYhk8V_oAfmqAPENiwD`). Not display text.
68
- */
69
- name: string;
70
- /** What the picker shows and the placed annotation's default `/Subj` —
71
- * the text after `=` in the library key (`Goedgekeurd`). */
72
- label: string;
73
- /** Intrinsic size in PDF points (the source page's crop box / image pixels 1:1). */
74
- size: {
75
- width: number;
76
- height: number;
77
- };
78
- /** The library page that IS this asset. Every asset is a page: a raster
79
- * added to a library becomes a page carrying the image. */
80
- pageObjectNumber: number;
81
- /** An explicit `/Subj` override (PieceInfo); placements use `label` otherwise. */
82
- subject?: string;
83
- categories?: string[];
84
- }
85
- /**
86
- * A library IS a PDF: its `/Title` is the name, its `/Names /Pages` registry
87
- * the assets, its pages the artwork, PieceInfo only what has no standard
88
- * home. One imported PDF becomes one library; `exportLibrary` returns it.
89
- */
90
- interface StampLibrary {
91
- /** PieceInfo `Id` — stable while the title is editable. */
92
- id: string;
93
- name: string;
94
- /** PieceInfo `Kind`: `'stamps'`, `'signatures'`, or an embedder's own. */
95
- kind: StampLibraryKind;
96
- /** PieceInfo `Locale` — the language of the labels, when the library says. */
97
- locale?: string;
98
- categories?: string[];
99
- /** Asset ids in display order. */
100
- assetIds: string[];
101
- }
102
- interface StampState {
103
- libraries: Record<string, StampLibrary>;
104
- /** Library display order (insertion order). */
105
- libraryOrder: string[];
106
- assets: Record<string, StampAsset>;
107
- }
108
- type StampAction = {
109
- type: 'LIBRARY_ADDED';
110
- library: StampLibrary;
111
- } | {
112
- type: 'LIBRARY_UPDATED';
113
- library: StampLibrary;
114
- } | {
115
- type: 'LIBRARY_REMOVED';
116
- libraryId: string;
117
- } | {
118
- type: 'ASSET_ADDED';
119
- asset: StampAsset;
120
- } | {
121
- type: 'ASSET_UPDATED';
122
- asset: StampAsset;
123
- } | {
124
- type: 'ASSET_REMOVED';
125
- assetId: string;
126
- };
127
- /** Why a library's canonical bytes changed — the persistence signal. */
128
- interface StampLibraryChange {
129
- libraryId: string;
130
- reason: 'created' | 'imported' | 'updated' | 'asset-added' | 'asset-updated' | 'asset-removed' | 'removed';
131
- }
132
- interface StampConfig {
133
- /**
134
- * The ASSET ENGINE port: any `Engine` that can open `{ kind: 'bytes' }` —
135
- * used only to slice an imported library PDF into per-page assets and
136
- * render their previews.
137
- *
138
- * Omitted → the kernel's own engine is used, which is exactly right for a
139
- * local deployment (same WASM instance, zero extra cost). In a CLOUD
140
- * deployment the kernel engine cannot open local bytes, so pass a factory —
141
- * it is called (and memoized) on the first import, never at viewer boot:
142
- *
143
- * ```ts
144
- * stampPlugin({
145
- * assetEngine: () => import('@embedpdf/engine').then((m) => m.createLocalEngine()),
146
- * })
147
- * ```
148
- */
149
- assetEngine?: Engine | (() => Engine | Promise<Engine>);
150
- /** Cached thumbnail width in device px (import-time render). Default 256. */
151
- previewWidth?: number;
152
- /**
153
- * Evaluate form-backed (dynamic) PDF stamp assets on arm. Default `true`.
154
- * Scripting itself is the workspace's ONE JavaScript switch,
155
- * `actionsPlugin({ javascript: { enabled } })`: stamp has no switch of its
156
- * own — it asks the target document's actions plugin for a DETACHED realm
157
- * (same identity, clock, sandbox, and budget; isolated globals), and arms
158
- * the template unevaluated when scripting is off or actions is absent.
159
- * `false` keeps templates static even with scripting on — a product
160
- * choice (a stamp's appearance must equal the reviewed template), not a
161
- * trust boundary: a detached realm can only alert and spend budget.
162
- */
163
- dynamic?: boolean;
164
- }
165
- interface ImportLibraryOptions {
166
- /**
167
- * FALLBACK library name, applied only when the PDF carries no `/Title`
168
- * (an Acrobat-authored or previously exported library names itself).
169
- * Default `'Stamps'`.
170
- */
171
- name?: string;
172
- /** Library categories written to catalog `/PieceInfo`. */
173
- categories?: string[];
174
- /** Kind stamped onto every imported asset. Default `'stamp'`. */
175
- kind?: StampAssetKind;
176
- /** What the file is for; overrides what the file says (an Acrobat-authored set imported for a toolbar). */
177
- libraryKind?: StampLibraryKind;
178
- /**
179
- * FALLBACK per-page labels for a plain PDF (no `/Names /Pages` registry):
180
- * every page becomes a stamp named `Stamp<n>` with this label. Ignored
181
- * when the PDF registers its stamps itself.
182
- */
183
- assetName?: (pageIndex: number) => string;
184
- }
185
- interface AddAssetInput {
186
- /** Target library; omitted → a new single-asset library named after the asset. */
187
- libraryId?: string;
188
- /** The identifier (placed `/Name`). Omit to mint an Acrobat-style `#…` one. */
189
- name?: string;
190
- /** Picker text and default `/Subj`. Defaults to `name`. */
191
- label?: string;
192
- kind?: StampAssetKind;
193
- subject?: string;
194
- categories?: string[];
195
- /**
196
- * Single-page PDF (vector) or PNG/JPEG bytes. A raster becomes a PAGE of
197
- * the library sized to `size` (default: its pixels as points, 1:1) with the
198
- * image flattened into it — so every asset is a page and every library a
199
- * complete PDF.
200
- */
201
- /** PNG, JPEG, or single-page PDF bytes. Exactly one of `source` / `mark`. */
202
- source?: BinarySource;
203
- /** An authored mark — drawn, typed, an image, or a PDF page. Exactly one of `source` / `mark`. */
204
- mark?: MarkSource;
205
- /** Thumbnail override for pickers (PNG/JPEG); rendered from the page otherwise. */
206
- preview?: BinarySource;
207
- /** Page size in PDF points for a RASTER source. Ignored for PDF sources (the page has one). */
208
- size?: {
209
- width: number;
210
- height: number;
211
- };
212
- }
213
- /** A cached, browser-paintable render of an asset (PNG from import; raster assets as-is). */
214
- interface StampAssetPreview {
215
- bytes: Uint8Array;
216
- mimeType: string;
217
- }
218
- interface StampCapability {
219
- libraries(query?: StampLibraryQuery): StampLibrary[];
220
- library(id: string): StampLibrary | null;
221
- /** Assets of one library, in library order — or every asset when omitted. */
222
- assets(libraryId?: string): StampAsset[];
223
- asset(id: string): StampAsset | null;
224
- /** The asset's paintable preview, or null while none is cached. */
225
- assetPreview(id: string): StampAssetPreview | null;
226
- /** Placement bytes; derived from the canonical page for PDF-backed libraries. */
227
- assetBytes(id: string): Uint8Array | null;
228
- /**
229
- * A new, empty library: a PDF with the given title and no registered
230
- * stamps yet (like Acrobat, it carries one unregistered blank page so it
231
- * is a valid file from the start). Resolves to the library id; feed it to
232
- * `addAsset({ libraryId })` to fill it.
233
- */
234
- createLibrary(name: string, opts?: {
235
- id?: string;
236
- kind?: StampLibraryKind;
237
- categories?: string[];
238
- }): Promise<string>;
239
- /** Rename (the PDF's `/Title`) or re-categorise a library. */
240
- updateLibrary(id: string, patch: {
241
- name?: string;
242
- categories?: string[];
243
- }): Promise<void>;
244
- /**
245
- * Import a PDF as a stamp library: every page becomes one vector asset
246
- * (single-page PDF bytes + a cached preview render). Uses the asset
247
- * engine; in a cloud deployment without one configured this rejects with
248
- * an actionable error. Resolves to the new library id.
249
- */
250
- importLibraryPdf(source: BinarySource, opts?: ImportLibraryOptions): Promise<string>;
251
- /**
252
- * Add a single asset as a page of its library (a raster is flattened into
253
- * a fresh page first) and register it under `identifier=label`. Without
254
- * `libraryId`, a new library named after the label is created for it.
255
- */
256
- addAsset(input: AddAssetInput): Promise<string>;
257
- /**
258
- * Turn selected annotations of an open document into an asset: their
259
- * appearances are exported by the engine as ONE single-page PDF sized to
260
- * their union rect (vector, positions preserved — exactly what the page
261
- * shows) and added like any PDF asset. The identifier defaults to an
262
- * Acrobat-style `#…` one so the stamp keeps its identity in Acrobat.
263
- * Rejects when any ref is not on `pageObjectNumber`, is hidden, or has no
264
- * appearance (all-or-nothing: a stamp missing a part is worse than an error).
265
- */
266
- addAssetFromAnnotations(documentId: string, pageObjectNumber: PageObjectNumber, refs: AnnotationRef[], input: Omit<AddAssetInput, 'source' | 'size'>): Promise<string>;
267
- /** Remove an asset, deleting its canonical page before state changes when PDF-backed. */
268
- removeAsset(id: string): Promise<void>;
269
- /** Remove a library and every asset in it, ordered with in-flight library mutations. */
270
- removeLibrary(id: string): Promise<void>;
271
- /**
272
- * Relabel an asset (the registry key is renamed in one job), set or clear
273
- * its `/Subj` override, or replace its categories. The identifier never
274
- * changes — it is the asset's identity and every placed stamp's `/Name`.
275
- */
276
- updateAsset(id: string, patch: {
277
- label?: string;
278
- subject?: string | null;
279
- categories?: string[];
280
- }): Promise<void>;
281
- /**
282
- * The library as a PDF — its title, its named pages, its artwork: the
283
- * complete, Acrobat-readable file. This IS the persistence format: store
284
- * these bytes wherever you like and `importLibraryPdf` them back.
285
- */
286
- exportLibrary(id: string): Uint8Array | null;
287
- /** Fires after every change to a library's canonical bytes — subscribe to persist. */
288
- onLibraryChanged: EventHook<StampLibraryChange>;
289
- /**
290
- * Arm an asset on a document: the next click on that document's pages
291
- * places it (and the hover ghost previews the exact placement). With
292
- * scripting on (the actions plugin's `javascript` switch), form-backed
293
- * PDFs are evaluated against that target document in a detached realm and
294
- * flattened first. Rides `annotation.armStamp` — bytes,
295
- * preview, and intrinsic size all travel along, so vector stamps keep
296
- * their true aspect.
297
- */
298
- armAsset(documentId: string, assetId: string, opts?: {
299
- targetWidth?: number;
300
- }): Promise<void>;
301
- /**
302
- * Place an asset WITHOUT the pointer: the same materialization, name,
303
- * subject, fit, and page clamp a click after `armAsset` would produce —
304
- * one placement law, two entry points. Resolves to the new annotation.
305
- */
306
- placeAsset(documentId: string, assetId: string, placement: StampPlacement): Promise<AnnotationRef>;
307
- /** Disarm the stamp tool on a document. */
308
- disarm(documentId: string): void;
309
- /** The asset armed on a document through {@link armAsset}, while the annotation plugin still holds it. */
310
- armedAsset(documentId: string): StampAsset | null;
311
- }
312
- declare const StampToken: import("@embedpdf/core").CapabilityToken<StampCapability>;
313
- //#endregion
314
- //#region src/convention.d.ts
315
- interface StampKey {
316
- name: string;
317
- label: string;
318
- }
319
- declare function parseStampKey(key: string): StampKey;
320
- declare function stampKey(name: string, label: string): string;
321
- /**
322
- * A fresh identifier for a stamp authored here, in Acrobat's own shape
323
- * (`#` + 22 base-62 characters) so a stamp created in this viewer keeps its
324
- * identity when the library is opened and placed in Acrobat.
325
- */
326
- declare function customStampName(random?: () => number): string;
327
- /** Asset ids are derived, not allocated: library id + identifier. */
328
- declare function assetIdFor(libraryId: string, name: string): string;
329
- /** Catalog `/PieceInfo` application name for library-level data. */
330
- declare const STAMP_LIBRARY_PIECEINFO_APP = "EMBD_StampLibrary";
331
- /** Page `/PieceInfo` application name for per-stamp data. */
332
- declare const STAMP_PIECEINFO_APP = "EMBD_Stamp";
333
- /** The `Version` both dictionaries carry. */
334
- declare const STAMP_PIECEINFO_VERSION = 2;
335
- /** The library kind every file has unless it says otherwise. */
336
- declare const DEFAULT_LIBRARY_KIND = "stamps";
337
- /** `/Kind` names: the two the plugin defines keep their PDF spellings; others are written as given. */
338
- declare function libraryKindToPdfName(kind: string): string;
339
- declare function libraryKindFromPdfName(name: string | undefined): string;
340
- declare function stampKindToPdfName(kind: StampAssetKind): string;
341
- /** The catalog patch: library id, categories, locale. The name is `/Title`. */
342
- declare function stampLibraryPieceInfo(id: string, opts?: {
343
- kind?: string;
344
- categories?: readonly string[];
345
- locale?: string;
346
- }): PieceInfoPatch;
347
- /** The page patch: kind, an explicit `/Subj` override, categories. */
348
- declare function stampPieceInfo(kind: StampAssetKind, opts?: {
349
- subject?: string | null;
350
- categories?: readonly string[];
351
- }): PieceInfoPatch;
352
- //#endregion
353
- //#region src/persistence.d.ts
354
- /** The persistence port: bytes by library id. */
355
- interface StampLibraryStore {
356
- list(): Promise<Array<{
357
- id: string;
358
- bytes: Uint8Array;
359
- }>>;
360
- put(id: string, bytes: Uint8Array): Promise<void>;
361
- delete(id: string): Promise<void>;
362
- }
363
- /** An in-memory store — tests and SSR. */
364
- declare function memoryStampStore(): StampLibraryStore;
365
- /**
366
- * Bring every stored library back: each PDF is imported as-is (its title,
367
- * registry, and PieceInfo id come from the file — the store's key is only a
368
- * hint). Call once at boot, before seeding defaults, so "already has
369
- * libraries" means the user's own.
370
- */
371
- declare function restoreStampLibraries(stamp: StampCapability, store: StampLibraryStore): Promise<string[]>;
372
- /**
373
- * Keep the store in sync from now on: every canonical change writes the
374
- * library's PDF (coalesced per library so a burst of edits saves once),
375
- * a removal deletes it. `except` names libraries never to persist — the
376
- * bundled default set, typically. Returns the unsubscribe.
377
- */
378
- declare function persistStampLibraries(stamp: StampCapability, store: StampLibraryStore, opts?: {
379
- except?: readonly string[];
380
- debounceMs?: number;
381
- }): () => void;
382
- //#endregion
383
- export { StampLibraryKind as A, StampAsset as C, StampConfig as D, StampCapability as E, StampState as M, StampToken as N, StampLibrary as O, StampAction as S, StampAssetPreview as T, stampLibraryPieceInfo as _, DEFAULT_LIBRARY_KIND as a, ImportLibraryOptions as b, STAMP_PIECEINFO_VERSION as c, customStampName as d, libraryKindFromPdfName as f, stampKindToPdfName as g, stampKey as h, restoreStampLibraries as i, StampLibraryQuery as j, StampLibraryChange as k, StampKey as l, parseStampKey as m, memoryStampStore as n, STAMP_LIBRARY_PIECEINFO_APP as o, libraryKindToPdfName as p, persistStampLibraries as r, STAMP_PIECEINFO_APP as s, StampLibraryStore as t, assetIdFor as u, stampPieceInfo as v, StampAssetKind as w, MarkSource as x, AddAssetInput as y };
384
- //# sourceMappingURL=contract-VuCLK5Sr.d.ts.map