@embedpdf/plugin-stamp 2.15.0 → 3.0.0-next.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.
Files changed (66) hide show
  1. package/LICENSE +192 -21
  2. package/dist/index.cjs +591 -2
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +187 -0
  5. package/dist/index.d.ts +187 -1
  6. package/dist/index.js +584 -975
  7. package/dist/index.js.map +1 -1
  8. package/package.json +23 -61
  9. package/dist/lib/actions.d.ts +0 -14
  10. package/dist/lib/defaults/name-map.d.ts +0 -2
  11. package/dist/lib/handlers/rubber-stamp.handler.d.ts +0 -4
  12. package/dist/lib/index.d.ts +0 -11
  13. package/dist/lib/manifest.d.ts +0 -4
  14. package/dist/lib/reducer.d.ts +0 -5
  15. package/dist/lib/stamp-plugin.d.ts +0 -54
  16. package/dist/lib/tools.d.ts +0 -58
  17. package/dist/lib/types.d.ts +0 -130
  18. package/dist/preact/adapter.d.ts +0 -5
  19. package/dist/preact/annotation.d.ts +0 -1
  20. package/dist/preact/core.d.ts +0 -1
  21. package/dist/preact/index.cjs +0 -2
  22. package/dist/preact/index.cjs.map +0 -1
  23. package/dist/preact/index.d.ts +0 -1
  24. package/dist/preact/index.js +0 -116
  25. package/dist/preact/index.js.map +0 -1
  26. package/dist/react/adapter.d.ts +0 -2
  27. package/dist/react/annotation.d.ts +0 -1
  28. package/dist/react/core.d.ts +0 -1
  29. package/dist/react/index.cjs +0 -2
  30. package/dist/react/index.cjs.map +0 -1
  31. package/dist/react/index.d.ts +0 -1
  32. package/dist/react/index.js +0 -115
  33. package/dist/react/index.js.map +0 -1
  34. package/dist/shared/components/index.d.ts +0 -1
  35. package/dist/shared/components/stamp-img.d.ts +0 -10
  36. package/dist/shared/hooks/index.d.ts +0 -1
  37. package/dist/shared/hooks/use-stamp.d.ts +0 -18
  38. package/dist/shared/index.d.ts +0 -4
  39. package/dist/shared-preact/components/index.d.ts +0 -1
  40. package/dist/shared-preact/components/stamp-img.d.ts +0 -10
  41. package/dist/shared-preact/hooks/index.d.ts +0 -1
  42. package/dist/shared-preact/hooks/use-stamp.d.ts +0 -18
  43. package/dist/shared-preact/index.d.ts +0 -4
  44. package/dist/shared-react/components/index.d.ts +0 -1
  45. package/dist/shared-react/components/stamp-img.d.ts +0 -10
  46. package/dist/shared-react/hooks/index.d.ts +0 -1
  47. package/dist/shared-react/hooks/use-stamp.d.ts +0 -18
  48. package/dist/shared-react/index.d.ts +0 -4
  49. package/dist/svelte/components/StampImg.svelte.d.ts +0 -10
  50. package/dist/svelte/components/index.d.ts +0 -1
  51. package/dist/svelte/hooks/index.d.ts +0 -1
  52. package/dist/svelte/hooks/use-stamp.svelte.d.ts +0 -23
  53. package/dist/svelte/index.cjs +0 -2
  54. package/dist/svelte/index.cjs.map +0 -1
  55. package/dist/svelte/index.d.ts +0 -4
  56. package/dist/svelte/index.js +0 -187
  57. package/dist/svelte/index.js.map +0 -1
  58. package/dist/vue/components/index.d.ts +0 -1
  59. package/dist/vue/components/stamp-img.vue.d.ts +0 -9
  60. package/dist/vue/hooks/index.d.ts +0 -1
  61. package/dist/vue/hooks/use-stamp.d.ts +0 -460
  62. package/dist/vue/index.cjs +0 -2
  63. package/dist/vue/index.cjs.map +0 -1
  64. package/dist/vue/index.d.ts +0 -4
  65. package/dist/vue/index.js +0 -189
  66. package/dist/vue/index.js.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1 +1,187 @@
