@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
70 lines • 1.96 kB
TypeScript
/**
* Reactive share composable
*/
export declare function useShare(): ShareRef;
/**
* Simple share helper
*/
export declare function share(data: ShareData): Promise<ShareResult>;
/**
* Share a URL with optional title and text
*/
export declare function shareURL(url: string, title?: string, text?: string): Promise<ShareResult>;
/**
* Share text content
*/
export declare function shareText(text: string, title?: string): Promise<ShareResult>;
/**
* Share files
*/
export declare function shareFiles(files: File[], title?: string, text?: string): Promise<ShareResult>;
/**
* Create a shareable file from a blob
*/
export declare function createShareableFile(blob: Blob, filename: string, mimeType?: string): File;
/**
* Share current page
*/
export declare function shareCurrentPage(text?: string): Promise<ShareResult>;
/**
* Copy to clipboard as fallback when share is not supported
*/
export declare function shareWithFallback(data: ShareData, fallbackMessage?: string): Promise<ShareResult & { usedFallback?: boolean }>;
/**
* useShare - Web Share API wrapper
*
* Share content using the native share dialog on supported devices.
*
* @example
* ```ts
* const { isSupported, share, canShare } = useShare()
*
* // Share text
* await share({ title: 'Check this out!', text: 'Amazing content', url: 'https://example.com' })
*
* // Share files
* await share({ files: [imageFile] })
*
* // Check if specific content can be shared
* if (canShare({ files: [pdfFile] })) {
* await share({ files: [pdfFile] })
* }
* ```
*/
export declare interface ShareData {
title?: string
text?: string
url?: string
files?: File[]
}
export declare interface ShareResult {
success: boolean
error?: Error
cancelled?: boolean
}
export declare interface ShareRef {
isSupported: () => boolean
isFileShareSupported: () => boolean
canShare: (data?: ShareData) => boolean
share: (data: ShareData) => Promise<ShareResult>
}