@embedpdf/plugin-stamp 3.0.0-next.19 → 3.0.0-next.20

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,6 +1,6 @@
1
1
  import { BatchResult, DeepPartial, EventHook, OperationOptions, SettingsApi } from "@embedpdf/core";
2
- import { StampPlacement, StampPlacement as StampPlacement$1 } from "@embedpdf/plugin-annotation/contract";
3
2
  import { Annotation, AnnotationRef, BinarySource, LocalEngine, PageRef } from "@embedpdf/engine-core/runtime";
3
+ import { StampPlacement, StampPlacement as StampPlacement$1 } from "@embedpdf/plugin-annotation/contract";
4
4
  //#region src/token.d.ts
5
5
  declare const StampToken: import("@embedpdf/core").CapabilityToken<StampCapability>;
6
6
  //#endregion
@@ -61,7 +61,8 @@ type StampAssetKind = 'stamp' | 'signature' | 'initials';
61
61
  type StampLibraryKind = string;
62
62
  /**
63
63
  * How a mark is authored: drawn strokes (kept as a vector path), typed text
64
- * in a registered font (embedded by the flatten), a raster image, or a page
64
+ * in a standard font or one of the `fonts` setting's (embedded by the
65
+ * flatten), a raster image, or a page
65
66
  * of a PDF. Ink strokes are in points, from the top-left and y down like
66
67
  * every page position, any origin — the asset page is the mark's bounds.
67
68
  */
