# @embedpdf/plugin-stamp — ./internal AddAssetInput [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface AddAssetInput{ libraryId?: string; name?: string; label?: string; kind?: StampAssetKind; subject?: string; categories?: string[]; source?: BinarySource; mark?: MarkSource; preview?: BinarySource; size?:{ width: number; height: number} ; } DEFAULT_LIBRARY_KIND [VariableDeclaration] (from packages/plugin/stamp/src/convention.ts): DEFAULT_LIBRARY_KIND = 'stamps' ImportLibraryOptions [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface ImportLibraryOptions{ name?: string; categories?: string[]; kind?: StampAssetKind; libraryKind?: StampLibraryKind; assetName?: (pageIndex: number) => string; } MarkSource [TypeAliasDeclaration] (from packages/plugin/stamp/src/contract.ts): export type MarkSource = |{ kind: 'ink'; strokes: ReadonlyArray>; color?: string; strokeWidth?: number; } |{ kind: 'text'; text: string; fontFamily: string; color?: string; fontSize?: number} |{ kind: 'image'; source: BinarySource} |{ kind: 'pdf'; source: BinarySource; pageIndex?: number} ; STAMP_LIBRARY_PIECEINFO_APP [VariableDeclaration] (from packages/plugin/stamp/src/convention.ts): STAMP_LIBRARY_PIECEINFO_APP = 'EMBD_StampLibrary' STAMP_PIECEINFO_APP [VariableDeclaration] (from packages/plugin/stamp/src/convention.ts): STAMP_PIECEINFO_APP = 'EMBD_Stamp' STAMP_PIECEINFO_VERSION [VariableDeclaration] (from packages/plugin/stamp/src/convention.ts): STAMP_PIECEINFO_VERSION = 2 StampAction [TypeAliasDeclaration] (from packages/plugin/stamp/src/model.ts): export type StampAction = |{ type: 'LIBRARY_ADDED'; library: StampLibrary} |{ type: 'LIBRARY_UPDATED'; library: StampLibrary} |{ type: 'LIBRARY_REMOVED'; libraryId: string} |{ type: 'ASSET_ADDED'; asset: StampAsset} |{ type: 'ASSET_UPDATED'; asset: StampAsset} |{ type: 'ASSET_REMOVED'; assetId: string} ; StampArmChangedEvent [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampArmChangedEvent{ readonly documentId: string; readonly assetId: string | null; } StampAsset [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampAsset{ id: string; libraryId: string; kind: StampAssetKind; name: string; label: string; size:{ width: number; height: number} ; page: PageRef; subject?: string; categories?: string[]; } StampAssetEvent [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampAssetEvent{ readonly assetId: string; readonly libraryId: string; readonly asset: StampAsset | null; } StampAssetFilter [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampAssetFilter{ readonly libraryId?: string; readonly kind?: StampAssetKind; readonly category?: string; } StampAssetKind [TypeAliasDeclaration] (from packages/plugin/stamp/src/contract.ts): export type StampAssetKind = 'stamp' | 'signature' | 'initials'; StampAssetPreview [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampAssetPreview{ bytes: Uint8Array; mimeType: string; } StampCapability [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampCapability{ listLibraries(filter?: StampLibraryFilter): readonly StampLibrary[]; getLibrary(id: string): StampLibrary | null; listAssets(filter?: StampAssetFilter): readonly StampAsset[]; getAsset(id: string): StampAsset | null; getAssetPreview(id: string): StampAssetPreview | null; renderAssetPreview( id: string, options:{ width: number} & OperationOptions, ): Promise; readAssetBytes(id: string): Uint8Array | null; createLibrary( name: string, options?:{ id?: string; kind?: StampLibraryKind; categories?: string[]} , ): Promise; updateLibrary(id: string, patch:{ name?: string; categories?: string[]} ): Promise; deleteLibrary(id: string): Promise; importLibrary(source: BinarySource, options?: ImportLibraryOptions): Promise; exportLibrary(id: string): Promise; createAsset(input: AddAssetInput): Promise; createAssetFromAnnotations( documentId: string, page: PageRef, refs: readonly AnnotationRef[], input: Omit, ): Promise; updateAsset( id: string, patch:{ label?: string; subject?: string | null; categories?: string[]} , ): Promise; deleteAsset(id: string): Promise; moveAsset(id: string, to:{ libraryId: string} ): Promise; duplicateAsset(id: string, options?:{ label?: string} ): Promise; armAsset(documentId: string, assetId: string, options?:{ targetWidth?: number} ): Promise; disarm(documentId: string): void; getArmedAsset(documentId: string): StampAsset | null; placeAsset( documentId: string, assetId: string, placement: StampPlacement, ): Promise; placeAssetOnPages( documentId: string, assetId: string, pages: readonly PageRef[] | 'all', placement: Omit, options?: OperationOptions, ): Promise>; canPlace(documentId?: string): boolean; canImport(): boolean; readonly onLibraryCreated: EventHook; readonly onLibraryUpdated: EventHook; readonly onLibraryDeleted: EventHook; readonly onAssetCreated: EventHook; readonly onAssetUpdated: EventHook; readonly onAssetDeleted: EventHook; readonly onArmChanged: EventHook; readonly onLibraryChanged: EventHook; } StampConfig [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampConfig{ assetEngine?: Engine | (() => Engine | Promise); previewWidth?: number; dynamic?: boolean; } StampHostCapability [TypeAliasDeclaration] (from packages/plugin/stamp/src/host-contract.ts): export type StampHostCapability = StampCapability; StampKey [InterfaceDeclaration] (from packages/plugin/stamp/src/convention.ts): export interface StampKey{ name: string; label: string; } StampLibrary [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampLibrary{ id: string; name: string; kind: StampLibraryKind; locale?: string; categories?: string[]; assetIds: string[]; } StampLibraryChange [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampLibraryChange{ libraryId: string; reason: | 'created' | 'imported' | 'updated' | 'asset-added' | 'asset-updated' | 'asset-removed' | 'removed'; } StampLibraryEvent [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampLibraryEvent{ readonly libraryId: string; readonly library: StampLibrary | null; } StampLibraryFilter [InterfaceDeclaration] (from packages/plugin/stamp/src/contract.ts): export interface StampLibraryFilter{ readonly kind?: StampLibraryKind | readonly StampLibraryKind[]; } StampLibraryKind [TypeAliasDeclaration] (from packages/plugin/stamp/src/contract.ts): export type StampLibraryKind = string; StampLibraryStore [InterfaceDeclaration] (from packages/plugin/stamp/src/persistence.ts): export interface StampLibraryStore{ list(): Promise>; put(id: string, bytes: Uint8Array): Promise; delete(id: string): Promise; } StampState [InterfaceDeclaration] (from packages/plugin/stamp/src/model.ts): export interface StampState{ libraries: Record; libraryOrder: string[]; assets: Record; } StampToken [VariableDeclaration] (from packages/plugin/stamp/src/token.ts): StampToken = createCapabilityToken('stamp', { hint: `add stampPlugin() from '@embedpdf/plugin-stamp' to your plugins list`, } ) assetIdFor [FunctionDeclaration] (from packages/plugin/stamp/src/convention.ts): export function assetIdFor(libraryId: string, name: string): string{ return `${ libraryId} :${ name} `; } createStampController [FunctionDeclaration] (from packages/plugin/stamp/src/controller.ts): export function createStampController( ctx: StampContext, config: StampConfig ={ } , ): StampHostCapability{ const services = createServices(ctx, config); const{ events} = services; const catalog = createCatalog(ctx, services); const marks = createMarks(services); const libraries = createLibraryWrites(ctx, services); const assets = createAssetWrites(ctx, services, marks, libraries); const placement = createPlacement(ctx, services, config); const api = composeApi('stamp', [ catalog.api, libraries.api, assets.api, placement.api, { onLibraryChanged: events.libraryChanged.on, onLibraryCreated: events.libraryCreated.on, onLibraryUpdated: events.libraryUpdated.on, onLibraryDeleted: events.libraryDeleted.on, onAssetCreated: events.assetCreated.on, onAssetUpdated: events.assetUpdated.on, onAssetDeleted: events.assetDeleted.on, onArmChanged: events.armChanged.on, } , ]) satisfies StampHostCapability; return api; } customStampName [FunctionDeclaration] (from packages/plugin/stamp/src/convention.ts): export function customStampName(random: () => number = Math.random): string{ let out = '#'; for (let i = 0; i < 22; i++) out += BASE62[Math.floor(random() * BASE62.length)]; return out; } initialStampState [VariableDeclaration] (from packages/plugin/stamp/src/model.ts): initialStampState = (): StampState => ({ libraries:{ } , libraryOrder: [], assets:{ } , } ) libraryKindFromPdfName [FunctionDeclaration] (from packages/plugin/stamp/src/convention.ts): export function libraryKindFromPdfName(name: string | undefined): string{ if (!name || name === 'StampLibrary') return DEFAULT_LIBRARY_KIND; return name === 'SignatureLibrary' ? 'signatures' : name; } libraryKindToPdfName [FunctionDeclaration] (from packages/plugin/stamp/src/convention.ts): export function libraryKindToPdfName(kind: string): string{ return kind === 'stamps' ? 'StampLibrary' : kind === 'signatures' ? 'SignatureLibrary' : kind; } parseStampKey [FunctionDeclaration] (from packages/plugin/stamp/src/convention.ts): export function parseStampKey(key: string): StampKey{ const separator = key.indexOf('='); if (separator < 0) return{ name: key, label: key} ; return{ name: key.slice(0, separator), label: key.slice(separator + 1)} ; } stampKey [FunctionDeclaration] (from packages/plugin/stamp/src/convention.ts): export function stampKey(name: string, label: string): string{ return `${ name} =${ label} `; } stampKindToPdfName [FunctionDeclaration] (from packages/plugin/stamp/src/convention.ts): export function stampKindToPdfName(kind: StampAssetKind): string{ return kind === 'signature' ? 'Signature' : kind === 'initials' ? 'Initials' : 'Stamp'; } stampLibraryPieceInfo [FunctionDeclaration] (from packages/plugin/stamp/src/convention.ts): export function stampLibraryPieceInfo( id: string, opts:{ kind?: string; categories?: readonly string[]; locale?: string} ={ } , ): PieceInfoPatch{ return{ Version: STAMP_PIECEINFO_VERSION, Id: id, Kind:{ name: libraryKindToPdfName(opts.kind ?? DEFAULT_LIBRARY_KIND)} , Name: null, Categories: opts.categories ?? null, Locale: opts.locale ?? null, } ; } stampPieceInfo [FunctionDeclaration] (from packages/plugin/stamp/src/convention.ts): export function stampPieceInfo( kind: StampAssetKind, opts:{ subject?: string | null; categories?: readonly string[]} ={ } , ): PieceInfoPatch{ return{ Version: STAMP_PIECEINFO_VERSION, Kind:{ name: stampKindToPdfName(kind)} , Name: null, Subject: null, SubjectOverride: opts.subject ?? null, Categories: opts.categories ?? null, } ; } stampReducer [VariableDeclaration] (from packages/plugin/stamp/src/model.ts): stampReducer = (state: StampState, action: StampAction): StampState =>{ switch (action.type){ case 'LIBRARY_ADDED': return{ ...state, libraries:{ ...state.libraries, [action.library.id]: action.library} , libraryOrder: [...state.libraryOrder, action.library.id], } ; case 'LIBRARY_UPDATED': return state.libraries[action.library.id] ?{ ...state, libraries:{ ...state.libraries, [action.library.id]: action.library} } : state; case 'LIBRARY_REMOVED':{ const library = state.libraries[action.libraryId]; if (!library) return state; const libraries ={ ...state.libraries} ; delete libraries[action.libraryId]; const assets ={ ...state.assets} ; for (const id of library.assetIds) delete assets[id]; return{ ...state, libraries, libraryOrder: state.libraryOrder.filter((id) => id !== action.libraryId), assets, } ; } case 'ASSET_ADDED':{ const library = state.libraries[action.asset.libraryId]; if (!library) return state; return{ ...state, assets:{ ...state.assets, [action.asset.id]: action.asset} , libraries:{ ...state.libraries, [library.id]:{ ...library, assetIds: [...library.assetIds, action.asset.id]} , } , } ; } case 'ASSET_UPDATED': return state.assets[action.asset.id] ?{ ...state, assets:{ ...state.assets, [action.asset.id]: action.asset} } : state; case 'ASSET_REMOVED':{ const asset = state.assets[action.assetId]; if (!asset) return state; const assets ={ ...state.assets} ; delete assets[action.assetId]; const library = state.libraries[asset.libraryId]; return{ ...state, assets, libraries: library ?{ ...state.libraries, [library.id]:{ ...library, assetIds: library.assetIds.filter((id) => id !== action.assetId), } , } : state.libraries, } ; } default: return state; } }