1
- export * from './lib';
1
+ import { BinarySource, Engine } from "@embedpdf/engine-core/runtime";
2
+ import { FormScriptingOptions } from "@embedpdf/plugin-form";
3
+ //#region src/types.d.ts
4
+ /**
5
+ * The stamp plugin: a workspace-scoped ASSET substrate.
6
+ *
7
+ * The design law ("documents have a home; assets ride the wire"): imported
8
+ * PDF libraries retain one canonical PDF whose catalog/page `/PieceInfo`
9
+ * carries their metadata. Per-asset PDFs and previews are derived caches used
10
+ * for placement. Standalone PNG/JPEG assets remain loose because the engine
11
+ * intentionally has no raster-to-PDF-page authoring primitive.
12
+ */
13
+ type StampAssetKind = 'stamp' | 'signature' | 'initials';
14
+ /**
15
+ * One asset's SERIALIZABLE descriptor. The bytes and the cached preview are
16
+ * deliberately NOT here — the reducer state stays pure/serializable (kernel
17
+ * rule 1); binary lives in the capability and crosses only as call
18
+ * arguments/returns, mirroring the engine's own BinarySource rule.
19
+ */
20
+ interface StampAsset {
21
+ id: string;
22
+ libraryId: string;
23
+ kind: StampAssetKind;
24
+ name: string;
25
+ /** Intrinsic size in PDF points (the source page's crop box / image pixels 1:1). */
26
+ size: {
27
+ width: number;
28
+ height: number;
29
+ };
30
+ /** What the asset bytes are: a single-page vector PDF, or a raster image. */
31
+ format: 'pdf' | 'png' | 'jpeg';
32
+ /** Canonical library page identity; present for PDF-backed libraries. */
33
+ pageObjectNumber?: number;
34
+ subject?: string;
35
+ categories?: string[];
36
+ }
37
+ /** A named group of assets — one imported PDF becomes one library. */
38
+ interface StampLibrary {
39
+ id: string;
40
+ name: string;
41
+ /** PDF-backed libraries own canonical bytes; loose libraries are raster/pre-sliced conveniences. */
42
+ storage: 'canonical-pdf' | 'loose';
43
+ categories?: string[];
44
+ /** Asset ids in display order. */
45
+ assetIds: string[];
46
+ }
47
+ interface StampState {
48
+ libraries: Record<string, StampLibrary>;
49
+ /** Library display order (insertion order). */
50
+ libraryOrder: string[];
51
+ assets: Record<string, StampAsset>;
52
+ }
53
+ type StampAction = {
54
+ type: 'LIBRARY_ADDED';
55
+ library: StampLibrary;
56
+ } | {
57
+ type: 'LIBRARY_REMOVED';
58
+ libraryId: string;
59
+ } | {
60
+ type: 'ASSET_ADDED';
61
+ asset: StampAsset;
62
+ } | {
63
+ type: 'ASSET_REMOVED';
64
+ assetId: string;
65
+ };
66
+ interface StampConfig {
67
+ /**
68
+ * The ASSET ENGINE port: any `Engine` that can open `{ kind: 'bytes' }` —
69
+ * used only to slice an imported library PDF into per-page assets and
70
+ * render their previews.
71
+ *
72
+ * Omitted → the kernel's own engine is used, which is exactly right for a
73
+ * local deployment (same WASM instance, zero extra cost). In a CLOUD
74
+ * deployment the kernel engine cannot open local bytes, so pass a factory —
75
+ * it is called (and memoized) on the first import, never at viewer boot:
76
+ *
77
+ * ```ts
78
+ * stampPlugin({
79
+ * assetEngine: () => import('@embedpdf/engine').then((m) => m.createLocalEngine()),
80
+ * })
81
+ * ```
82
+ */
83
+ assetEngine?: Engine | (() => Engine | Promise<Engine>);
84
+ /** Cached preview width in device px (import-time render). Default 256. */
85
+ previewWidth?: number;
86
+ /**
87
+ * Opt-in Acrobat JavaScript evaluation for form-backed PDF stamp assets.
88
+ * On arm, the plugin recalculates a temporary copy using the target
89
+ * document's identity/name/clock, flattens it, and arms the resulting
90
+ * static page. Canonical library and derived base bytes stay unchanged.
91
+ */
92
+ scripting?: FormScriptingOptions;
93
+ }
94
+ interface ImportLibraryOptions {
95
+ /** Library display name. Default `'Stamps'`. */
96
+ name?: string;
97
+ /** Library categories written to catalog `/PieceInfo`. */
98
+ categories?: string[];
99
+ /** Kind stamped onto every imported asset. Default `'stamp'`. */
100
+ kind?: StampAssetKind;
101
+ /** Per-page asset names; default `Stamp <n>`. */
102
+ assetName?: (pageIndex: number) => string;
103
+ }
104
+ interface AddAssetInput {
105
+ /** Target library; omitted → a new single-asset library named after the asset. */
106
+ libraryId?: string;
107
+ name: string;
108
+ kind?: StampAssetKind;
109
+ subject?: string;
110
+ categories?: string[];
111
+ /** Single-page PDF (vector) or PNG/JPEG bytes. */
112
+ source: BinarySource;
113
+ /**
114
+ * Paintable preview for pickers + the hover ghost. Loose PDF assets cannot
115
+ * derive one without opening the PDF; canonical libraries render it after
116
+ * insertion. Raster sources default to their own bytes.
117
+ */
118
+ preview?: BinarySource;
119
+ /** Intrinsic size in PDF points. Required for PDF sources; rasters are sniffed. */
120
+ size?: {
121
+ width: number;
122
+ height: number;
123
+ };
124
+ }
125
+ /** A cached, browser-paintable render of an asset (PNG from import; raster assets as-is). */
126
+ interface StampAssetPreview {
127
+ bytes: Uint8Array;
128
+ mimeType: string;
129
+ }
130
+ interface StampCapability {
131
+ libraries(): StampLibrary[];
132
+ library(id: string): StampLibrary | null;
133
+ /** Assets of one library, in library order — or every asset when omitted. */
134
+ assets(libraryId?: string): StampAsset[];
135
+ asset(id: string): StampAsset | null;
136
+ /** The asset's paintable preview, or null while none is cached. */
137
+ assetPreview(id: string): StampAssetPreview | null;
138
+ /** Placement bytes; derived from the canonical page for PDF-backed libraries. */
139
+ assetBytes(id: string): Uint8Array | null;
140
+ /** Canonical library PDF bytes, or null for a loose library/unknown id. */
141
+ libraryBytes(id: string): Uint8Array | null;
142
+ /**
143
+ * Import a PDF as a stamp library: every page becomes one vector asset
144
+ * (single-page PDF bytes + a cached preview render). Uses the asset
145
+ * engine; in a cloud deployment without one configured this rejects with
146
+ * an actionable error. Resolves to the new library id.
147
+ */
148
+ importLibraryPdf(source: BinarySource, opts?: ImportLibraryOptions): Promise<string>;
149
+ /**
150
+ * Add a single asset. A PDF added to a canonical library is inserted as a
151
+ * page and receives `/PieceInfo`; loose assets keep their bytes directly.
152
+ * Raster input cannot be appended to a canonical PDF library.
153
+ */
154
+ addAsset(input: AddAssetInput): Promise<string>;
155
+ /** Remove an asset, deleting its canonical page before state changes when PDF-backed. */
156
+ removeAsset(id: string): Promise<void>;
157
+ /** Remove a library and every asset in it, ordered with in-flight library mutations. */
158
+ removeLibrary(id: string): Promise<void>;
159
+ /**
160
+ * Arm an asset on a document: the next click on that document's pages
161
+ * places it (and the hover ghost previews the exact placement). With
162
+ * scripting enabled, form-backed PDFs are evaluated against that target
163
+ * document and flattened first. Rides `annotation.armStamp` — bytes,
164
+ * preview, and intrinsic size all travel along, so vector stamps keep
165
+ * their true aspect.
166
+ */
167
+ armAsset(documentId: string, assetId: string, opts?: {
168
+ targetWidth?: number;
169
+ }): Promise<void>;
170
+ /** Disarm the stamp tool on a document. */
171
+ disarm(documentId: string): void;
172
+ }
173
+ declare const StampToken: import("@embedpdf/core").CapabilityToken<StampCapability>;
174
+ //#endregion
175
+ //#region src/stamp.plugin.d.ts
176
+ /**
177
+ * The stamp plugin. WORKSPACE-scoped: libraries are shared across every open
178
+ * document; placement names its document explicitly (`armAsset(documentId, …)`)
179
+ * and delegates to that document's annotation plugin — no hard `requires`,
180
+ * because the annotation token is document-scoped and resolved lazily per
181
+ * placement (a viewer without the annotation plugin fails at the arm call,
182
+ * with the kernel's own missing-capability error).
183
+ */
184
+ declare const stampPlugin: (config?: StampConfig) => import("@embedpdf/core").PluginDef<StampState, StampAction, StampCapability>;
185
+ //#endregion
186
+ export { type AddAssetInput, type ImportLibraryOptions, type StampAsset, type StampAssetKind, type StampAssetPreview, type StampCapability, type StampConfig, type StampLibrary, type StampState, StampToken, stampPlugin };
187
+ //# sourceMappingURL=index.d.ts.map