@@ -142,6 +143,17 @@ interface StampLibrary {
142
143
  * destroyed with the plugin.
143
144
  */
144
145
  type StampAssetEngine = LocalEngine | (() => LocalEngine | Promise<LocalEngine>);
146
+ /**
147
+ * A font typed marks can be written in (`mark: { kind: 'text', fontFamily: key }`), beyond the
148
+ * standard 14 and the asset engine's own: registered on the asset engine the first time a mark
149
+ * names it.
150
+ */
151
+ interface StampFont {
152
+ /** What a typed mark's `fontFamily` names it by. */
153
+ readonly key: string;
154
+ /** Its TrueType or OpenType file, read the first time a mark names it. */
155
+ readonly load: () => Promise<Uint8Array>;
156
+ }
145
157
  /**
146
158
  * The stamp plugin's settings. `stampPlugin(config)` registers them over
147
159
  * {@link STAMP_DEFAULTS}, and `updateSettings()` changes them while the app
@@ -160,6 +172,12 @@ interface StampSettings {
160
172
  * ```
161
173
  */
162
174
  readonly assetEngine: StampAssetEngine | null;
175
+ /**
176
+ * The fonts typed marks can be written in, each registered on the asset engine the first time
177
+ * a mark names it: a mark is written on the asset engine, so the font goes there, whichever
178
+ * engine the viewer draws with.
179
+ */
180
+ readonly fonts: readonly StampFont[];
163
181
  /** The width of a stamp's thumbnail, in device pixels. */
164
182
  readonly previewWidth: number;
165
183
  /**
@@ -427,5 +445,5 @@ interface StampCapability extends SettingsApi<StampSettings> {
427
445
  readonly onLibraryChanged: EventHook<StampLibraryChangedEvent>;
428
446
  }
429
447
  //#endregion
430
- export { StampSettings as A, StampLibraryCreatedEvent as C, StampLibraryPatch as D, StampLibraryKind as E, DEFAULT_LIBRARY_KIND as F, StampToken as I, memoryStampStore as M, persistStampLibraries as N, StampLibraryUpdatedEvent as O, restoreStampLibraries as P, StampLibraryChangedEvent as S, StampLibraryFilter as T, StampAssetUpdatedEvent as _, MarkSource as a, StampDocumentOptions as b, StampArmOptions as c, StampAssetDeletedEvent as d, StampAssetEngine as f, StampAssetPreview as g, StampAssetPatch as h, ImportLibraryOptions as i, StampLibraryStore as j, StampPlacement$1 as k, StampAsset as l, StampAssetKind as m, AssetFromAnnotationsInput as n, STAMP_DEFAULTS as o, StampAssetFilter as p, CreateLibraryOptions as r, StampArmChangedEvent as s, AddAssetInput as t, StampAssetCreatedEvent as u, StampCapability as v, StampLibraryDeletedEvent as w, StampLibrary as x, StampConfig as y };
431
- //# sourceMappingURL=contract-CjGXUUDJ.d.ts.map
448
+ export { StampPlacement$1 as A, StampLibraryChangedEvent as C, StampLibraryKind as D, StampLibraryFilter as E, restoreStampLibraries as F, DEFAULT_LIBRARY_KIND as I, StampToken as L, StampLibraryStore as M, memoryStampStore as N, StampLibraryPatch as O, persistStampLibraries as P, StampLibrary as S, StampLibraryDeletedEvent as T, StampAssetUpdatedEvent as _, MarkSource as a, StampDocumentOptions as b, StampArmOptions as c, StampAssetDeletedEvent as d, StampAssetEngine as f, StampAssetPreview as g, StampAssetPatch as h, ImportLibraryOptions as i, StampSettings as j, StampLibraryUpdatedEvent as k, StampAsset as l, StampAssetKind as m, AssetFromAnnotationsInput as n, STAMP_DEFAULTS as o, StampAssetFilter as p, CreateLibraryOptions as r, StampArmChangedEvent as s, AddAssetInput as t, StampAssetCreatedEvent as u, StampCapability as v, StampLibraryCreatedEvent as w, StampFont as x, StampConfig as y };
449
+ //# sourceMappingURL=contract-BQP56Vp4.d.cts.map
@@ -1,6 +1,6 @@
1
1
  import { BatchResult, DeepPartial, EventHook, OperationOptions, SettingsApi } from "@embedpdf/core";
2
- import { Annotation, AnnotationRef, BinarySource, LocalEngine, PageRef } from "@embedpdf/engine-core/runtime";
3
2
  import { StampPlacement, StampPlacement as StampPlacement$1 } from "@embedpdf/plugin-annotation/contract";
3
+ import { Annotation, AnnotationRef, BinarySource, LocalEngine, PageRef } from "@embedpdf/engine-core/runtime";
4
4
  //#region src/token.d.ts
5
5
  declare const StampToken: import("@embedpdf/core").CapabilityToken<StampCapability>;
6
6
  //#endregion
@@ -61,7 +61,8 @@ type StampAssetKind = 'stamp' | 'signature' | 'initials';
61
61
  type StampLibraryKind = string;
62
62
  /**
63
63
  * How a mark is authored: drawn strokes (kept as a vector path), typed text
64
- * in a registered font (embedded by the flatten), a raster image, or a page
64
+ * in a standard font or one of the `fonts` setting's (embedded by the
65
+ * flatten), a raster image, or a page
65
66
  * of a PDF. Ink strokes are in points, from the top-left and y down like
66
67
  * every page position, any origin — the asset page is the mark's bounds.
67
68
  */
@@ -142,6 +143,17 @@ interface StampLibrary {
142
143
  * destroyed with the plugin.
143
144
  */
144
145
  type StampAssetEngine = LocalEngine | (() => LocalEngine | Promise<LocalEngine>);
146
+ /**
147
+ * A font typed marks can be written in (`mark: { kind: 'text', fontFamily: key }`), beyond the
148
+ * standard 14 and the asset engine's own: registered on the asset engine the first time a mark
149
+ * names it.
150
+ */
151
+ interface StampFont {
152
+ /** What a typed mark's `fontFamily` names it by. */
153
+ readonly key: string;
154
+ /** Its TrueType or OpenType file, read the first time a mark names it. */
155
+ readonly load: () => Promise<Uint8Array>;
156
+ }
145
157
  /**
146
158
  * The stamp plugin's settings. `stampPlugin(config)` registers them over
147
159
  * {@link STAMP_DEFAULTS}, and `updateSettings()` changes them while the app
@@ -160,6 +172,12 @@ interface StampSettings {
160
172
  * ```
161
173
  */
162
174
  readonly assetEngine: StampAssetEngine | null;
175
+ /**
176
+ * The fonts typed marks can be written in, each registered on the asset engine the first time
177
+ * a mark names it: a mark is written on the asset engine, so the font goes there, whichever
178
+ * engine the viewer draws with.
179
+ */
180
+ readonly fonts: readonly StampFont[];
163
181
  /** The width of a stamp's thumbnail, in device pixels. */
164
182
  readonly previewWidth: number;
165
183
  /**
@@ -427,5 +445,5 @@ interface StampCapability extends SettingsApi<StampSettings> {
427
445
  readonly onLibraryChanged: EventHook<StampLibraryChangedEvent>;
428
446
  }
429
447
  //#endregion
430
- export { StampSettings as A, StampLibraryCreatedEvent as C, StampLibraryPatch as D, StampLibraryKind as E, DEFAULT_LIBRARY_KIND as F, StampToken as I, memoryStampStore as M, persistStampLibraries as N, StampLibraryUpdatedEvent as O, restoreStampLibraries as P, StampLibraryChangedEvent as S, StampLibraryFilter as T, StampAssetUpdatedEvent as _, MarkSource as a, StampDocumentOptions as b, StampArmOptions as c, StampAssetDeletedEvent as d, StampAssetEngine as f, StampAssetPreview as g, StampAssetPatch as h, ImportLibraryOptions as i, StampLibraryStore as j, StampPlacement$1 as k, StampAsset as l, StampAssetKind as m, AssetFromAnnotationsInput as n, STAMP_DEFAULTS as o, StampAssetFilter as p, CreateLibraryOptions as r, StampArmChangedEvent as s, AddAssetInput as t, StampAssetCreatedEvent as u, StampCapability as v, StampLibraryDeletedEvent as w, StampLibrary as x, StampConfig as y };
431
- //# sourceMappingURL=contract-CEeBOug9.d.cts.map
448
+ export { StampPlacement$1 as A, StampLibraryChangedEvent as C, StampLibraryKind as D, StampLibraryFilter as E, restoreStampLibraries as F, DEFAULT_LIBRARY_KIND as I, StampToken as L, StampLibraryStore as M, memoryStampStore as N, StampLibraryPatch as O, persistStampLibraries as P, StampLibrary as S, StampLibraryDeletedEvent as T, StampAssetUpdatedEvent as _, MarkSource as a, StampDocumentOptions as b, StampArmOptions as c, StampAssetDeletedEvent as d, StampAssetEngine as f, StampAssetPreview as g, StampAssetPatch as h, ImportLibraryOptions as i, StampSettings as j, StampLibraryUpdatedEvent as k, StampAsset as l, StampAssetKind as m, AssetFromAnnotationsInput as n, STAMP_DEFAULTS as o, StampAssetFilter as p, CreateLibraryOptions as r, StampArmChangedEvent as s, AddAssetInput as t, StampAssetCreatedEvent as u, StampCapability as v, StampLibraryCreatedEvent as w, StampFont as x, StampConfig as y };
449
+ //# sourceMappingURL=contract-D6Hs6iO3.d.ts.map
@@ -77,10 +77,11 @@ function stampPieceInfo(kind, options = {}) {
77
77
  /** What the stamp settings are when the app registers none. */
78
78
  const STAMP_DEFAULTS = {
79
79
  assetEngine: null,
80
+ fonts: [],
80
81
  previewWidth: 256,
81
82
  dynamic: true
82
83
  };
83
84
  //#endregion
84
85
  export { assetIdFor as a, parseStampKey as c, stampPieceInfo as d, StampToken as f, STAMP_PIECEINFO_APP as i, stampKey as l, DEFAULT_LIBRARY_KIND as n, customStampName as o, STAMP_LIBRARY_PIECEINFO_APP as r, libraryKindFromPdfName as s, STAMP_DEFAULTS as t, stampLibraryPieceInfo as u };
85
86
 
86
- //# sourceMappingURL=contract-CJBvneyw.js.map
87
+ //# sourceMappingURL=contract-DHcn38S9.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-DHcn38S9.js","names":[],"sources":["../src/token.ts","../src/convention.ts","../src/contract.ts"],"sourcesContent":["/** The package token, created once here and re-exported by `contract.ts`. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { StampCapability } from './contract';\n\nexport const StampToken = createCapabilityToken<StampCapability>('stamp', {\n hint: `add stampPlugin() from '@embedpdf/plugin-stamp' to your plugins list`,\n});\n","/**\n * Acrobat's stamp-library convention, interpreted in one place. A library is\n * a PDF whose `/Names /Pages` registry names each stamp page with a key of\n * the form `identifier=label`:\n *\n * - `identifier` (before the first `=`) is the stamp's durable identity\n * and becomes the placed annotation's `/Name` — a standard name such as\n * `Approved`, or a custom one such as Acrobat's `#LBGiYhk8V_oAfmqAPENiwD`;\n * - `label` (after it) is what the picker shows and the placed\n * annotation's default `/Subj`.\n *\n * The engine never interprets key text; this module does. A key without\n * `=` is its own label. `#` is never stripped: it is part of the identity.\n */\nimport type { PieceInfoPatch } from '@embedpdf/engine-core/runtime';\nimport type { StampAssetKind } from './contract';\n\nexport interface StampKey {\n name: string;\n label: string;\n}\n\nexport function parseStampKey(key: string): StampKey {\n const separator = key.indexOf('=');\n if (separator < 0) return { name: key, label: key };\n return { name: key.slice(0, separator), label: key.slice(separator + 1) };\n}\n\nexport function stampKey(name: string, label: string): string {\n return `${name}=${label}`;\n}\n\nconst BASE62 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\n/**\n * A fresh identifier for a stamp authored here, in Acrobat's own shape\n * (`#` + 22 base-62 characters) so a stamp created in this viewer keeps its\n * identity when the library is opened and placed in Acrobat.\n */\nexport function customStampName(random: () => number = Math.random): string {\n let name = '#';\n for (let i = 0; i < 22; i++) name += BASE62[Math.floor(random() * BASE62.length)];\n return name;\n}\n\n/** Asset ids are derived, not allocated: library id + identifier. */\nexport function assetIdFor(libraryId: string, name: string): string {\n return `${libraryId}:${name}`;\n}\n\n// ── PieceInfo: only what has no standard home ────────────────────────────────\n//\n// The title, the registry, and the artwork are standard PDF. What remains\n// (a durable library id, categories, a locale, a stamp's kind and an explicit\n// `/Subj` override) rides `/PieceInfo` under these application names, in the\n// shape below, so every write produces the dictionary the import reads.\n\n/** Catalog `/PieceInfo` application name for library-level data. */\nexport const STAMP_LIBRARY_PIECEINFO_APP = 'EMBD_StampLibrary';\n/** Page `/PieceInfo` application name for per-stamp data. */\nexport const STAMP_PIECEINFO_APP = 'EMBD_Stamp';\n/** The PieceInfo format version both dictionaries carry in `Version`. */\nexport const STAMP_PIECEINFO_VERSION = 2;\n\n/** The library kind every file has unless it says otherwise. */\nexport const DEFAULT_LIBRARY_KIND = 'stamps';\n\n/** `/Kind` names: the two the plugin defines keep their PDF spellings; others are written as given. */\nexport function libraryKindToPdfName(kind: string): string {\n return kind === 'stamps' ? 'StampLibrary' : kind === 'signatures' ? 'SignatureLibrary' : kind;\n}\n\nexport function libraryKindFromPdfName(name: string | undefined): string {\n if (!name || name === 'StampLibrary') return DEFAULT_LIBRARY_KIND;\n return name === 'SignatureLibrary' ? 'signatures' : name;\n}\n\nexport function stampKindToPdfName(kind: StampAssetKind): string {\n return kind === 'signature' ? 'Signature' : kind === 'initials' ? 'Initials' : 'Stamp';\n}\n\n/** The catalog patch: library id, categories, locale. The name is `/Title`. */\nexport function stampLibraryPieceInfo(\n id: string,\n options: { kind?: string; categories?: readonly string[]; locale?: string } = {},\n): PieceInfoPatch {\n return {\n Version: STAMP_PIECEINFO_VERSION,\n Id: id,\n Kind: { name: libraryKindToPdfName(options.kind ?? DEFAULT_LIBRARY_KIND) },\n // Format version 2 keeps the name in the PDF's /Title.\n Name: null,\n Categories: options.categories ?? null,\n Locale: options.locale ?? null,\n };\n}\n\n/** The page patch: kind, an explicit `/Subj` override, categories. */\nexport function stampPieceInfo(\n kind: StampAssetKind,\n options: { subject?: string | null; categories?: readonly string[] } = {},\n): PieceInfoPatch {\n return {\n Version: STAMP_PIECEINFO_VERSION,\n Kind: { name: stampKindToPdfName(kind) },\n // Format version 2 keeps the identifier and label in the /Names /Pages\n // key; only an explicit /Subj override has no standard home. The format\n // version 1 `Name`/`Subject` keys are cleared, so a re-imported format\n // version 1 library cannot disagree with its registry.\n Name: null,\n Subject: null,\n SubjectOverride: options.subject ?? null,\n Categories: options.categories ?? null,\n };\n}\n","/** @embedpdf/plugin-stamp/contract: the public stamp vocabulary. */\nimport type {\n BatchResult,\n DeepPartial,\n EventHook,\n OperationOptions,\n SettingsApi,\n} from '@embedpdf/core';\nimport type {\n Annotation,\n AnnotationRef,\n BinarySource,\n LocalEngine,\n PageRef,\n} from '@embedpdf/engine-core/runtime';\nimport type { StampPlacement } from '@embedpdf/plugin-annotation/contract';\n\nexport { StampToken } from './token';\nexport { DEFAULT_LIBRARY_KIND } from './convention';\nexport type { StampLibraryStore } from './persistence';\nexport type { StampPlacement } from '@embedpdf/plugin-annotation/contract';\n\n/**\n * The stamp plugin: a workspace-scoped asset substrate.\n *\n * The design law (\"documents have a home; assets ride the wire\"): imported\n * PDF libraries retain one canonical PDF whose catalog/page `/PieceInfo`\n * carries their metadata. Per-asset PDFs and previews are derived caches used\n * for placement. Standalone PNG/JPEG assets remain loose because the engine\n * intentionally has no raster-to-PDF-page authoring primitive.\n */\n\nexport type StampAssetKind = 'stamp' | 'signature' | 'initials';\n\n/**\n * What a library file is for: the routing key a surface queries by. Open:\n * the plugin defines `stamps` (the default) and `signatures`; an embedder\n * may define its own (`toolbar`, `legal-seals`). Persisted in the file.\n */\nexport type StampLibraryKind = string;\n\n/**\n * How a mark is authored: drawn strokes (kept as a vector path), typed text\n * in a standard font or one of the `fonts` setting's (embedded by the\n * flatten), a raster image, or a page\n * of a PDF. Ink strokes are in points, from the top-left and y down like\n * every page position, any origin — the asset page is the mark's bounds.\n */\nexport type MarkSource =\n | {\n kind: 'ink';\n strokes: ReadonlyArray<ReadonlyArray<{ x: number; y: number }>>;\n color?: string;\n strokeWidth?: number;\n }\n | { kind: 'text'; text: string; fontFamily: string; color?: string; fontSize?: number }\n | { kind: 'image'; source: BinarySource }\n | { kind: 'pdf'; source: BinarySource; pageIndex?: number };\n\n/**\n * One asset's serializable descriptor. The bytes and the cached preview are\n * deliberately not here: session state holds serializable data only, and\n * binary lives in the capability and crosses only as call arguments and\n * return values, mirroring the engine's own BinarySource rule.\n */\nexport interface StampAsset {\n /** Derived and stable: `${libraryId}:${name}` (never allocated). */\n id: string;\n libraryId: string;\n kind: StampAssetKind;\n /**\n * The stamp's identifier: the text before the first `=` in its library\n * key, and the placed annotation's `/Name`: a standard name (`Approved`)\n * or a custom one (`#LBGiYhk8V_oAfmqAPENiwD`). Not display text.\n */\n name: string;\n /** What the picker shows and the placed annotation's default `/Subj`:\n * the text after `=` in the library key (`Goedgekeurd`). */\n label: string;\n /** Intrinsic size in PDF points (the source page's crop box / image pixels 1:1). */\n size: { width: number; height: number };\n /** The library page that is this asset. Every asset is a page: a raster\n * added to a library becomes a page carrying the image. */\n page: PageRef;\n /** An explicit `/Subj` override (PieceInfo); placements use `label` otherwise. */\n subject?: string;\n categories?: string[];\n}\n\n/**\n * A library is a PDF: its `/Title` is the name, its `/Names /Pages` registry\n * the assets, its pages the artwork, PieceInfo only what has no standard\n * home. One imported PDF becomes one library; `exportLibrary` returns it.\n */\nexport interface StampLibrary {\n /** PieceInfo `Id`: stable while the title is editable. */\n id: string;\n name: string;\n /** PieceInfo `Kind`: `'stamps'`, `'signatures'`, or an embedder's own. */\n kind: StampLibraryKind;\n /** PieceInfo `Locale`: the language of the labels, when the library says. */\n locale?: string;\n categories?: string[];\n /** Asset ids in display order. */\n assetIds: string[];\n}\n\n// ── settings ──────────────────────────────────────────────────────────────\n\n/**\n * The local engine stamp libraries open in, or a function that makes one. A\n * function is called on the first import, not at startup, and its engine is\n * destroyed with the plugin.\n */\nexport type StampAssetEngine = LocalEngine | (() => LocalEngine | Promise<LocalEngine>);\n\n/**\n * A font typed marks can be written in (`mark: { kind: 'text', fontFamily: key }`), beyond the\n * standard 14 and the asset engine's own: registered on the asset engine the first time a mark\n * names it.\n */\nexport interface StampFont {\n /** What a typed mark's `fontFamily` names it by. */\n readonly key: string;\n /** Its TrueType or OpenType file, read the first time a mark names it. */\n readonly load: () => Promise<Uint8Array>;\n}\n\n/**\n * The stamp plugin's settings. `stampPlugin(config)` registers them over\n * {@link STAMP_DEFAULTS}, and `updateSettings()` changes them while the app\n * runs.\n */\nexport interface StampSettings {\n /**\n * The engine stamp libraries open in. `null` uses the viewer's own engine,\n * which is right when that engine is local. A cloud viewer passes a local\n * engine, or a function that makes one:\n *\n * ```ts\n * stampPlugin({\n * assetEngine: () => import('@embedpdf/engine').then((module) => module.createLocalEngine()),\n * })\n * ```\n */\n readonly assetEngine: StampAssetEngine | null;\n /**\n * The fonts typed marks can be written in, each registered on the asset engine the first time\n * a mark names it: a mark is written on the asset engine, so the font goes there, whichever\n * engine the viewer draws with.\n */\n readonly fonts: readonly StampFont[];\n /** The width of a stamp's thumbnail, in device pixels. */\n readonly previewWidth: number;\n /**\n * Fill in a dynamic stamp's form fields when it's armed or placed.\n * Scripting itself is the workspace's one JavaScript switch,\n * `actionsPlugin({ javascript: { enabled } })`: without the actions plugin,\n * or with scripting off, a stamp is placed as it is. `false` keeps every\n * stamp as reviewed, even with scripting on.\n */\n readonly dynamic: boolean;\n}\n\n/** What the stamp settings are when the app registers none. */\nexport const STAMP_DEFAULTS: StampSettings = {\n assetEngine: null,\n fonts: [],\n previewWidth: 256,\n dynamic: true,\n};\n\n/** What `stampPlugin(config)` takes: any of the settings, merged over the defaults. */\nexport type StampConfig = DeepPartial<StampSettings>;\n\n// ── verbs ─────────────────────────────────────────────────────────────────\n\n/**\n * Which document a placing verb acts on. Left out, it is the document in\n * scope (`useStamp()` inside a `<DocumentScope>`, a document plugin's\n * `ctx.get(StampToken)`), else the active document.\n */\nexport interface StampDocumentOptions extends OperationOptions {\n readonly documentId?: string;\n}\n\n/** `armAsset()`'s options. */\nexport interface StampArmOptions extends StampDocumentOptions {\n /** Placed width in PDF points; the stamp's own width by default. */\n readonly targetWidth?: number;\n}\n\nexport interface CreateLibraryOptions extends OperationOptions {\n /** The library's id; a fresh one when left out or taken. */\n readonly id?: string;\n /** What the library is for. Default `'stamps'`. */\n readonly kind?: StampLibraryKind;\n readonly categories?: string[];\n}\n\nexport interface StampLibraryPatch {\n readonly name?: string;\n readonly categories?: string[];\n}\n\nexport interface ImportLibraryOptions extends OperationOptions {\n /**\n * Fallback library name, applied only when the PDF carries no `/Title`\n * (an Acrobat-authored or previously exported library names itself).\n * Default `'Stamps'`.\n */\n name?: string;\n /** Library categories written to catalog `/PieceInfo`. */\n categories?: string[];\n /** Kind stamped onto every imported asset. Default `'stamp'`. */\n kind?: StampAssetKind;\n /** What the file is for; overrides what the file says (an Acrobat-authored set imported for a toolbar). */\n libraryKind?: StampLibraryKind;\n /**\n * Fallback per-page labels for a plain PDF (no `/Names /Pages` registry):\n * every page becomes a stamp named `Stamp<n>` with this label. Ignored\n * when the PDF registers its stamps itself.\n */\n assetName?: (pageIndex: number) => string;\n}\n\nexport interface AddAssetInput {\n /** Target library; omitted, a new single-asset library named after the asset. */\n libraryId?: string;\n /** The identifier (placed `/Name`). Omit to mint an Acrobat-style `#…` one. */\n name?: string;\n /** Picker text and default `/Subj`. Defaults to `name`. */\n label?: string;\n kind?: StampAssetKind;\n subject?: string;\n categories?: string[];\n /**\n * PNG, JPEG, or single-page PDF bytes. Exactly one of `source` / `mark`. A\n * raster becomes a page of the library sized to `size` (default: its\n * pixels as points, 1:1) with the image flattened into it, so every asset\n * is a page and every library a complete PDF.\n */\n source?: BinarySource;\n /** An authored mark: drawn, typed, an image, or a PDF page. Exactly one of `source` / `mark`. */\n mark?: MarkSource;\n /** Thumbnail override for pickers (PNG/JPEG); rendered from the page otherwise. */\n preview?: BinarySource;\n /** Page size in PDF points for a raster source. Ignored for PDF sources (the page has one). */\n size?: { width: number; height: number };\n}\n\n/** What `createAssetFromAnnotations()` takes besides the annotations: where the stamp goes and its name. */\nexport type AssetFromAnnotationsInput = Omit<AddAssetInput, 'source' | 'mark' | 'size'>;\n\nexport interface StampAssetPatch {\n readonly label?: string;\n /** `null` drops the subject override, so placements use the label. */\n readonly subject?: string | null;\n readonly categories?: string[];\n}\n\n/** A cached, browser-paintable render of an asset (PNG from import; raster assets as-is). */\nexport interface StampAssetPreview {\n bytes: Uint8Array;\n mimeType: string;\n}\n\nexport interface StampLibraryFilter {\n readonly kind?: StampLibraryKind | readonly StampLibraryKind[];\n}\nexport interface StampAssetFilter {\n readonly libraryId?: string;\n readonly kind?: StampAssetKind;\n readonly category?: string;\n}\n\n// ── events ────────────────────────────────────────────────────────────────\n\n/** A library's bytes changed, and why: the one to save it on. */\nexport interface StampLibraryChangedEvent {\n readonly libraryId: string;\n readonly reason:\n | 'created'\n | 'imported'\n | 'updated'\n | 'asset-added'\n | 'asset-updated'\n | 'asset-removed'\n | 'removed';\n}\nexport interface StampLibraryCreatedEvent {\n readonly libraryId: string;\n readonly library: StampLibrary;\n}\nexport interface StampLibraryUpdatedEvent {\n readonly libraryId: string;\n readonly library: StampLibrary;\n}\nexport interface StampLibraryDeletedEvent {\n readonly libraryId: string;\n readonly library: null;\n}\nexport interface StampAssetCreatedEvent {\n readonly assetId: string;\n readonly libraryId: string;\n readonly asset: StampAsset;\n}\nexport interface StampAssetUpdatedEvent {\n readonly assetId: string;\n readonly libraryId: string;\n readonly asset: StampAsset;\n}\nexport interface StampAssetDeletedEvent {\n readonly assetId: string;\n readonly libraryId: string;\n readonly asset: null;\n}\n/** A stamp was armed on a document, or disarmed (`asset: null`). */\nexport interface StampArmChangedEvent {\n readonly documentId: string;\n readonly asset: StampAsset | null;\n}\n\n/**\n * Stamp libraries and their assets, shared by every document, and placing\n * them on a document. The placing verbs act on the document in scope, else\n * the active one, or the one their options name (`documentId`). A library is\n * a PDF (one page per asset): `exportLibrary` returns the persistence format,\n * `importLibrary` reads it back. Every verb rejects with a `PluginError`, and\n * every async verb takes a `signal`: cancelled, it rejects\n * `operation-cancelled` and changes nothing. The settings belong to the\n * plugin, not to a document.\n */\nexport interface StampCapability extends SettingsApi<StampSettings> {\n // ── reading ──\n listLibraries(filter?: StampLibraryFilter): readonly StampLibrary[];\n getLibrary(libraryId: string): StampLibrary | null;\n /** Assets in the order a picker shows them: by library, then within it. */\n listAssets(filter?: StampAssetFilter): readonly StampAsset[];\n getAsset(assetId: string): StampAsset | null;\n /** The cached thumbnail (the `previewWidth` setting), or null. */\n getAssetPreview(assetId: string): StampAssetPreview | null;\n /** A preview at any width, rendered by the asset engine and cached per width. Rejects `not-found`. */\n renderAssetPreview(\n assetId: string,\n options: { width: number } & OperationOptions,\n ): Promise<StampAssetPreview | null>;\n /** A copy of the asset's placement bytes (a one-page PDF), or null. */\n readAssetBytes(assetId: string): Uint8Array | null;\n\n // ── libraries ──\n /** Create an empty library. Fires `onLibraryCreated` and `onLibraryChanged`. */\n createLibrary(name: string, options?: CreateLibraryOptions): Promise<{ library: StampLibrary }>;\n /** Rename a library or change its categories. Rejects `not-found`. Fires `onLibraryUpdated`. */\n updateLibrary(\n libraryId: string,\n changes: StampLibraryPatch,\n options?: OperationOptions,\n ): Promise<{ library: StampLibrary }>;\n /** Delete a library with its assets. Fires `onLibraryDeleted`. */\n deleteLibrary(libraryId: string, options?: OperationOptions): Promise<void>;\n /**\n * A PDF becomes a library (one asset per page). Rejects `invalid-input` for\n * bytes that aren't a PDF, `unsupported` without a local asset engine.\n * Fires `onLibraryCreated`, then `onAssetCreated` per stamp.\n */\n importLibrary(\n source: BinarySource,\n options?: ImportLibraryOptions,\n ): Promise<{ library: StampLibrary }>;\n /** The library as the PDF it is. Rejects `not-found`. */\n exportLibrary(libraryId: string, options?: OperationOptions): Promise<Uint8Array>;\n\n // ── assets ──\n /**\n * Add a stamp from bytes or a mark. Rejects `not-found` for an unknown\n * library, `invalid-input` for bytes that aren't a picture or a taken\n * identifier. Fires `onAssetCreated`.\n */\n createAsset(input: AddAssetInput, options?: OperationOptions): Promise<{ asset: StampAsset }>;\n /**\n * Annotations on a page of a document become one stamp, exactly as they\n * look. All or nothing: a hidden annotation, one without an appearance, or\n * one on another page fails the call. Rejects `permission-denied` without\n * `doc.download` (see `canCreateFromAnnotations`), `not-found` for a page\n * that isn't in the document.\n */\n createAssetFromAnnotations(\n page: PageRef | number,\n refs: readonly AnnotationRef[],\n input: AssetFromAnnotationsInput,\n options?: StampDocumentOptions,\n ): Promise<{ asset: StampAsset }>;\n /** Change a stamp's label, subject or categories; its identifier never changes. Rejects `not-found`. */\n updateAsset(\n assetId: string,\n changes: StampAssetPatch,\n options?: OperationOptions,\n ): Promise<{ asset: StampAsset }>;\n /** Remove a stamp from its library. Fires `onAssetDeleted`. */\n deleteAsset(assetId: string, options?: OperationOptions): Promise<void>;\n /** Move a stamp to another library: a copy there, with a new id, then the original goes. */\n moveAsset(\n assetId: string,\n to: { libraryId: string },\n options?: OperationOptions,\n ): Promise<{ asset: StampAsset }>;\n /** Copy a stamp within its library. */\n duplicateAsset(\n assetId: string,\n options?: { label?: string } & OperationOptions,\n ): Promise<{ asset: StampAsset }>;\n\n // ── placing, on one document ──\n /**\n * Arm a stamp: the next click on the document places it, with a preview\n * under the pointer. Rejects `not-found` for an unknown asset,\n * `permission-denied` without `annotations:create` (see `canPlace`).\n * Fires `onArmChanged`.\n */\n armAsset(assetId: string, options?: StampArmOptions): Promise<void>;\n /** Disarm the stamp without placing it. Fires `onArmChanged` when one was armed. */\n disarm(documentId?: string): void;\n /** The stamp the next click on the document places, or null. */\n getArmedAsset(documentId?: string): StampAsset | null;\n /**\n * Place a stamp without the pointer, its middle on `center`, sized by its\n * picture and kept on the page. Resolves `{ annotation }`. Selected only\n * with `select: true`. Rejects `permission-denied` without\n * `annotations:create`, `not-found` for an unknown asset or page.\n */\n placeAsset(\n assetId: string,\n placement: StampPlacement,\n options?: StampDocumentOptions,\n ): Promise<{ annotation: Annotation }>;\n /**\n * Place one stamp at the same spot on several pages (refs or indexes), or\n * on `'all'`. Resolves the placed stamps, and the pages that failed.\n */\n placeAssetOnPages(\n assetId: string,\n pages: readonly (PageRef | number)[] | 'all',\n placement: Omit<StampPlacement, 'page'>,\n options?: StampDocumentOptions,\n ): Promise<BatchResult<Annotation, PageRef>>;\n /** Whether a stamp may be armed or placed on the document (`annotations:create`). */\n canPlace(documentId?: string): boolean;\n /** Whether annotations of the document may become a stamp, which copies them out (`doc.download`). */\n canCreateFromAnnotations(documentId?: string): boolean;\n /** Whether libraries can be imported: false once an import found no local engine to open them in. */\n canImport(): boolean;\n\n // ── events ──\n readonly onLibraryCreated: EventHook<StampLibraryCreatedEvent>;\n readonly onLibraryUpdated: EventHook<StampLibraryUpdatedEvent>;\n readonly onLibraryDeleted: EventHook<StampLibraryDeletedEvent>;\n readonly onAssetCreated: EventHook<StampAssetCreatedEvent>;\n readonly onAssetUpdated: EventHook<StampAssetUpdatedEvent>;\n readonly onAssetDeleted: EventHook<StampAssetDeletedEvent>;\n /** A stamp was armed or disarmed on a document. */\n readonly onArmChanged: EventHook<StampArmChangedEvent>;\n /** A library's bytes changed (subscribe to persist). */\n readonly onLibraryChanged: EventHook<StampLibraryChangedEvent>;\n}\n"],"mappings":";;;AAKA,MAAa,aAAa,sBAAuC,SAAS,EACxE,MAAM,uEACR,CAAC;;;ACeD,SAAgB,cAAc,KAAuB;CACnD,MAAM,YAAY,IAAI,QAAQ,GAAG;CACjC,IAAI,YAAY,GAAG,OAAO;EAAE,MAAM;EAAK,OAAO;CAAI;CAClD,OAAO;EAAE,MAAM,IAAI,MAAM,GAAG,SAAS;EAAG,OAAO,IAAI,MAAM,YAAY,CAAC;CAAE;AAC1E;AAEA,SAAgB,SAAS,MAAc,OAAuB;CAC5D,OAAO,GAAG,KAAK,GAAG;AACpB;AAEA,MAAM,SAAS;;;;;;AAOf,SAAgB,gBAAgB,SAAuB,KAAK,QAAgB;CAC1E,IAAI,OAAO;CACX,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK,QAAQ,OAAO,KAAK,MAAM,OAAO,IAAI,EAAa;CAC/E,OAAO;AACT;;AAGA,SAAgB,WAAW,WAAmB,MAAsB;CAClE,OAAO,GAAG,UAAU,GAAG;AACzB;;AAUA,MAAa,8BAA8B;;AAE3C,MAAa,sBAAsB;;AAKnC,MAAa,uBAAuB;;AAGpC,SAAgB,qBAAqB,MAAsB;CACzD,OAAO,SAAS,WAAW,iBAAiB,SAAS,eAAe,qBAAqB;AAC3F;AAEA,SAAgB,uBAAuB,MAAkC;CACvE,IAAI,CAAC,QAAQ,SAAS,gBAAgB,OAAO;CAC7C,OAAO,SAAS,qBAAqB,eAAe;AACtD;AAEA,SAAgB,mBAAmB,MAA8B;CAC/D,OAAO,SAAS,cAAc,cAAc,SAAS,aAAa,aAAa;AACjF;;AAGA,SAAgB,sBACd,IACA,UAA8E,CAAC,GAC/D;CAChB,OAAO;EACL,SAAA;EACA,IAAI;EACJ,MAAM,EAAE,MAAM,qBAAqB,QAAQ,QAAA,QAA4B,EAAE;EAEzE,MAAM;EACN,YAAY,QAAQ,cAAc;EAClC,QAAQ,QAAQ,UAAU;CAC5B;AACF;;AAGA,SAAgB,eACd,MACA,UAAuE,CAAC,GACxD;CAChB,OAAO;EACL,SAAA;EACA,MAAM,EAAE,MAAM,mBAAmB,IAAI,EAAE;EAKvC,MAAM;EACN,SAAS;EACT,iBAAiB,QAAQ,WAAW;EACpC,YAAY,QAAQ,cAAc;CACpC;AACF;;;;ACmDA,MAAa,iBAAgC;CAC3C,aAAa;CACb,OAAO,CAAC;CACR,cAAc;CACd,SAAS;AACX"}
@@ -76,6 +76,7 @@ function stampPieceInfo(kind, options = {}) {
76
76
  /** What the stamp settings are when the app registers none. */
77
77
  const STAMP_DEFAULTS = {
78
78
  assetEngine: null,
79
+ fonts: [],
79
80
  previewWidth: 256,
80
81
  dynamic: true
81
82
  };
@@ -153,4 +154,4 @@ Object.defineProperty(exports, "stampPieceInfo", {
153
154
  }
154
155
  });
155
156
 
156
- //# sourceMappingURL=contract-lDLkRDYV.cjs.map
157
+ //# sourceMappingURL=contract-Dj5KiMyW.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-Dj5KiMyW.cjs","names":[],"sources":["../src/token.ts","../src/convention.ts","../src/contract.ts"],"sourcesContent":["/** The package token, created once here and re-exported by `contract.ts`. */\nimport { createCapabilityToken } from '@embedpdf/core';\n\nimport type { StampCapability } from './contract';\n\nexport const StampToken = createCapabilityToken<StampCapability>('stamp', {\n hint: `add stampPlugin() from '@embedpdf/plugin-stamp' to your plugins list`,\n});\n","/**\n * Acrobat's stamp-library convention, interpreted in one place. A library is\n * a PDF whose `/Names /Pages` registry names each stamp page with a key of\n * the form `identifier=label`:\n *\n * - `identifier` (before the first `=`) is the stamp's durable identity\n * and becomes the placed annotation's `/Name` — a standard name such as\n * `Approved`, or a custom one such as Acrobat's `#LBGiYhk8V_oAfmqAPENiwD`;\n * - `label` (after it) is what the picker shows and the placed\n * annotation's default `/Subj`.\n *\n * The engine never interprets key text; this module does. A key without\n * `=` is its own label. `#` is never stripped: it is part of the identity.\n */\nimport type { PieceInfoPatch } from '@embedpdf/engine-core/runtime';\nimport type { StampAssetKind } from './contract';\n\nexport interface StampKey {\n name: string;\n label: string;\n}\n\nexport function parseStampKey(key: string): StampKey {\n const separator = key.indexOf('=');\n if (separator < 0) return { name: key, label: key };\n return { name: key.slice(0, separator), label: key.slice(separator + 1) };\n}\n\nexport function stampKey(name: string, label: string): string {\n return `${name}=${label}`;\n}\n\nconst BASE62 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n\n/**\n * A fresh identifier for a stamp authored here, in Acrobat's own shape\n * (`#` + 22 base-62 characters) so a stamp created in this viewer keeps its\n * identity when the library is opened and placed in Acrobat.\n */\nexport function customStampName(random: () => number = Math.random): string {\n let name = '#';\n for (let i = 0; i < 22; i++) name += BASE62[Math.floor(random() * BASE62.length)];\n return name;\n}\n\n/** Asset ids are derived, not allocated: library id + identifier. */\nexport function assetIdFor(libraryId: string, name: string): string {\n return `${libraryId}:${name}`;\n}\n\n// ── PieceInfo: only what has no standard home ────────────────────────────────\n//\n// The title, the registry, and the artwork are standard PDF. What remains\n// (a durable library id, categories, a locale, a stamp's kind and an explicit\n// `/Subj` override) rides `/PieceInfo` under these application names, in the\n// shape below, so every write produces the dictionary the import reads.\n\n/** Catalog `/PieceInfo` application name for library-level data. */\nexport const STAMP_LIBRARY_PIECEINFO_APP = 'EMBD_StampLibrary';\n/** Page `/PieceInfo` application name for per-stamp data. */\nexport const STAMP_PIECEINFO_APP = 'EMBD_Stamp';\n/** The PieceInfo format version both dictionaries carry in `Version`. */\nexport const STAMP_PIECEINFO_VERSION = 2;\n\n/** The library kind every file has unless it says otherwise. */\nexport const DEFAULT_LIBRARY_KIND = 'stamps';\n\n/** `/Kind` names: the two the plugin defines keep their PDF spellings; others are written as given. */\nexport function libraryKindToPdfName(kind: string): string {\n return kind === 'stamps' ? 'StampLibrary' : kind === 'signatures' ? 'SignatureLibrary' : kind;\n}\n\nexport function libraryKindFromPdfName(name: string | undefined): string {\n if (!name || name === 'StampLibrary') return DEFAULT_LIBRARY_KIND;\n return name === 'SignatureLibrary' ? 'signatures' : name;\n}\n\nexport function stampKindToPdfName(kind: StampAssetKind): string {\n return kind === 'signature' ? 'Signature' : kind === 'initials' ? 'Initials' : 'Stamp';\n}\n\n/** The catalog patch: library id, categories, locale. The name is `/Title`. */\nexport function stampLibraryPieceInfo(\n id: string,\n options: { kind?: string; categories?: readonly string[]; locale?: string } = {},\n): PieceInfoPatch {\n return {\n Version: STAMP_PIECEINFO_VERSION,\n Id: id,\n Kind: { name: libraryKindToPdfName(options.kind ?? DEFAULT_LIBRARY_KIND) },\n // Format version 2 keeps the name in the PDF's /Title.\n Name: null,\n Categories: options.categories ?? null,\n Locale: options.locale ?? null,\n };\n}\n\n/** The page patch: kind, an explicit `/Subj` override, categories. */\nexport function stampPieceInfo(\n kind: StampAssetKind,\n options: { subject?: string | null; categories?: readonly string[] } = {},\n): PieceInfoPatch {\n return {\n Version: STAMP_PIECEINFO_VERSION,\n Kind: { name: stampKindToPdfName(kind) },\n // Format version 2 keeps the identifier and label in the /Names /Pages\n // key; only an explicit /Subj override has no standard home. The format\n // version 1 `Name`/`Subject` keys are cleared, so a re-imported format\n // version 1 library cannot disagree with its registry.\n Name: null,\n Subject: null,\n SubjectOverride: options.subject ?? null,\n Categories: options.categories ?? null,\n };\n}\n","/** @embedpdf/plugin-stamp/contract: the public stamp vocabulary. */\nimport type {\n BatchResult,\n DeepPartial,\n EventHook,\n OperationOptions,\n SettingsApi,\n} from '@embedpdf/core';\nimport type {\n Annotation,\n AnnotationRef,\n BinarySource,\n LocalEngine,\n PageRef,\n} from '@embedpdf/engine-core/runtime';\nimport type { StampPlacement } from '@embedpdf/plugin-annotation/contract';\n\nexport { StampToken } from './token';\nexport { DEFAULT_LIBRARY_KIND } from './convention';\nexport type { StampLibraryStore } from './persistence';\nexport type { StampPlacement } from '@embedpdf/plugin-annotation/contract';\n\n/**\n * The stamp plugin: a workspace-scoped asset substrate.\n *\n * The design law (\"documents have a home; assets ride the wire\"): imported\n * PDF libraries retain one canonical PDF whose catalog/page `/PieceInfo`\n * carries their metadata. Per-asset PDFs and previews are derived caches used\n * for placement. Standalone PNG/JPEG assets remain loose because the engine\n * intentionally has no raster-to-PDF-page authoring primitive.\n */\n\nexport type StampAssetKind = 'stamp' | 'signature' | 'initials';\n\n/**\n * What a library file is for: the routing key a surface queries by. Open:\n * the plugin defines `stamps` (the default) and `signatures`; an embedder\n * may define its own (`toolbar`, `legal-seals`). Persisted in the file.\n */\nexport type StampLibraryKind = string;\n\n/**\n * How a mark is authored: drawn strokes (kept as a vector path), typed text\n * in a standard font or one of the `fonts` setting's (embedded by the\n * flatten), a raster image, or a page\n * of a PDF. Ink strokes are in points, from the top-left and y down like\n * every page position, any origin — the asset page is the mark's bounds.\n */\nexport type MarkSource =\n | {\n kind: 'ink';\n strokes: ReadonlyArray<ReadonlyArray<{ x: number; y: number }>>;\n color?: string;\n strokeWidth?: number;\n }\n | { kind: 'text'; text: string; fontFamily: string; color?: string; fontSize?: number }\n | { kind: 'image'; source: BinarySource }\n | { kind: 'pdf'; source: BinarySource; pageIndex?: number };\n\n/**\n * One asset's serializable descriptor. The bytes and the cached preview are\n * deliberately not here: session state holds serializable data only, and\n * binary lives in the capability and crosses only as call arguments and\n * return values, mirroring the engine's own BinarySource rule.\n */\nexport interface StampAsset {\n /** Derived and stable: `${libraryId}:${name}` (never allocated). */\n id: string;\n libraryId: string;\n kind: StampAssetKind;\n /**\n * The stamp's identifier: the text before the first `=` in its library\n * key, and the placed annotation's `/Name`: a standard name (`Approved`)\n * or a custom one (`#LBGiYhk8V_oAfmqAPENiwD`). Not display text.\n */\n name: string;\n /** What the picker shows and the placed annotation's default `/Subj`:\n * the text after `=` in the library key (`Goedgekeurd`). */\n label: string;\n /** Intrinsic size in PDF points (the source page's crop box / image pixels 1:1). */\n size: { width: number; height: number };\n /** The library page that is this asset. Every asset is a page: a raster\n * added to a library becomes a page carrying the image. */\n page: PageRef;\n /** An explicit `/Subj` override (PieceInfo); placements use `label` otherwise. */\n subject?: string;\n categories?: string[];\n}\n\n/**\n * A library is a PDF: its `/Title` is the name, its `/Names /Pages` registry\n * the assets, its pages the artwork, PieceInfo only what has no standard\n * home. One imported PDF becomes one library; `exportLibrary` returns it.\n */\nexport interface StampLibrary {\n /** PieceInfo `Id`: stable while the title is editable. */\n id: string;\n name: string;\n /** PieceInfo `Kind`: `'stamps'`, `'signatures'`, or an embedder's own. */\n kind: StampLibraryKind;\n /** PieceInfo `Locale`: the language of the labels, when the library says. */\n locale?: string;\n categories?: string[];\n /** Asset ids in display order. */\n assetIds: string[];\n}\n\n// ── settings ──────────────────────────────────────────────────────────────\n\n/**\n * The local engine stamp libraries open in, or a function that makes one. A\n * function is called on the first import, not at startup, and its engine is\n * destroyed with the plugin.\n */\nexport type StampAssetEngine = LocalEngine | (() => LocalEngine | Promise<LocalEngine>);\n\n/**\n * A font typed marks can be written in (`mark: { kind: 'text', fontFamily: key }`), beyond the\n * standard 14 and the asset engine's own: registered on the asset engine the first time a mark\n * names it.\n */\nexport interface StampFont {\n /** What a typed mark's `fontFamily` names it by. */\n readonly key: string;\n /** Its TrueType or OpenType file, read the first time a mark names it. */\n readonly load: () => Promise<Uint8Array>;\n}\n\n/**\n * The stamp plugin's settings. `stampPlugin(config)` registers them over\n * {@link STAMP_DEFAULTS}, and `updateSettings()` changes them while the app\n * runs.\n */\nexport interface StampSettings {\n /**\n * The engine stamp libraries open in. `null` uses the viewer's own engine,\n * which is right when that engine is local. A cloud viewer passes a local\n * engine, or a function that makes one:\n *\n * ```ts\n * stampPlugin({\n * assetEngine: () => import('@embedpdf/engine').then((module) => module.createLocalEngine()),\n * })\n * ```\n */\n readonly assetEngine: StampAssetEngine | null;\n /**\n * The fonts typed marks can be written in, each registered on the asset engine the first time\n * a mark names it: a mark is written on the asset engine, so the font goes there, whichever\n * engine the viewer draws with.\n */\n readonly fonts: readonly StampFont[];\n /** The width of a stamp's thumbnail, in device pixels. */\n readonly previewWidth: number;\n /**\n * Fill in a dynamic stamp's form fields when it's armed or placed.\n * Scripting itself is the workspace's one JavaScript switch,\n * `actionsPlugin({ javascript: { enabled } })`: without the actions plugin,\n * or with scripting off, a stamp is placed as it is. `false` keeps every\n * stamp as reviewed, even with scripting on.\n */\n readonly dynamic: boolean;\n}\n\n/** What the stamp settings are when the app registers none. */\nexport const STAMP_DEFAULTS: StampSettings = {\n assetEngine: null,\n fonts: [],\n previewWidth: 256,\n dynamic: true,\n};\n\n/** What `stampPlugin(config)` takes: any of the settings, merged over the defaults. */\nexport type StampConfig = DeepPartial<StampSettings>;\n\n// ── verbs ─────────────────────────────────────────────────────────────────\n\n/**\n * Which document a placing verb acts on. Left out, it is the document in\n * scope (`useStamp()` inside a `<DocumentScope>`, a document plugin's\n * `ctx.get(StampToken)`), else the active document.\n */\nexport interface StampDocumentOptions extends OperationOptions {\n readonly documentId?: string;\n}\n\n/** `armAsset()`'s options. */\nexport interface StampArmOptions extends StampDocumentOptions {\n /** Placed width in PDF points; the stamp's own width by default. */\n readonly targetWidth?: number;\n}\n\nexport interface CreateLibraryOptions extends OperationOptions {\n /** The library's id; a fresh one when left out or taken. */\n readonly id?: string;\n /** What the library is for. Default `'stamps'`. */\n readonly kind?: StampLibraryKind;\n readonly categories?: string[];\n}\n\nexport interface StampLibraryPatch {\n readonly name?: string;\n readonly categories?: string[];\n}\n\nexport interface ImportLibraryOptions extends OperationOptions {\n /**\n * Fallback library name, applied only when the PDF carries no `/Title`\n * (an Acrobat-authored or previously exported library names itself).\n * Default `'Stamps'`.\n */\n name?: string;\n /** Library categories written to catalog `/PieceInfo`. */\n categories?: string[];\n /** Kind stamped onto every imported asset. Default `'stamp'`. */\n kind?: StampAssetKind;\n /** What the file is for; overrides what the file says (an Acrobat-authored set imported for a toolbar). */\n libraryKind?: StampLibraryKind;\n /**\n * Fallback per-page labels for a plain PDF (no `/Names /Pages` registry):\n * every page becomes a stamp named `Stamp<n>` with this label. Ignored\n * when the PDF registers its stamps itself.\n */\n assetName?: (pageIndex: number) => string;\n}\n\nexport interface AddAssetInput {\n /** Target library; omitted, a new single-asset library named after the asset. */\n libraryId?: string;\n /** The identifier (placed `/Name`). Omit to mint an Acrobat-style `#…` one. */\n name?: string;\n /** Picker text and default `/Subj`. Defaults to `name`. */\n label?: string;\n kind?: StampAssetKind;\n subject?: string;\n categories?: string[];\n /**\n * PNG, JPEG, or single-page PDF bytes. Exactly one of `source` / `mark`. A\n * raster becomes a page of the library sized to `size` (default: its\n * pixels as points, 1:1) with the image flattened into it, so every asset\n * is a page and every library a complete PDF.\n */\n source?: BinarySource;\n /** An authored mark: drawn, typed, an image, or a PDF page. Exactly one of `source` / `mark`. */\n mark?: MarkSource;\n /** Thumbnail override for pickers (PNG/JPEG); rendered from the page otherwise. */\n preview?: BinarySource;\n /** Page size in PDF points for a raster source. Ignored for PDF sources (the page has one). */\n size?: { width: number; height: number };\n}\n\n/** What `createAssetFromAnnotations()` takes besides the annotations: where the stamp goes and its name. */\nexport type AssetFromAnnotationsInput = Omit<AddAssetInput, 'source' | 'mark' | 'size'>;\n\nexport interface StampAssetPatch {\n readonly label?: string;\n /** `null` drops the subject override, so placements use the label. */\n readonly subject?: string | null;\n readonly categories?: string[];\n}\n\n/** A cached, browser-paintable render of an asset (PNG from import; raster assets as-is). */\nexport interface StampAssetPreview {\n bytes: Uint8Array;\n mimeType: string;\n}\n\nexport interface StampLibraryFilter {\n readonly kind?: StampLibraryKind | readonly StampLibraryKind[];\n}\nexport interface StampAssetFilter {\n readonly libraryId?: string;\n readonly kind?: StampAssetKind;\n readonly category?: string;\n}\n\n// ── events ────────────────────────────────────────────────────────────────\n\n/** A library's bytes changed, and why: the one to save it on. */\nexport interface StampLibraryChangedEvent {\n readonly libraryId: string;\n readonly reason:\n | 'created'\n | 'imported'\n | 'updated'\n | 'asset-added'\n | 'asset-updated'\n | 'asset-removed'\n | 'removed';\n}\nexport interface StampLibraryCreatedEvent {\n readonly libraryId: string;\n readonly library: StampLibrary;\n}\nexport interface StampLibraryUpdatedEvent {\n readonly libraryId: string;\n readonly library: StampLibrary;\n}\nexport interface StampLibraryDeletedEvent {\n readonly libraryId: string;\n readonly library: null;\n}\nexport interface StampAssetCreatedEvent {\n readonly assetId: string;\n readonly libraryId: string;\n readonly asset: StampAsset;\n}\nexport interface StampAssetUpdatedEvent {\n readonly assetId: string;\n readonly libraryId: string;\n readonly asset: StampAsset;\n}\nexport interface StampAssetDeletedEvent {\n readonly assetId: string;\n readonly libraryId: string;\n readonly asset: null;\n}\n/** A stamp was armed on a document, or disarmed (`asset: null`). */\nexport interface StampArmChangedEvent {\n readonly documentId: string;\n readonly asset: StampAsset | null;\n}\n\n/**\n * Stamp libraries and their assets, shared by every document, and placing\n * them on a document. The placing verbs act on the document in scope, else\n * the active one, or the one their options name (`documentId`). A library is\n * a PDF (one page per asset): `exportLibrary` returns the persistence format,\n * `importLibrary` reads it back. Every verb rejects with a `PluginError`, and\n * every async verb takes a `signal`: cancelled, it rejects\n * `operation-cancelled` and changes nothing. The settings belong to the\n * plugin, not to a document.\n */\nexport interface StampCapability extends SettingsApi<StampSettings> {\n // ── reading ──\n listLibraries(filter?: StampLibraryFilter): readonly StampLibrary[];\n getLibrary(libraryId: string): StampLibrary | null;\n /** Assets in the order a picker shows them: by library, then within it. */\n listAssets(filter?: StampAssetFilter): readonly StampAsset[];\n getAsset(assetId: string): StampAsset | null;\n /** The cached thumbnail (the `previewWidth` setting), or null. */\n getAssetPreview(assetId: string): StampAssetPreview | null;\n /** A preview at any width, rendered by the asset engine and cached per width. Rejects `not-found`. */\n renderAssetPreview(\n assetId: string,\n options: { width: number } & OperationOptions,\n ): Promise<StampAssetPreview | null>;\n /** A copy of the asset's placement bytes (a one-page PDF), or null. */\n readAssetBytes(assetId: string): Uint8Array | null;\n\n // ── libraries ──\n /** Create an empty library. Fires `onLibraryCreated` and `onLibraryChanged`. */\n createLibrary(name: string, options?: CreateLibraryOptions): Promise<{ library: StampLibrary }>;\n /** Rename a library or change its categories. Rejects `not-found`. Fires `onLibraryUpdated`. */\n updateLibrary(\n libraryId: string,\n changes: StampLibraryPatch,\n options?: OperationOptions,\n ): Promise<{ library: StampLibrary }>;\n /** Delete a library with its assets. Fires `onLibraryDeleted`. */\n deleteLibrary(libraryId: string, options?: OperationOptions): Promise<void>;\n /**\n * A PDF becomes a library (one asset per page). Rejects `invalid-input` for\n * bytes that aren't a PDF, `unsupported` without a local asset engine.\n * Fires `onLibraryCreated`, then `onAssetCreated` per stamp.\n */\n importLibrary(\n source: BinarySource,\n options?: ImportLibraryOptions,\n ): Promise<{ library: StampLibrary }>;\n /** The library as the PDF it is. Rejects `not-found`. */\n exportLibrary(libraryId: string, options?: OperationOptions): Promise<Uint8Array>;\n\n // ── assets ──\n /**\n * Add a stamp from bytes or a mark. Rejects `not-found` for an unknown\n * library, `invalid-input` for bytes that aren't a picture or a taken\n * identifier. Fires `onAssetCreated`.\n */\n createAsset(input: AddAssetInput, options?: OperationOptions): Promise<{ asset: StampAsset }>;\n /**\n * Annotations on a page of a document become one stamp, exactly as they\n * look. All or nothing: a hidden annotation, one without an appearance, or\n * one on another page fails the call. Rejects `permission-denied` without\n * `doc.download` (see `canCreateFromAnnotations`), `not-found` for a page\n * that isn't in the document.\n */\n createAssetFromAnnotations(\n page: PageRef | number,\n refs: readonly AnnotationRef[],\n input: AssetFromAnnotationsInput,\n options?: StampDocumentOptions,\n ): Promise<{ asset: StampAsset }>;\n /** Change a stamp's label, subject or categories; its identifier never changes. Rejects `not-found`. */\n updateAsset(\n assetId: string,\n changes: StampAssetPatch,\n options?: OperationOptions,\n ): Promise<{ asset: StampAsset }>;\n /** Remove a stamp from its library. Fires `onAssetDeleted`. */\n deleteAsset(assetId: string, options?: OperationOptions): Promise<void>;\n /** Move a stamp to another library: a copy there, with a new id, then the original goes. */\n moveAsset(\n assetId: string,\n to: { libraryId: string },\n options?: OperationOptions,\n ): Promise<{ asset: StampAsset }>;\n /** Copy a stamp within its library. */\n duplicateAsset(\n assetId: string,\n options?: { label?: string } & OperationOptions,\n ): Promise<{ asset: StampAsset }>;\n\n // ── placing, on one document ──\n /**\n * Arm a stamp: the next click on the document places it, with a preview\n * under the pointer. Rejects `not-found` for an unknown asset,\n * `permission-denied` without `annotations:create` (see `canPlace`).\n * Fires `onArmChanged`.\n */\n armAsset(assetId: string, options?: StampArmOptions): Promise<void>;\n /** Disarm the stamp without placing it. Fires `onArmChanged` when one was armed. */\n disarm(documentId?: string): void;\n /** The stamp the next click on the document places, or null. */\n getArmedAsset(documentId?: string): StampAsset | null;\n /**\n * Place a stamp without the pointer, its middle on `center`, sized by its\n * picture and kept on the page. Resolves `{ annotation }`. Selected only\n * with `select: true`. Rejects `permission-denied` without\n * `annotations:create`, `not-found` for an unknown asset or page.\n */\n placeAsset(\n assetId: string,\n placement: StampPlacement,\n options?: StampDocumentOptions,\n ): Promise<{ annotation: Annotation }>;\n /**\n * Place one stamp at the same spot on several pages (refs or indexes), or\n * on `'all'`. Resolves the placed stamps, and the pages that failed.\n */\n placeAssetOnPages(\n assetId: string,\n pages: readonly (PageRef | number)[] | 'all',\n placement: Omit<StampPlacement, 'page'>,\n options?: StampDocumentOptions,\n ): Promise<BatchResult<Annotation, PageRef>>;\n /** Whether a stamp may be armed or placed on the document (`annotations:create`). */\n canPlace(documentId?: string): boolean;\n /** Whether annotations of the document may become a stamp, which copies them out (`doc.download`). */\n canCreateFromAnnotations(documentId?: string): boolean;\n /** Whether libraries can be imported: false once an import found no local engine to open them in. */\n canImport(): boolean;\n\n // ── events ──\n readonly onLibraryCreated: EventHook<StampLibraryCreatedEvent>;\n readonly onLibraryUpdated: EventHook<StampLibraryUpdatedEvent>;\n readonly onLibraryDeleted: EventHook<StampLibraryDeletedEvent>;\n readonly onAssetCreated: EventHook<StampAssetCreatedEvent>;\n readonly onAssetUpdated: EventHook<StampAssetUpdatedEvent>;\n readonly onAssetDeleted: EventHook<StampAssetDeletedEvent>;\n /** A stamp was armed or disarmed on a document. */\n readonly onArmChanged: EventHook<StampArmChangedEvent>;\n /** A library's bytes changed (subscribe to persist). */\n readonly onLibraryChanged: EventHook<StampLibraryChangedEvent>;\n}\n"],"mappings":";;AAKA,MAAa,cAAA,2BAAA,CAAA,CAAA,sBAAA,CAAoD,SAAS,EACxE,MAAM,uEACR,CAAC;;;ACeD,SAAgB,cAAc,KAAuB;CACnD,MAAM,YAAY,IAAI,QAAQ,GAAG;CACjC,IAAI,YAAY,GAAG,OAAO;EAAE,MAAM;EAAK,OAAO;CAAI;CAClD,OAAO;EAAE,MAAM,IAAI,MAAM,GAAG,SAAS;EAAG,OAAO,IAAI,MAAM,YAAY,CAAC;CAAE;AAC1E;AAEA,SAAgB,SAAS,MAAc,OAAuB;CAC5D,OAAO,GAAG,KAAK,GAAG;AACpB;AAEA,MAAM,SAAS;;;;;;AAOf,SAAgB,gBAAgB,SAAuB,KAAK,QAAgB;CAC1E,IAAI,OAAO;CACX,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK,QAAQ,OAAO,KAAK,MAAM,OAAO,IAAI,EAAa;CAC/E,OAAO;AACT;;AAGA,SAAgB,WAAW,WAAmB,MAAsB;CAClE,OAAO,GAAG,UAAU,GAAG;AACzB;;AAUA,MAAa,8BAA8B;;AAE3C,MAAa,sBAAsB;;AAKnC,MAAa,uBAAuB;;AAGpC,SAAgB,qBAAqB,MAAsB;CACzD,OAAO,SAAS,WAAW,iBAAiB,SAAS,eAAe,qBAAqB;AAC3F;AAEA,SAAgB,uBAAuB,MAAkC;CACvE,IAAI,CAAC,QAAQ,SAAS,gBAAgB,OAAO;CAC7C,OAAO,SAAS,qBAAqB,eAAe;AACtD;AAEA,SAAgB,mBAAmB,MAA8B;CAC/D,OAAO,SAAS,cAAc,cAAc,SAAS,aAAa,aAAa;AACjF;;AAGA,SAAgB,sBACd,IACA,UAA8E,CAAC,GAC/D;CAChB,OAAO;EACL,SAAA;EACA,IAAI;EACJ,MAAM,EAAE,MAAM,qBAAqB,QAAQ,QAAA,QAA4B,EAAE;EAEzE,MAAM;EACN,YAAY,QAAQ,cAAc;EAClC,QAAQ,QAAQ,UAAU;CAC5B;AACF;;AAGA,SAAgB,eACd,MACA,UAAuE,CAAC,GACxD;CAChB,OAAO;EACL,SAAA;EACA,MAAM,EAAE,MAAM,mBAAmB,IAAI,EAAE;EAKvC,MAAM;EACN,SAAS;EACT,iBAAiB,QAAQ,WAAW;EACpC,YAAY,QAAQ,cAAc;CACpC;AACF;;;;ACmDA,MAAa,iBAAgC;CAC3C,aAAa;CACb,OAAO,CAAC;CACR,cAAc;CACd,SAAS;AACX"}
package/dist/contract.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_contract = require("./contract-lDLkRDYV.cjs");
2
+ const require_contract = require("./contract-Dj5KiMyW.cjs");
3
3
  exports.DEFAULT_LIBRARY_KIND = require_contract.DEFAULT_LIBRARY_KIND;
4
4
  exports.STAMP_DEFAULTS = require_contract.STAMP_DEFAULTS;
5
5
  exports.StampToken = require_contract.StampToken;
@@ -1,2 +1,2 @@
1
- import { A as StampSettings, C as StampLibraryCreatedEvent, D as StampLibraryPatch, E as StampLibraryKind, F as DEFAULT_LIBRARY_KIND, I as StampToken, O as StampLibraryUpdatedEvent, S as StampLibraryChangedEvent, T as StampLibraryFilter, _ as StampAssetUpdatedEvent, a as MarkSource, b as StampDocumentOptions, c as StampArmOptions, d as StampAssetDeletedEvent, f as StampAssetEngine, g as StampAssetPreview, h as StampAssetPatch, i as ImportLibraryOptions, j as StampLibraryStore, k as StampPlacement, l as StampAsset, m as StampAssetKind, n as AssetFromAnnotationsInput, o as STAMP_DEFAULTS, p as StampAssetFilter, r as CreateLibraryOptions, s as StampArmChangedEvent, t as AddAssetInput, u as StampAssetCreatedEvent, v as StampCapability, w as StampLibraryDeletedEvent, x as StampLibrary, y as StampConfig } from "./contract-CEeBOug9.cjs";
2
- export { AddAssetInput, AssetFromAnnotationsInput, CreateLibraryOptions, DEFAULT_LIBRARY_KIND, ImportLibraryOptions, MarkSource, STAMP_DEFAULTS, StampArmChangedEvent, StampArmOptions, StampAsset, StampAssetCreatedEvent, StampAssetDeletedEvent, StampAssetEngine, StampAssetFilter, StampAssetKind, StampAssetPatch, StampAssetPreview, StampAssetUpdatedEvent, StampCapability, StampConfig, StampDocumentOptions, StampLibrary, StampLibraryChangedEvent, StampLibraryCreatedEvent, StampLibraryDeletedEvent, StampLibraryFilter, StampLibraryKind, StampLibraryPatch, type StampLibraryStore, StampLibraryUpdatedEvent, type StampPlacement, StampSettings, StampToken };
1
+ import { A as StampPlacement, C as StampLibraryChangedEvent, D as StampLibraryKind, E as StampLibraryFilter, I as DEFAULT_LIBRARY_KIND, L as StampToken, M as StampLibraryStore, O as StampLibraryPatch, S as StampLibrary, T as StampLibraryDeletedEvent, _ as StampAssetUpdatedEvent, a as MarkSource, b as StampDocumentOptions, c as StampArmOptions, d as StampAssetDeletedEvent, f as StampAssetEngine, g as StampAssetPreview, h as StampAssetPatch, i as ImportLibraryOptions, j as StampSettings, k as StampLibraryUpdatedEvent, l as StampAsset, m as StampAssetKind, n as AssetFromAnnotationsInput, o as STAMP_DEFAULTS, p as StampAssetFilter, r as CreateLibraryOptions, s as StampArmChangedEvent, t as AddAssetInput, u as StampAssetCreatedEvent, v as StampCapability, w as StampLibraryCreatedEvent, x as StampFont, y as StampConfig } from "./contract-BQP56Vp4.cjs";
2
+ export { AddAssetInput, AssetFromAnnotationsInput, CreateLibraryOptions, DEFAULT_LIBRARY_KIND, ImportLibraryOptions, MarkSource, STAMP_DEFAULTS, StampArmChangedEvent, StampArmOptions, StampAsset, StampAssetCreatedEvent, StampAssetDeletedEvent, StampAssetEngine, StampAssetFilter, StampAssetKind, StampAssetPatch, StampAssetPreview, StampAssetUpdatedEvent, StampCapability, StampConfig, StampDocumentOptions, StampFont, StampLibrary, StampLibraryChangedEvent, StampLibraryCreatedEvent, StampLibraryDeletedEvent, StampLibraryFilter, StampLibraryKind, StampLibraryPatch, type StampLibraryStore, StampLibraryUpdatedEvent, type StampPlacement, StampSettings, StampToken };
@@ -1,2 +1,2 @@
1
- import { A as StampSettings, C as StampLibraryCreatedEvent, D as StampLibraryPatch, E as StampLibraryKind, F as DEFAULT_LIBRARY_KIND, I as StampToken, O as StampLibraryUpdatedEvent, S as StampLibraryChangedEvent, T as StampLibraryFilter, _ as StampAssetUpdatedEvent, a as MarkSource, b as StampDocumentOptions, c as StampArmOptions, d as StampAssetDeletedEvent, f as StampAssetEngine, g as StampAssetPreview, h as StampAssetPatch, i as ImportLibraryOptions, j as StampLibraryStore, k as StampPlacement, l as StampAsset, m as StampAssetKind, n as AssetFromAnnotationsInput, o as STAMP_DEFAULTS, p as StampAssetFilter, r as CreateLibraryOptions, s as StampArmChangedEvent, t as AddAssetInput, u as StampAssetCreatedEvent, v as StampCapability, w as StampLibraryDeletedEvent, x as StampLibrary, y as StampConfig } from "./contract-CjGXUUDJ.js";
2
- export { AddAssetInput, AssetFromAnnotationsInput, CreateLibraryOptions, DEFAULT_LIBRARY_KIND, ImportLibraryOptions, MarkSource, STAMP_DEFAULTS, StampArmChangedEvent, StampArmOptions, StampAsset, StampAssetCreatedEvent, StampAssetDeletedEvent, StampAssetEngine, StampAssetFilter, StampAssetKind, StampAssetPatch, StampAssetPreview, StampAssetUpdatedEvent, StampCapability, StampConfig, StampDocumentOptions, StampLibrary, StampLibraryChangedEvent, StampLibraryCreatedEvent, StampLibraryDeletedEvent, StampLibraryFilter, StampLibraryKind, StampLibraryPatch, type StampLibraryStore, StampLibraryUpdatedEvent, type StampPlacement, StampSettings, StampToken };
1
+ import { A as StampPlacement, C as StampLibraryChangedEvent, D as StampLibraryKind, E as StampLibraryFilter, I as DEFAULT_LIBRARY_KIND, L as StampToken, M as StampLibraryStore, O as StampLibraryPatch, S as StampLibrary, T as StampLibraryDeletedEvent, _ as StampAssetUpdatedEvent, a as MarkSource, b as StampDocumentOptions, c as StampArmOptions, d as StampAssetDeletedEvent, f as StampAssetEngine, g as StampAssetPreview, h as StampAssetPatch, i as ImportLibraryOptions, j as StampSettings, k as StampLibraryUpdatedEvent, l as StampAsset, m as StampAssetKind, n as AssetFromAnnotationsInput, o as STAMP_DEFAULTS, p as StampAssetFilter, r as CreateLibraryOptions, s as StampArmChangedEvent, t as AddAssetInput, u as StampAssetCreatedEvent, v as StampCapability, w as StampLibraryCreatedEvent, x as StampFont, y as StampConfig } from "./contract-D6Hs6iO3.js";
2
+ export { AddAssetInput, AssetFromAnnotationsInput, CreateLibraryOptions, DEFAULT_LIBRARY_KIND, ImportLibraryOptions, MarkSource, STAMP_DEFAULTS, StampArmChangedEvent, StampArmOptions, StampAsset, StampAssetCreatedEvent, StampAssetDeletedEvent, StampAssetEngine, StampAssetFilter, StampAssetKind, StampAssetPatch, StampAssetPreview, StampAssetUpdatedEvent, StampCapability, StampConfig, StampDocumentOptions, StampFont, StampLibrary, StampLibraryChangedEvent, StampLibraryCreatedEvent, StampLibraryDeletedEvent, StampLibraryFilter, StampLibraryKind, StampLibraryPatch, type StampLibraryStore, StampLibraryUpdatedEvent, type StampPlacement, StampSettings, StampToken };
package/dist/contract.js CHANGED
@@ -1,2 +1,2 @@
1
- import { f as StampToken, n as DEFAULT_LIBRARY_KIND, t as STAMP_DEFAULTS } from "./contract-CJBvneyw.js";
1
+ import { f as StampToken, n as DEFAULT_LIBRARY_KIND, t as STAMP_DEFAULTS } from "./contract-DHcn38S9.js";
2
2
  export { DEFAULT_LIBRARY_KIND, STAMP_DEFAULTS, StampToken };
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_contract = require("./contract-lDLkRDYV.cjs");
2
+ const require_contract = require("./contract-Dj5KiMyW.cjs");
3
3
  let _embedpdf_core = require("@embedpdf/core");
4
4
  let _embedpdf_plugin_actions_contract = require("@embedpdf/plugin-actions/contract");
5
5
  let _embedpdf_plugin_annotation_contract = require("@embedpdf/plugin-annotation/contract");
@@ -126,6 +126,31 @@ function createAssetEngine(ctx) {
126
126
  }
127
127
  return resolved.engine;
128
128
  };
129
+ /** Each asset engine's fonts, by key: each read and registered once (a failed read is tried again). */
130
+ const registered = /* @__PURE__ */ new WeakMap();
131
+ /**
132
+ * Register the font a typed mark names on the asset engine, when it's one of the `fonts`
133
+ * setting's: a standard font, or one the engine has, needs nothing.
134
+ */
135
+ const registerFont = async (key) => {
136
+ const font = settings.get().fonts.find((each) => each.key === key);
137
+ if (!font) return;
138
+ const engine = await assetEngine();
139
+ if (!(0, _embedpdf_engine_core_runtime.isLocalEngine)(engine)) return;
140
+ let byKey = registered.get(engine);
141
+ if (!byKey) registered.set(engine, byKey = /* @__PURE__ */ new Map());
142
+ let registering = byKey.get(key);
143
+ if (!registering) {
144
+ const fonts = byKey;
145
+ registering = font.load().then((data) => engine.fonts.register({
146
+ key,
147
+ data
148
+ })).then(() => void 0);
149
+ fonts.set(key, registering);
150
+ registering.catch(() => fonts.delete(key));
151
+ }
152
+ return registering;
153
+ };
129
154
  /** Library PDFs are sliced and tagged (`/PieceInfo`) on a local engine only. */
130
155
  const openAssetDocument = async (bytes) => {
131
156
  const engine = await assetEngine();
@@ -167,6 +192,7 @@ function createAssetEngine(ctx) {
167
192
  });
168
193
  return {
169
194
  openAssetDocument,
195
+ registerFont,
170
196
  imageToPreview,
171
197
  renderThumbnail,
172
198
  /** Optimistic until an import finds the asset engine is not local (cloud). */
@@ -1037,7 +1063,7 @@ const textBounds = (text, fontSize) => ({
1037
1063
  height: fontSize * 1.6
1038
1064
  });
1039
1065
  function createMarks({ assetEngine }) {
1040
- const { openAssetDocument } = assetEngine;
1066
+ const { openAssetDocument, registerFont } = assetEngine;
1041
1067
  /**
1042
1068
  * A drawn or typed mark rendered to a one-page PDF: the annotation is
1043
1069
  * authored on a scratch page and exported the way "stamp from selection"
@@ -1045,6 +1071,7 @@ function createMarks({ assetEngine }) {
1045
1071
  * font subset-embedded. Self-contained and Acrobat-readable.
1046
1072
  */
1047
1073
  const renderMark = async (mark) => {
1074
+ if (mark.kind === "text") await registerFont(mark.fontFamily);
1048
1075
  const doc = await openAssetDocument(blankLibraryPdf());
1049
1076
  try {
1050
1077
  const scratch = (await doc.pages.list()).pages[0];
@@ -1367,7 +1394,7 @@ const stampPlugin = (config) => (0, _embedpdf_core.definePlugin)({
1367
1394
  settings: {
1368
1395
  defaults: require_contract.STAMP_DEFAULTS,
1369
1396
  registered: config,
1370
- whole: ["assetEngine"]
1397
+ whole: ["assetEngine", "fonts"]
1371
1398
  },
1372
1399
  create: createStampController,
1373
1400
  inScope: (stamp, documentId) => {