UNPKG

@mirawision/copily

Version:

A comprehensive clipboard manipulation library for TypeScript, providing functionalities for copying/pasting text, HTML, JSON, images, files, and smart content detection.

114 lines (113 loc) 2.61 kB
/** * Smart clipboard result types for intelligent content detection. */ type ClipboardSmartResult = { type: 'otp'; value: string; } | { type: 'url'; value: string; } | { type: 'email'; value: string; } | { type: 'json'; value: any; } | { type: 'html'; value: string; } | { type: 'text'; value: string; } | { type: 'image'; blob: Blob; } | { type: 'file'; file: File; }; /** * Copy interception handler type. * * Returned values allow preventing default copy behavior and/or overriding * the clipboard content. */ type CopyInterceptHandler = (params: { event: ClipboardEvent; selection: string; target: HTMLElement | null; }) => { prevent?: boolean; overrideText?: string; overrideHTML?: string; }; /** * Paste interception handler type. * * Returned values allow preventing default paste behavior and/or overriding * the inserted content as text or HTML. */ type PasteInterceptHandler = (params: { event: ClipboardEvent; plainText: string; html?: string; target: HTMLElement | null; }) => { prevent?: boolean; overrideText?: string; overrideHTML?: string; }; /** * Clipboard format support check result. */ interface ClipboardFormatSupport { read: boolean; write: boolean; } /** * Legacy options for a removed feature (copyWithFeedback). * Retained for backward-compatibility of type imports. */ interface CopyFeedbackOptions { showToast?: boolean; toastDuration?: number; toastMessage?: string; playSound?: boolean; soundUrl?: string; } /** * Formatted text style options. */ interface FormattedTextStyle { bold?: boolean; italic?: boolean; color?: string; fontSize?: string; fontFamily?: string; } /** * Base clipboard error class with a stable `code` field. */ declare class ClipboardError extends Error { code: string; constructor(message: string, code: string); } /** * Clipboard permission error. */ declare class ClipboardPermissionError extends ClipboardError { constructor(message?: string); } /** * Clipboard unsupported error. */ declare class ClipboardUnsupportedError extends ClipboardError { constructor(message?: string); } /** * Clipboard format error. */ declare class ClipboardFormatError extends ClipboardError { constructor(message?: string); } export { ClipboardSmartResult, CopyInterceptHandler, PasteInterceptHandler, ClipboardFormatSupport, CopyFeedbackOptions, FormattedTextStyle, ClipboardError, ClipboardPermissionError, ClipboardUnsupportedError, ClipboardFormatError };