react-smart-copy 1.27.0 → 1.27.1
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.
- package/dist/chunks/{clipboard-adapter-0haPt4jJ.js → clipboard-adapter-B-9XTqUp.js} +2 -3
- package/dist/chunks/clipboard-adapter-B-9XTqUp.js.map +1 -0
- package/dist/chunks/{clipboard-adapter-5bmjKbyK.cjs → clipboard-adapter-q_pp9q_x.cjs} +2 -3
- package/dist/chunks/clipboard-adapter-q_pp9q_x.cjs.map +1 -0
- package/dist/chunks/{core-BRMlZOtj.cjs → core-Bi4HUuRs.cjs} +2 -2
- package/dist/chunks/{core-BRMlZOtj.cjs.map → core-Bi4HUuRs.cjs.map} +1 -1
- package/dist/chunks/{core-CnAFS4Wh.js → core-BrmkVinL.js} +2 -2
- package/dist/chunks/{core-CnAFS4Wh.js.map → core-BrmkVinL.js.map} +1 -1
- package/dist/chunks/{inert-html-D75NyVvT.js → inert-html-BxuTrb6R.js} +11 -2
- package/dist/chunks/{inert-html-D75NyVvT.js.map → inert-html-BxuTrb6R.js.map} +1 -1
- package/dist/chunks/{inert-html-DyxjWDok.cjs → inert-html-aAsKvgJC.cjs} +16 -1
- package/dist/chunks/{inert-html-DyxjWDok.cjs.map → inert-html-aAsKvgJC.cjs.map} +1 -1
- package/dist/chunks/{share-CL72PUqq.js → share-CW1SnFz5.js} +2 -2
- package/dist/chunks/{share-CL72PUqq.js.map → share-CW1SnFz5.js.map} +1 -1
- package/dist/chunks/{share-Bu5u2ItX.cjs → share-K1GpVQdH.cjs} +2 -2
- package/dist/chunks/{share-Bu5u2ItX.cjs.map → share-K1GpVQdH.cjs.map} +1 -1
- package/dist/code.cjs +1 -1
- package/dist/code.js +1 -1
- package/dist/core.cjs +2 -2
- package/dist/core.js +2 -2
- package/dist/index.cjs +3 -3
- package/dist/index.js +3 -3
- package/dist/link.cjs +1 -1
- package/dist/link.js +1 -1
- package/dist/markdown.cjs +1 -1
- package/dist/markdown.js +1 -1
- package/dist/rich.cjs +1 -1
- package/dist/rich.js +1 -1
- package/dist/share.cjs +1 -1
- package/dist/share.js +1 -1
- package/dist/table.cjs +9 -2
- package/dist/table.cjs.map +1 -1
- package/dist/table.js +9 -2
- package/dist/table.js.map +1 -1
- package/package.json +3 -2
- package/dist/chunks/clipboard-adapter-0haPt4jJ.js.map +0 -1
- package/dist/chunks/clipboard-adapter-5bmjKbyK.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"share-CL72PUqq.js","names":[],"sources":["../../src/share/share.ts"],"sourcesContent":["import { createBrowserClipboardAdapter, type ClipboardAdapter } from '../core/clipboard-adapter';\nimport { createCopyError, describeCopyError, toCopyError, type CopyError, type CopyErrorType } from '../core/errors';\nimport { normalizePayload, validatePayload, type CopyInput, type CopyPayload } from '../core/payload';\nimport { cleanTitle, DEFAULT_LINK_TITLE_LENGTH, linkPayload } from '../link/payload';\nimport { linkUrlResolver, type LinkUrlOptions } from '../link/url';\n\n/** What to share: a link, a message, files, or any mix of them. */\nexport interface ShareContent {\n /** Validated like every link in this package: allowed schemes only, credentials removed. */\n readonly url?: string | URL;\n readonly title?: string;\n /** A message to share alongside (or instead of) the link. */\n readonly text?: string;\n /** Files for the share sheet, where the browser can share them (`navigator.canShare({ files })`). Never copied. */\n readonly files?: readonly File[];\n}\n\n/** The content after validation: what the share sheet or the clipboard receives. */\nexport interface ResolvedShare {\n readonly url: string | null;\n /** Cleaned of hidden characters; `null` when there is none. */\n readonly title: string | null;\n readonly text: string | null;\n readonly files: readonly File[];\n}\n\n/**\n * How to share:\n * - `auto` (default): the share sheet on phones and tablets, where people expect it; copy elsewhere.\n * - `native`: the share sheet wherever the browser has one (also desktop Safari, Edge and Chrome on Windows and macOS).\n * - `copy`: always copy.\n */\nexport type ShareMode = 'auto' | 'native' | 'copy';\n\nexport type ShareMethod = 'native' | 'copy';\n\n/** Structural view of what sharing needs from the browser; `window` by default. */\nexport interface ShareEnvironment {\n readonly navigator?: {\n readonly share?: (data: ShareData) => Promise<void>;\n readonly canShare?: (data: ShareData) => boolean;\n };\n readonly matchMedia?: (query: string) => { readonly matches: boolean };\n}\n\nexport interface ShareOptions extends LinkUrlOptions {\n /** Default `\"auto\"`. */\n readonly mode?: ShareMode;\n /** When the share sheet fails for a reason other than the user closing it, copy instead. Default `true`. */\n readonly fallback?: boolean;\n /**\n * What to copy. Default: a titled link (`linkPayload`) when there is a URL,\n * otherwise the text. Return a string or any copy payload.\n */\n readonly copy?: (content: ResolvedShare) => CopyInput;\n /** Default: the browser Clipboard API, as `useCopy` uses. */\n readonly adapter?: ClipboardAdapter;\n /** Default: `window`. For tests, webviews and other hosts. */\n readonly environment?: ShareEnvironment;\n /** Aborting it stops a copy in progress; the share sheet itself can only be closed by the user. */\n readonly signal?: AbortSignal;\n}\n\n/**\n * Why the content was copied rather than shared: `preferred` (the mode chose\n * copy, as on desktop in `auto`), `unsupported` (no share sheet, or it can't\n * take this content) or `fallback` (the share sheet failed).\n */\nexport type CopyReason = 'preferred' | 'unsupported' | 'fallback';\n\n/** What `shareOrCopy` resolves to. It never rejects. */\nexport type ShareOutcome =\n | { readonly status: 'shared'; readonly method: 'native'; readonly content: ResolvedShare }\n | { readonly status: 'copied'; readonly method: 'copy'; readonly reason: CopyReason; readonly payload: CopyPayload; readonly content: ResolvedShare }\n /** The user closed the share sheet. Nothing to report. */\n | { readonly status: 'cancelled'; readonly method: 'native' }\n | { readonly status: 'error'; readonly method: ShareMethod; readonly error: CopyError };\n\n/** Phones and tablets: a touch screen is the main input and nothing hovers. */\nexport const TOUCH_FIRST = '(hover: none) and (pointer: coarse)';\n\nconst defaultEnvironment = (): ShareEnvironment | undefined => (typeof window === 'undefined' ? undefined : window);\n\nconst invalid = (message: string): CopyError => createCopyError('invalid-payload', message);\n\n/** Validates and cleans what to share, or returns the typed error for invalid input. */\nfunction resolveContent(content: ShareContent, options: LinkUrlOptions): ResolvedShare | CopyError {\n const value: unknown = content;\n if (typeof value !== 'object' || value === null) return invalid('Share content must be an object with a url, text or files.');\n const { url, title, text, files } = value as Record<string, unknown>;\n let href: string | null = null;\n if (url !== undefined && url !== null) {\n try {\n href = linkUrlResolver(options)(url as string | URL);\n } catch (error) {\n return toCopyError(error);\n }\n }\n if (title !== undefined && typeof title !== 'string') return invalid('`title` must be a string.');\n if (text !== undefined && typeof text !== 'string') return invalid('`text` must be a string.');\n const list: unknown = files ?? [];\n if (!Array.isArray(list) || !list.every((file: unknown) => typeof File !== 'undefined' && file instanceof File)) {\n return invalid('`files` must be a list of File objects.');\n }\n const cleanName = title === undefined ? '' : cleanTitle(title, DEFAULT_LINK_TITLE_LENGTH);\n const message = text === undefined || text.trim() === '' ? null : text;\n if (href === null && message === null && list.length === 0) return invalid('There is nothing to share: give a url, text or files.');\n return { url: href, title: cleanName === '' ? null : cleanName, text: message, files: list as File[] };\n}\n\n/** The `ShareData` the browser receives: only the fields that are set. */\nfunction shareData(content: ResolvedShare): ShareData {\n return {\n ...(content.url === null ? {} : { url: content.url }),\n ...(content.title === null ? {} : { title: content.title }),\n ...(content.text === null ? {} : { text: content.text }),\n ...(content.files.length === 0 ? {} : { files: [...content.files] }),\n };\n}\n\n/** Whether this browser can open its share sheet for `data`. */\nfunction canShareNatively(environment: ShareEnvironment | undefined, data: ShareData | null): boolean {\n const nav = environment?.navigator;\n if (typeof nav?.share !== 'function') return false;\n if (data === null) return true;\n // Without canShare (older Safari), only links and text can be shared.\n return typeof nav.canShare === 'function' ? nav.canShare(data) : data.files === undefined;\n}\n\nfunction isTouchFirst(environment: ShareEnvironment | undefined): boolean {\n return typeof environment?.matchMedia === 'function' && environment.matchMedia(TOUCH_FIRST).matches;\n}\n\nfunction resolveMode(mode: unknown): ShareMode | CopyError {\n if (mode === undefined) return 'auto';\n return mode === 'auto' || mode === 'native' || mode === 'copy' ? mode : invalid('`mode` must be \"auto\", \"native\" or \"copy\".');\n}\n\n/**\n * How {@link shareOrCopy} would share right now: `\"native\"` (the share sheet) or\n * `\"copy\"`. Use it to label the button (\"Share…\" or \"Copy link\"). Pass the\n * content when it has files, since not every share sheet takes them.\n */\nexport function shareMethod(options: Pick<ShareOptions, 'mode' | 'environment'> = {}, content?: ShareContent): ShareMethod {\n const mode = resolveMode(options.mode);\n if (typeof mode !== 'string' || mode === 'copy') return 'copy';\n const environment = options.environment ?? defaultEnvironment();\n if (mode === 'auto' && !isTouchFirst(environment)) return 'copy';\n const resolved = content === undefined ? null : resolveContent(content, {});\n const data = resolved === null ? null : 'type' in resolved ? undefined : shareData(resolved);\n return data !== undefined && canShareNatively(environment, data) ? 'native' : 'copy';\n}\n\n/** The default copy: a titled link when there is a URL, otherwise the text (one of them is always set here). */\nfunction defaultCopy(content: ResolvedShare): CopyInput {\n if (content.url !== null) return linkPayload({ url: content.url, ...(content.title === null ? {} : { title: content.title }) });\n return content.text as string;\n}\n\nasync function copyContent(content: ResolvedShare, reason: CopyReason, options: ShareOptions): Promise<ShareOutcome> {\n if (options.copy === undefined && content.url === null && content.text === null) {\n return { status: 'error', method: 'copy', error: createCopyError('unsupported-format', 'Files can only be shared through a share sheet, and this browser has none for them.') };\n }\n let payload: CopyPayload;\n try {\n payload = normalizePayload((options.copy ?? defaultCopy)(content));\n } catch (error) {\n return { status: 'error', method: 'copy', error: toCopyError(error) };\n }\n const problem = validatePayload(payload);\n if (problem !== null) return { status: 'error', method: 'copy', error: problem };\n if (options.signal?.aborted === true) return { status: 'error', method: 'copy', error: createCopyError('aborted', 'The share was aborted.') };\n try {\n await (options.adapter ?? createBrowserClipboardAdapter()).write(payload, options.signal === undefined ? undefined : { signal: options.signal });\n } catch (error) {\n return { status: 'error', method: 'copy', error: toCopyError(error) };\n }\n return { status: 'copied', method: 'copy', reason, payload, content };\n}\n\n/**\n * Shares through the device's share sheet where people expect one, and copies a\n * titled link everywhere else. Call it directly in a click handler: the share\n * sheet needs the user's gesture.\n *\n * It never rejects. It resolves to `shared`, `copied` (with why), `cancelled`\n * (the user closed the share sheet: nothing to report) or `error` with a typed\n * {@link CopyError}.\n *\n * @example\n * button.addEventListener('click', async () => {\n * const outcome = await shareOrCopy({ url: location.href, title: document.title });\n * if (outcome.status === 'copied') toast('Link copied');\n * });\n */\nexport async function shareOrCopy(content: ShareContent, options: ShareOptions = {}): Promise<ShareOutcome> {\n const mode = resolveMode(options.mode);\n if (typeof mode !== 'string') return { status: 'error', method: 'copy', error: mode };\n const resolved = resolveContent(content, options);\n if ('type' in resolved) return { status: 'error', method: 'copy', error: resolved };\n const environment = options.environment ?? defaultEnvironment();\n if (mode === 'copy' || (mode === 'auto' && !isTouchFirst(environment))) return copyContent(resolved, 'preferred', options);\n const data = shareData(resolved);\n if (!canShareNatively(environment, data)) return copyContent(resolved, 'unsupported', options);\n try {\n // Called before any await: the share sheet needs the click's user activation.\n await (environment?.navigator?.share as (data: ShareData) => Promise<void>)(data);\n return { status: 'shared', method: 'native', content: resolved };\n } catch (error) {\n if (readName(error) === 'AbortError') return { status: 'cancelled', method: 'native' };\n if (options.fallback === false) return { status: 'error', method: 'native', error: shareError(error) };\n return copyContent(resolved, 'fallback', options);\n }\n}\n\nfunction readName(error: unknown): string | undefined {\n const name: unknown = typeof error === 'object' && error !== null ? (error as { name?: unknown }).name : undefined;\n return typeof name === 'string' ? name : undefined;\n}\n\n/** Classifies a share sheet failure. */\nfunction shareError(cause: unknown): CopyError {\n switch (readName(cause)) {\n case 'NotAllowedError':\n return createCopyError('permission-denied', 'The share sheet was blocked: it needs a click, and an iframe needs the web-share permission.', cause);\n case 'InvalidStateError':\n return createCopyError('unknown', 'Another share sheet is already open.', cause);\n case 'DataError':\n case 'TypeError':\n return createCopyError('unsupported-format', 'The share sheet rejected this content.', cause);\n default:\n return toCopyError(cause);\n }\n}\n\nconst SHARE_DESCRIPTIONS: Partial<Readonly<Record<CopyErrorType, string>>> = {\n 'permission-denied': \"Sharing isn't allowed here.\",\n 'unsupported-format': \"This can't be shared from this browser.\",\n timeout: 'Sharing took too long. Try again.',\n};\n\n/**\n * Default English, user-facing sentence for a failed share: a share sheet\n * failure is described as sharing, a failed copy as copying. Replace for i18n.\n */\nexport function describeShareError(error: CopyError, method: ShareMethod): string {\n if (method === 'copy') return describeCopyError(error);\n return SHARE_DESCRIPTIONS[error.type] ?? \"Couldn't share. Try again.\";\n}\n"],"mappings":";;;;;;;;AA+EA,MAAa,cAAc;AAE3B,MAAM,2BAA0D,OAAO,WAAW,cAAc,KAAA,IAAY;AAE5G,MAAM,WAAW,YAA+B,gBAAgB,mBAAmB,OAAO;;AAG1F,SAAS,eAAe,SAAuB,SAAoD;CACjG,MAAM,QAAiB;CACvB,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,QAAQ,4DAA4D;CAC5H,MAAM,EAAE,KAAK,OAAO,MAAM,UAAU;CACpC,IAAI,OAAsB;CAC1B,IAAI,QAAQ,KAAA,KAAa,QAAQ,MAC/B,IAAI;EACF,OAAO,gBAAgB,OAAO,CAAC,CAAC,GAAmB;CACrD,SAAS,OAAO;EACd,OAAO,YAAY,KAAK;CAC1B;CAEF,IAAI,UAAU,KAAA,KAAa,OAAO,UAAU,UAAU,OAAO,QAAQ,2BAA2B;CAChG,IAAI,SAAS,KAAA,KAAa,OAAO,SAAS,UAAU,OAAO,QAAQ,0BAA0B;CAC7F,MAAM,OAAgB,SAAS,CAAC;CAChC,IAAI,CAAC,MAAM,QAAQ,IAAI,KAAK,CAAC,KAAK,OAAO,SAAkB,OAAO,SAAS,eAAe,gBAAgB,IAAI,GAC5G,OAAO,QAAQ,yCAAyC;CAE1D,MAAM,YAAY,UAAU,KAAA,IAAY,KAAK,WAAW,OAAA,GAAgC;CACxF,MAAM,UAAU,SAAS,KAAA,KAAa,KAAK,KAAK,MAAM,KAAK,OAAO;CAClE,IAAI,SAAS,QAAQ,YAAY,QAAQ,KAAK,WAAW,GAAG,OAAO,QAAQ,uDAAuD;CAClI,OAAO;EAAE,KAAK;EAAM,OAAO,cAAc,KAAK,OAAO;EAAW,MAAM;EAAS,O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AAqB;CACrB,sBAAsB;CACtB,SAAS;AACX;;;;;AAMA,SAAgB,mBAAmB,OAAkB,QAA6B;CAChF,IAAI,WAAW,QAAQ,OAAO,kBAAkB,KAAK;CACrD,OAAO,mBAAmB,MAAM,SAAS;AAC3C"}
|
|
1
|
+
{"version":3,"file":"share-CW1SnFz5.js","names":[],"sources":["../../src/share/share.ts"],"sourcesContent":["import { createBrowserClipboardAdapter, type ClipboardAdapter } from '../core/clipboard-adapter';\nimport { createCopyError, describeCopyError, toCopyError, type CopyError, type CopyErrorType } from '../core/errors';\nimport { normalizePayload, validatePayload, type CopyInput, type CopyPayload } from '../core/payload';\nimport { cleanTitle, DEFAULT_LINK_TITLE_LENGTH, linkPayload } from '../link/payload';\nimport { linkUrlResolver, type LinkUrlOptions } from '../link/url';\n\n/** What to share: a link, a message, files, or any mix of them. */\nexport interface ShareContent {\n /** Validated like every link in this package: allowed schemes only, credentials removed. */\n readonly url?: string | URL;\n readonly title?: string;\n /** A message to share alongside (or instead of) the link. */\n readonly text?: string;\n /** Files for the share sheet, where the browser can share them (`navigator.canShare({ files })`). Never copied. */\n readonly files?: readonly File[];\n}\n\n/** The content after validation: what the share sheet or the clipboard receives. */\nexport interface ResolvedShare {\n readonly url: string | null;\n /** Cleaned of hidden characters; `null` when there is none. */\n readonly title: string | null;\n readonly text: string | null;\n readonly files: readonly File[];\n}\n\n/**\n * How to share:\n * - `auto` (default): the share sheet on phones and tablets, where people expect it; copy elsewhere.\n * - `native`: the share sheet wherever the browser has one (also desktop Safari, Edge and Chrome on Windows and macOS).\n * - `copy`: always copy.\n */\nexport type ShareMode = 'auto' | 'native' | 'copy';\n\nexport type ShareMethod = 'native' | 'copy';\n\n/** Structural view of what sharing needs from the browser; `window` by default. */\nexport interface ShareEnvironment {\n readonly navigator?: {\n readonly share?: (data: ShareData) => Promise<void>;\n readonly canShare?: (data: ShareData) => boolean;\n };\n readonly matchMedia?: (query: string) => { readonly matches: boolean };\n}\n\nexport interface ShareOptions extends LinkUrlOptions {\n /** Default `\"auto\"`. */\n readonly mode?: ShareMode;\n /** When the share sheet fails for a reason other than the user closing it, copy instead. Default `true`. */\n readonly fallback?: boolean;\n /**\n * What to copy. Default: a titled link (`linkPayload`) when there is a URL,\n * otherwise the text. Return a string or any copy payload.\n */\n readonly copy?: (content: ResolvedShare) => CopyInput;\n /** Default: the browser Clipboard API, as `useCopy` uses. */\n readonly adapter?: ClipboardAdapter;\n /** Default: `window`. For tests, webviews and other hosts. */\n readonly environment?: ShareEnvironment;\n /** Aborting it stops a copy in progress; the share sheet itself can only be closed by the user. */\n readonly signal?: AbortSignal;\n}\n\n/**\n * Why the content was copied rather than shared: `preferred` (the mode chose\n * copy, as on desktop in `auto`), `unsupported` (no share sheet, or it can't\n * take this content) or `fallback` (the share sheet failed).\n */\nexport type CopyReason = 'preferred' | 'unsupported' | 'fallback';\n\n/** What `shareOrCopy` resolves to. It never rejects. */\nexport type ShareOutcome =\n | { readonly status: 'shared'; readonly method: 'native'; readonly content: ResolvedShare }\n | { readonly status: 'copied'; readonly method: 'copy'; readonly reason: CopyReason; readonly payload: CopyPayload; readonly content: ResolvedShare }\n /** The user closed the share sheet. Nothing to report. */\n | { readonly status: 'cancelled'; readonly method: 'native' }\n | { readonly status: 'error'; readonly method: ShareMethod; readonly error: CopyError };\n\n/** Phones and tablets: a touch screen is the main input and nothing hovers. */\nexport const TOUCH_FIRST = '(hover: none) and (pointer: coarse)';\n\nconst defaultEnvironment = (): ShareEnvironment | undefined => (typeof window === 'undefined' ? undefined : window);\n\nconst invalid = (message: string): CopyError => createCopyError('invalid-payload', message);\n\n/** Validates and cleans what to share, or returns the typed error for invalid input. */\nfunction resolveContent(content: ShareContent, options: LinkUrlOptions): ResolvedShare | CopyError {\n const value: unknown = content;\n if (typeof value !== 'object' || value === null) return invalid('Share content must be an object with a url, text or files.');\n const { url, title, text, files } = value as Record<string, unknown>;\n let href: string | null = null;\n if (url !== undefined && url !== null) {\n try {\n href = linkUrlResolver(options)(url as string | URL);\n } catch (error) {\n return toCopyError(error);\n }\n }\n if (title !== undefined && typeof title !== 'string') return invalid('`title` must be a string.');\n if (text !== undefined && typeof text !== 'string') return invalid('`text` must be a string.');\n const list: unknown = files ?? [];\n if (!Array.isArray(list) || !list.every((file: unknown) => typeof File !== 'undefined' && file instanceof File)) {\n return invalid('`files` must be a list of File objects.');\n }\n const cleanName = title === undefined ? '' : cleanTitle(title, DEFAULT_LINK_TITLE_LENGTH);\n const message = text === undefined || text.trim() === '' ? null : text;\n if (href === null && message === null && list.length === 0) return invalid('There is nothing to share: give a url, text or files.');\n return { url: href, title: cleanName === '' ? null : cleanName, text: message, files: list as File[] };\n}\n\n/** The `ShareData` the browser receives: only the fields that are set. */\nfunction shareData(content: ResolvedShare): ShareData {\n return {\n ...(content.url === null ? {} : { url: content.url }),\n ...(content.title === null ? {} : { title: content.title }),\n ...(content.text === null ? {} : { text: content.text }),\n ...(content.files.length === 0 ? {} : { files: [...content.files] }),\n };\n}\n\n/** Whether this browser can open its share sheet for `data`. */\nfunction canShareNatively(environment: ShareEnvironment | undefined, data: ShareData | null): boolean {\n const nav = environment?.navigator;\n if (typeof nav?.share !== 'function') return false;\n if (data === null) return true;\n // Without canShare (older Safari), only links and text can be shared.\n return typeof nav.canShare === 'function' ? nav.canShare(data) : data.files === undefined;\n}\n\nfunction isTouchFirst(environment: ShareEnvironment | undefined): boolean {\n return typeof environment?.matchMedia === 'function' && environment.matchMedia(TOUCH_FIRST).matches;\n}\n\nfunction resolveMode(mode: unknown): ShareMode | CopyError {\n if (mode === undefined) return 'auto';\n return mode === 'auto' || mode === 'native' || mode === 'copy' ? mode : invalid('`mode` must be \"auto\", \"native\" or \"copy\".');\n}\n\n/**\n * How {@link shareOrCopy} would share right now: `\"native\"` (the share sheet) or\n * `\"copy\"`. Use it to label the button (\"Share…\" or \"Copy link\"). Pass the\n * content when it has files, since not every share sheet takes them.\n */\nexport function shareMethod(options: Pick<ShareOptions, 'mode' | 'environment'> = {}, content?: ShareContent): ShareMethod {\n const mode = resolveMode(options.mode);\n if (typeof mode !== 'string' || mode === 'copy') return 'copy';\n const environment = options.environment ?? defaultEnvironment();\n if (mode === 'auto' && !isTouchFirst(environment)) return 'copy';\n const resolved = content === undefined ? null : resolveContent(content, {});\n const data = resolved === null ? null : 'type' in resolved ? undefined : shareData(resolved);\n return data !== undefined && canShareNatively(environment, data) ? 'native' : 'copy';\n}\n\n/** The default copy: a titled link when there is a URL, otherwise the text (one of them is always set here). */\nfunction defaultCopy(content: ResolvedShare): CopyInput {\n if (content.url !== null) return linkPayload({ url: content.url, ...(content.title === null ? {} : { title: content.title }) });\n return content.text as string;\n}\n\nasync function copyContent(content: ResolvedShare, reason: CopyReason, options: ShareOptions): Promise<ShareOutcome> {\n if (options.copy === undefined && content.url === null && content.text === null) {\n return { status: 'error', method: 'copy', error: createCopyError('unsupported-format', 'Files can only be shared through a share sheet, and this browser has none for them.') };\n }\n let payload: CopyPayload;\n try {\n payload = normalizePayload((options.copy ?? defaultCopy)(content));\n } catch (error) {\n return { status: 'error', method: 'copy', error: toCopyError(error) };\n }\n const problem = validatePayload(payload);\n if (problem !== null) return { status: 'error', method: 'copy', error: problem };\n if (options.signal?.aborted === true) return { status: 'error', method: 'copy', error: createCopyError('aborted', 'The share was aborted.') };\n try {\n await (options.adapter ?? createBrowserClipboardAdapter()).write(payload, options.signal === undefined ? undefined : { signal: options.signal });\n } catch (error) {\n return { status: 'error', method: 'copy', error: toCopyError(error) };\n }\n return { status: 'copied', method: 'copy', reason, payload, content };\n}\n\n/**\n * Shares through the device's share sheet where people expect one, and copies a\n * titled link everywhere else. Call it directly in a click handler: the share\n * sheet needs the user's gesture.\n *\n * It never rejects. It resolves to `shared`, `copied` (with why), `cancelled`\n * (the user closed the share sheet: nothing to report) or `error` with a typed\n * {@link CopyError}.\n *\n * @example\n * button.addEventListener('click', async () => {\n * const outcome = await shareOrCopy({ url: location.href, title: document.title });\n * if (outcome.status === 'copied') toast('Link copied');\n * });\n */\nexport async function shareOrCopy(content: ShareContent, options: ShareOptions = {}): Promise<ShareOutcome> {\n const mode = resolveMode(options.mode);\n if (typeof mode !== 'string') return { status: 'error', method: 'copy', error: mode };\n const resolved = resolveContent(content, options);\n if ('type' in resolved) return { status: 'error', method: 'copy', error: resolved };\n const environment = options.environment ?? defaultEnvironment();\n if (mode === 'copy' || (mode === 'auto' && !isTouchFirst(environment))) return copyContent(resolved, 'preferred', options);\n const data = shareData(resolved);\n if (!canShareNatively(environment, data)) return copyContent(resolved, 'unsupported', options);\n try {\n // Called before any await: the share sheet needs the click's user activation.\n await (environment?.navigator?.share as (data: ShareData) => Promise<void>)(data);\n return { status: 'shared', method: 'native', content: resolved };\n } catch (error) {\n if (readName(error) === 'AbortError') return { status: 'cancelled', method: 'native' };\n if (options.fallback === false) return { status: 'error', method: 'native', error: shareError(error) };\n return copyContent(resolved, 'fallback', options);\n }\n}\n\nfunction readName(error: unknown): string | undefined {\n const name: unknown = typeof error === 'object' && error !== null ? (error as { name?: unknown }).name : undefined;\n return typeof name === 'string' ? name : undefined;\n}\n\n/** Classifies a share sheet failure. */\nfunction shareError(cause: unknown): CopyError {\n switch (readName(cause)) {\n case 'NotAllowedError':\n return createCopyError('permission-denied', 'The share sheet was blocked: it needs a click, and an iframe needs the web-share permission.', cause);\n case 'InvalidStateError':\n return createCopyError('unknown', 'Another share sheet is already open.', cause);\n case 'DataError':\n case 'TypeError':\n return createCopyError('unsupported-format', 'The share sheet rejected this content.', cause);\n default:\n return toCopyError(cause);\n }\n}\n\nconst SHARE_DESCRIPTIONS: Partial<Readonly<Record<CopyErrorType, string>>> = {\n 'permission-denied': \"Sharing isn't allowed here.\",\n 'unsupported-format': \"This can't be shared from this browser.\",\n timeout: 'Sharing took too long. Try again.',\n};\n\n/**\n * Default English, user-facing sentence for a failed share: a share sheet\n * failure is described as sharing, a failed copy as copying. Replace for i18n.\n */\nexport function describeShareError(error: CopyError, method: ShareMethod): string {\n if (method === 'copy') return describeCopyError(error);\n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AO,mBAAmB,MAAM,SAAS;AAC3C"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
const require_errors = require("./errors-CF2EQNbc.cjs");
|
|
3
3
|
const require_payload = require("./payload-DjSSLonm.cjs");
|
|
4
|
-
const require_clipboard_adapter = require("./clipboard-adapter-
|
|
4
|
+
const require_clipboard_adapter = require("./clipboard-adapter-q_pp9q_x.cjs");
|
|
5
5
|
const require_url = require("./url-CL4YTCvM.cjs");
|
|
6
6
|
const require_payload$1 = require("./payload-DzHhs6Ey.cjs");
|
|
7
7
|
//#region src/share/share.ts
|
|
@@ -228,4 +228,4 @@ Object.defineProperty(exports, "shareOrCopy", {
|
|
|
228
228
|
}
|
|
229
229
|
});
|
|
230
230
|
|
|
231
|
-
//# sourceMappingURL=share-
|
|
231
|
+
//# sourceMappingURL=share-K1GpVQdH.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"share-Bu5u2ItX.cjs","names":["createCopyError","linkUrlResolver","toCopyError","cleanTitle","linkPayload","normalizePayload","validatePayload","createBrowserClipboardAdapter","describeCopyError"],"sources":["../../src/share/share.ts"],"sourcesContent":["import { createBrowserClipboardAdapter, type ClipboardAdapter } from '../core/clipboard-adapter';\nimport { createCopyError, describeCopyError, toCopyError, type CopyError, type CopyErrorType } from '../core/errors';\nimport { normalizePayload, validatePayload, type CopyInput, type CopyPayload } from '../core/payload';\nimport { cleanTitle, DEFAULT_LINK_TITLE_LENGTH, linkPayload } from '../link/payload';\nimport { linkUrlResolver, type LinkUrlOptions } from '../link/url';\n\n/** What to share: a link, a message, files, or any mix of them. */\nexport interface ShareContent {\n /** Validated like every link in this package: allowed schemes only, credentials removed. */\n readonly url?: string | URL;\n readonly title?: string;\n /** A message to share alongside (or instead of) the link. */\n readonly text?: string;\n /** Files for the share sheet, where the browser can share them (`navigator.canShare({ files })`). Never copied. */\n readonly files?: readonly File[];\n}\n\n/** The content after validation: what the share sheet or the clipboard receives. */\nexport interface ResolvedShare {\n readonly url: string | null;\n /** Cleaned of hidden characters; `null` when there is none. */\n readonly title: string | null;\n readonly text: string | null;\n readonly files: readonly File[];\n}\n\n/**\n * How to share:\n * - `auto` (default): the share sheet on phones and tablets, where people expect it; copy elsewhere.\n * - `native`: the share sheet wherever the browser has one (also desktop Safari, Edge and Chrome on Windows and macOS).\n * - `copy`: always copy.\n */\nexport type ShareMode = 'auto' | 'native' | 'copy';\n\nexport type ShareMethod = 'native' | 'copy';\n\n/** Structural view of what sharing needs from the browser; `window` by default. */\nexport interface ShareEnvironment {\n readonly navigator?: {\n readonly share?: (data: ShareData) => Promise<void>;\n readonly canShare?: (data: ShareData) => boolean;\n };\n readonly matchMedia?: (query: string) => { readonly matches: boolean };\n}\n\nexport interface ShareOptions extends LinkUrlOptions {\n /** Default `\"auto\"`. */\n readonly mode?: ShareMode;\n /** When the share sheet fails for a reason other than the user closing it, copy instead. Default `true`. */\n readonly fallback?: boolean;\n /**\n * What to copy. Default: a titled link (`linkPayload`) when there is a URL,\n * otherwise the text. Return a string or any copy payload.\n */\n readonly copy?: (content: ResolvedShare) => CopyInput;\n /** Default: the browser Clipboard API, as `useCopy` uses. */\n readonly adapter?: ClipboardAdapter;\n /** Default: `window`. For tests, webviews and other hosts. */\n readonly environment?: ShareEnvironment;\n /** Aborting it stops a copy in progress; the share sheet itself can only be closed by the user. */\n readonly signal?: AbortSignal;\n}\n\n/**\n * Why the content was copied rather than shared: `preferred` (the mode chose\n * copy, as on desktop in `auto`), `unsupported` (no share sheet, or it can't\n * take this content) or `fallback` (the share sheet failed).\n */\nexport type CopyReason = 'preferred' | 'unsupported' | 'fallback';\n\n/** What `shareOrCopy` resolves to. It never rejects. */\nexport type ShareOutcome =\n | { readonly status: 'shared'; readonly method: 'native'; readonly content: ResolvedShare }\n | { readonly status: 'copied'; readonly method: 'copy'; readonly reason: CopyReason; readonly payload: CopyPayload; readonly content: ResolvedShare }\n /** The user closed the share sheet. Nothing to report. */\n | { readonly status: 'cancelled'; readonly method: 'native' }\n | { readonly status: 'error'; readonly method: ShareMethod; readonly error: CopyError };\n\n/** Phones and tablets: a touch screen is the main input and nothing hovers. */\nexport const TOUCH_FIRST = '(hover: none) and (pointer: coarse)';\n\nconst defaultEnvironment = (): ShareEnvironment | undefined => (typeof window === 'undefined' ? undefined : window);\n\nconst invalid = (message: string): CopyError => createCopyError('invalid-payload', message);\n\n/** Validates and cleans what to share, or returns the typed error for invalid input. */\nfunction resolveContent(content: ShareContent, options: LinkUrlOptions): ResolvedShare | CopyError {\n const value: unknown = content;\n if (typeof value !== 'object' || value === null) return invalid('Share content must be an object with a url, text or files.');\n const { url, title, text, files } = value as Record<string, unknown>;\n let href: string | null = null;\n if (url !== undefined && url !== null) {\n try {\n href = linkUrlResolver(options)(url as string | URL);\n } catch (error) {\n return toCopyError(error);\n }\n }\n if (title !== undefined && typeof title !== 'string') return invalid('`title` must be a string.');\n if (text !== undefined && typeof text !== 'string') return invalid('`text` must be a string.');\n const list: unknown = files ?? [];\n if (!Array.isArray(list) || !list.every((file: unknown) => typeof File !== 'undefined' && file instanceof File)) {\n return invalid('`files` must be a list of File objects.');\n }\n const cleanName = title === undefined ? '' : cleanTitle(title, DEFAULT_LINK_TITLE_LENGTH);\n const message = text === undefined || text.trim() === '' ? null : text;\n if (href === null && message === null && list.length === 0) return invalid('There is nothing to share: give a url, text or files.');\n return { url: href, title: cleanName === '' ? null : cleanName, text: message, files: list as File[] };\n}\n\n/** The `ShareData` the browser receives: only the fields that are set. */\nfunction shareData(content: ResolvedShare): ShareData {\n return {\n ...(content.url === null ? {} : { url: content.url }),\n ...(content.title === null ? {} : { title: content.title }),\n ...(content.text === null ? {} : { text: content.text }),\n ...(content.files.length === 0 ? {} : { files: [...content.files] }),\n };\n}\n\n/** Whether this browser can open its share sheet for `data`. */\nfunction canShareNatively(environment: ShareEnvironment | undefined, data: ShareData | null): boolean {\n const nav = environment?.navigator;\n if (typeof nav?.share !== 'function') return false;\n if (data === null) return true;\n // Without canShare (older Safari), only links and text can be shared.\n return typeof nav.canShare === 'function' ? nav.canShare(data) : data.files === undefined;\n}\n\nfunction isTouchFirst(environment: ShareEnvironment | undefined): boolean {\n return typeof environment?.matchMedia === 'function' && environment.matchMedia(TOUCH_FIRST).matches;\n}\n\nfunction resolveMode(mode: unknown): ShareMode | CopyError {\n if (mode === undefined) return 'auto';\n return mode === 'auto' || mode === 'native' || mode === 'copy' ? mode : invalid('`mode` must be \"auto\", \"native\" or \"copy\".');\n}\n\n/**\n * How {@link shareOrCopy} would share right now: `\"native\"` (the share sheet) or\n * `\"copy\"`. Use it to label the button (\"Share…\" or \"Copy link\"). Pass the\n * content when it has files, since not every share sheet takes them.\n */\nexport function shareMethod(options: Pick<ShareOptions, 'mode' | 'environment'> = {}, content?: ShareContent): ShareMethod {\n const mode = resolveMode(options.mode);\n if (typeof mode !== 'string' || mode === 'copy') return 'copy';\n const environment = options.environment ?? defaultEnvironment();\n if (mode === 'auto' && !isTouchFirst(environment)) return 'copy';\n const resolved = content === undefined ? null : resolveContent(content, {});\n const data = resolved === null ? null : 'type' in resolved ? undefined : shareData(resolved);\n return data !== undefined && canShareNatively(environment, data) ? 'native' : 'copy';\n}\n\n/** The default copy: a titled link when there is a URL, otherwise the text (one of them is always set here). */\nfunction defaultCopy(content: ResolvedShare): CopyInput {\n if (content.url !== null) return linkPayload({ url: content.url, ...(content.title === null ? {} : { title: content.title }) });\n return content.text as string;\n}\n\nasync function copyContent(content: ResolvedShare, reason: CopyReason, options: ShareOptions): Promise<ShareOutcome> {\n if (options.copy === undefined && content.url === null && content.text === null) {\n return { status: 'error', method: 'copy', error: createCopyError('unsupported-format', 'Files can only be shared through a share sheet, and this browser has none for them.') };\n }\n let payload: CopyPayload;\n try {\n payload = normalizePayload((options.copy ?? defaultCopy)(content));\n } catch (error) {\n return { status: 'error', method: 'copy', error: toCopyError(error) };\n }\n const problem = validatePayload(payload);\n if (problem !== null) return { status: 'error', method: 'copy', error: problem };\n if (options.signal?.aborted === true) return { status: 'error', method: 'copy', error: createCopyError('aborted', 'The share was aborted.') };\n try {\n await (options.adapter ?? createBrowserClipboardAdapter()).write(payload, options.signal === undefined ? undefined : { signal: options.signal });\n } catch (error) {\n return { status: 'error', method: 'copy', error: toCopyError(error) };\n }\n return { status: 'copied', method: 'copy', reason, payload, content };\n}\n\n/**\n * Shares through the device's share sheet where people expect one, and copies a\n * titled link everywhere else. Call it directly in a click handler: the share\n * sheet needs the user's gesture.\n *\n * It never rejects. It resolves to `shared`, `copied` (with why), `cancelled`\n * (the user closed the share sheet: nothing to report) or `error` with a typed\n * {@link CopyError}.\n *\n * @example\n * button.addEventListener('click', async () => {\n * const outcome = await shareOrCopy({ url: location.href, title: document.title });\n * if (outcome.status === 'copied') toast('Link copied');\n * });\n */\nexport async function shareOrCopy(content: ShareContent, options: ShareOptions = {}): Promise<ShareOutcome> {\n const mode = resolveMode(options.mode);\n if (typeof mode !== 'string') return { status: 'error', method: 'copy', error: mode };\n const resolved = resolveContent(content, options);\n if ('type' in resolved) return { status: 'error', method: 'copy', error: resolved };\n const environment = options.environment ?? defaultEnvironment();\n if (mode === 'copy' || (mode === 'auto' && !isTouchFirst(environment))) return copyContent(resolved, 'preferred', options);\n const data = shareData(resolved);\n if (!canShareNatively(environment, data)) return copyContent(resolved, 'unsupported', options);\n try {\n // Called before any await: the share sheet needs the click's user activation.\n await (environment?.navigator?.share as (data: ShareData) => Promise<void>)(data);\n return { status: 'shared', method: 'native', content: resolved };\n } catch (error) {\n if (readName(error) === 'AbortError') return { status: 'cancelled', method: 'native' };\n if (options.fallback === false) return { status: 'error', method: 'native', error: shareError(error) };\n return copyContent(resolved, 'fallback', options);\n }\n}\n\nfunction readName(error: unknown): string | undefined {\n const name: unknown = typeof error === 'object' && error !== null ? (error as { name?: unknown }).name : undefined;\n return typeof name === 'string' ? name : undefined;\n}\n\n/** Classifies a share sheet failure. */\nfunction shareError(cause: unknown): CopyError {\n switch (readName(cause)) {\n case 'NotAllowedError':\n return createCopyError('permission-denied', 'The share sheet was blocked: it needs a click, and an iframe needs the web-share permission.', cause);\n case 'InvalidStateError':\n return createCopyError('unknown', 'Another share sheet is already open.', cause);\n case 'DataError':\n case 'TypeError':\n return createCopyError('unsupported-format', 'The share sheet rejected this content.', cause);\n default:\n return toCopyError(cause);\n }\n}\n\nconst SHARE_DESCRIPTIONS: Partial<Readonly<Record<CopyErrorType, string>>> = {\n 'permission-denied': \"Sharing isn't allowed here.\",\n 'unsupported-format': \"This can't be shared from this browser.\",\n timeout: 'Sharing took too long. Try again.',\n};\n\n/**\n * Default English, user-facing sentence for a failed share: a share sheet\n * failure is described as sharing, a failed copy as copying. Replace for i18n.\n */\nexport function describeShareError(error: CopyError, method: ShareMethod): string {\n if (method === 'copy') return describeCopyError(error);\n return SHARE_DESCRIPTIONS[error.type] ?? \"Couldn't share. Try again.\";\n}\n"],"mappings":";;;;;;;;AA+EA,MAAa,cAAc;AAE3B,MAAM,2BAA0D,OAAO,WAAW,cAAc,KAAA,IAAY;AAE5G,MAAM,WAAW,YAA+BA,eAAAA,gBAAgB,mBAAmB,OAAO;;AAG1F,SAAS,eAAe,SAAuB,SAAoD;CACjG,MAAM,QAAiB;CACvB,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,QAAQ,4DAA4D;CAC5H,MAAM,EAAE,KAAK,OAAO,MAAM,UAAU;CACpC,IAAI,OAAsB;CAC1B,IAAI,QAAQ,KAAA,KAAa,QAAQ,MAC/B,IAAI;EACF,OAAOC,YAAAA,gBAAgB,OAAO,CAAC,CAAC,GAAmB;CACrD,SAAS,OAAO;EACd,OAAOC,eAAAA,YAAY,KAAK;CAC1B;CAEF,IAAI,UAAU,KAAA,KAAa,OAAO,UAAU,UAAU,OAAO,QAAQ,2BAA2B;CAChG,IAAI,SAAS,KAAA,KAAa,OAAO,SAAS,UAAU,OAAO,QAAQ,0BAA0B;CAC7F,MAAM,OAAgB,SAAS,CAAC;CAChC,IAAI,CAAC,MAAM,QAAQ,IA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ClD;AACF;AAEA,SAAS,SAAS,OAAoC;CACpD,MAAM,OAAgB,OAAO,UAAU,YAAY,UAAU,OAAQ,MAA6B,OAAO,KAAA;CACzG,OAAO,OAAO,SAAS,WAAW,OAAO,KAAA;AAC3C;;AAGA,SAAS,WAAW,OAA2B;CAC7C,QAAQ,SAAS,KAAK,GAAtB;EACE,KAAK,mBACH,OAAOF,eAAAA,gBAAgB,qBAAqB,gGAAgG,KAAK;EACnJ,KAAK,qBACH,OAAOA,eAAAA,gBAAgB,WAAW,wCAAwC,KAAK;EACjF,KAAK;EACL,KAAK,aACH,OAAOA,eAAAA,gBAAgB,sBAAsB,0CAA0C,KAAK;EAC9F,SACE,OAAOE,eAAAA,YAAY,KAAK;CAC5B;AACF;AAEA,MAAM,qBAAuE;CAC3E,qBAAqB;CACrB,sBAAsB;CACtB,SAAS;AACX;;;;;AAMA,SAAgB,mBAAmB,OAAkB,QAA6B;CAChF,IAAI,WAAW,QAAQ,OAAOM,eAAAA,kBAAkB,KAAK;CACrD,OAAO,mBAAmB,MAAM,SAAS;AAC3C"}
|
|
1
|
+
{"version":3,"file":"share-K1GpVQdH.cjs","names":["createCopyError","linkUrlResolver","toCopyError","cleanTitle","linkPayload","normalizePayload","validatePayload","createBrowserClipboardAdapter","describeCopyError"],"sources":["../../src/share/share.ts"],"sourcesContent":["import { createBrowserClipboardAdapter, type ClipboardAdapter } from '../core/clipboard-adapter';\nimport { createCopyError, describeCopyError, toCopyError, type CopyError, type CopyErrorType } from '../core/errors';\nimport { normalizePayload, validatePayload, type CopyInput, type CopyPayload } from '../core/payload';\nimport { cleanTitle, DEFAULT_LINK_TITLE_LENGTH, linkPayload } from '../link/payload';\nimport { linkUrlResolver, type LinkUrlOptions } from '../link/url';\n\n/** What to share: a link, a message, files, or any mix of them. */\nexport interface ShareContent {\n /** Validated like every link in this package: allowed schemes only, credentials removed. */\n readonly url?: string | URL;\n readonly title?: string;\n /** A message to share alongside (or instead of) the link. */\n readonly text?: string;\n /** Files for the share sheet, where the browser can share them (`navigator.canShare({ files })`). Never copied. */\n readonly files?: readonly File[];\n}\n\n/** The content after validation: what the share sheet or the clipboard receives. */\nexport interface ResolvedShare {\n readonly url: string | null;\n /** Cleaned of hidden characters; `null` when there is none. */\n readonly title: string | null;\n readonly text: string | null;\n readonly files: readonly File[];\n}\n\n/**\n * How to share:\n * - `auto` (default): the share sheet on phones and tablets, where people expect it; copy elsewhere.\n * - `native`: the share sheet wherever the browser has one (also desktop Safari, Edge and Chrome on Windows and macOS).\n * - `copy`: always copy.\n */\nexport type ShareMode = 'auto' | 'native' | 'copy';\n\nexport type ShareMethod = 'native' | 'copy';\n\n/** Structural view of what sharing needs from the browser; `window` by default. */\nexport interface ShareEnvironment {\n readonly navigator?: {\n readonly share?: (data: ShareData) => Promise<void>;\n readonly canShare?: (data: ShareData) => boolean;\n };\n readonly matchMedia?: (query: string) => { readonly matches: boolean };\n}\n\nexport interface ShareOptions extends LinkUrlOptions {\n /** Default `\"auto\"`. */\n readonly mode?: ShareMode;\n /** When the share sheet fails for a reason other than the user closing it, copy instead. Default `true`. */\n readonly fallback?: boolean;\n /**\n * What to copy. Default: a titled link (`linkPayload`) when there is a URL,\n * otherwise the text. Return a string or any copy payload.\n */\n readonly copy?: (content: ResolvedShare) => CopyInput;\n /** Default: the browser Clipboard API, as `useCopy` uses. */\n readonly adapter?: ClipboardAdapter;\n /** Default: `window`. For tests, webviews and other hosts. */\n readonly environment?: ShareEnvironment;\n /** Aborting it stops a copy in progress; the share sheet itself can only be closed by the user. */\n readonly signal?: AbortSignal;\n}\n\n/**\n * Why the content was copied rather than shared: `preferred` (the mode chose\n * copy, as on desktop in `auto`), `unsupported` (no share sheet, or it can't\n * take this content) or `fallback` (the share sheet failed).\n */\nexport type CopyReason = 'preferred' | 'unsupported' | 'fallback';\n\n/** What `shareOrCopy` resolves to. It never rejects. */\nexport type ShareOutcome =\n | { readonly status: 'shared'; readonly method: 'native'; readonly content: ResolvedShare }\n | { readonly status: 'copied'; readonly method: 'copy'; readonly reason: CopyReason; readonly payload: CopyPayload; readonly content: ResolvedShare }\n /** The user closed the share sheet. Nothing to report. */\n | { readonly status: 'cancelled'; readonly method: 'native' }\n | { readonly status: 'error'; readonly method: ShareMethod; readonly error: CopyError };\n\n/** Phones and tablets: a touch screen is the main input and nothing hovers. */\nexport const TOUCH_FIRST = '(hover: none) and (pointer: coarse)';\n\nconst defaultEnvironment = (): ShareEnvironment | undefined => (typeof window === 'undefined' ? undefined : window);\n\nconst invalid = (message: string): CopyError => createCopyError('invalid-payload', message);\n\n/** Validates and cleans what to share, or returns the typed error for invalid input. */\nfunction resolveContent(content: ShareContent, options: LinkUrlOptions): ResolvedShare | CopyError {\n const value: unknown = content;\n if (typeof value !== 'object' || value === null) return invalid('Share content must be an object with a url, text or files.');\n const { url, title, text, files } = value as Record<string, unknown>;\n let href: string | null = null;\n if (url !== undefined && url !== null) {\n try {\n href = linkUrlResolver(options)(url as string | URL);\n } catch (error) {\n return toCopyError(error);\n }\n }\n if (title !== undefined && typeof title !== 'string') return invalid('`title` must be a string.');\n if (text !== undefined && typeof text !== 'string') return invalid('`text` must be a string.');\n const list: unknown = files ?? [];\n if (!Array.isArray(list) || !list.every((file: unknown) => typeof File !== 'undefined' && file instanceof File)) {\n return invalid('`files` must be a list of File objects.');\n }\n const cleanName = title === undefined ? '' : cleanTitle(title, DEFAULT_LINK_TITLE_LENGTH);\n const message = text === undefined || text.trim() === '' ? null : text;\n if (href === null && message === null && list.length === 0) return invalid('There is nothing to share: give a url, text or files.');\n return { url: href, title: cleanName === '' ? null : cleanName, text: message, files: list as File[] };\n}\n\n/** The `ShareData` the browser receives: only the fields that are set. */\nfunction shareData(content: ResolvedShare): ShareData {\n return {\n ...(content.url === null ? {} : { url: content.url }),\n ...(content.title === null ? {} : { title: content.title }),\n ...(content.text === null ? {} : { text: content.text }),\n ...(content.files.length === 0 ? {} : { files: [...content.files] }),\n };\n}\n\n/** Whether this browser can open its share sheet for `data`. */\nfunction canShareNatively(environment: ShareEnvironment | undefined, data: ShareData | null): boolean {\n const nav = environment?.navigator;\n if (typeof nav?.share !== 'function') return false;\n if (data === null) return true;\n // Without canShare (older Safari), only links and text can be shared.\n return typeof nav.canShare === 'function' ? nav.canShare(data) : data.files === undefined;\n}\n\nfunction isTouchFirst(environment: ShareEnvironment | undefined): boolean {\n return typeof environment?.matchMedia === 'function' && environment.matchMedia(TOUCH_FIRST).matches;\n}\n\nfunction resolveMode(mode: unknown): ShareMode | CopyError {\n if (mode === undefined) return 'auto';\n return mode === 'auto' || mode === 'native' || mode === 'copy' ? mode : invalid('`mode` must be \"auto\", \"native\" or \"copy\".');\n}\n\n/**\n * How {@link shareOrCopy} would share right now: `\"native\"` (the share sheet) or\n * `\"copy\"`. Use it to label the button (\"Share…\" or \"Copy link\"). Pass the\n * content when it has files, since not every share sheet takes them.\n */\nexport function shareMethod(options: Pick<ShareOptions, 'mode' | 'environment'> = {}, content?: ShareContent): ShareMethod {\n const mode = resolveMode(options.mode);\n if (typeof mode !== 'string' || mode === 'copy') return 'copy';\n const environment = options.environment ?? defaultEnvironment();\n if (mode === 'auto' && !isTouchFirst(environment)) return 'copy';\n const resolved = content === undefined ? null : resolveContent(content, {});\n const data = resolved === null ? null : 'type' in resolved ? undefined : shareData(resolved);\n return data !== undefined && canShareNatively(environment, data) ? 'native' : 'copy';\n}\n\n/** The default copy: a titled link when there is a URL, otherwise the text (one of them is always set here). */\nfunction defaultCopy(content: ResolvedShare): CopyInput {\n if (content.url !== null) return linkPayload({ url: content.url, ...(content.title === null ? {} : { title: content.title }) });\n return content.text as string;\n}\n\nasync function copyContent(content: ResolvedShare, reason: CopyReason, options: ShareOptions): Promise<ShareOutcome> {\n if (options.copy === undefined && content.url === null && content.text === null) {\n return { status: 'error', method: 'copy', error: createCopyError('unsupported-format', 'Files can only be shared through a share sheet, and this browser has none for them.') };\n }\n let payload: CopyPayload;\n try {\n payload = normalizePayload((options.copy ?? defaultCopy)(content));\n } catch (error) {\n return { status: 'error', method: 'copy', error: toCopyError(error) };\n }\n const problem = validatePayload(payload);\n if (problem !== null) return { status: 'error', method: 'copy', error: problem };\n if (options.signal?.aborted === true) return { status: 'error', method: 'copy', error: createCopyError('aborted', 'The share was aborted.') };\n try {\n await (options.adapter ?? createBrowserClipboardAdapter()).write(payload, options.signal === undefined ? undefined : { signal: options.signal });\n } catch (error) {\n return { status: 'error', method: 'copy', error: toCopyError(error) };\n }\n return { status: 'copied', method: 'copy', reason, payload, content };\n}\n\n/**\n * Shares through the device's share sheet where people expect one, and copies a\n * titled link everywhere else. Call it directly in a click handler: the share\n * sheet needs the user's gesture.\n *\n * It never rejects. It resolves to `shared`, `copied` (with why), `cancelled`\n * (the user closed the share sheet: nothing to report) or `error` with a typed\n * {@link CopyError}.\n *\n * @example\n * button.addEventListener('click', async () => {\n * const outcome = await shareOrCopy({ url: location.href, title: document.title });\n * if (outcome.status === 'copied') toast('Link copied');\n * });\n */\nexport async function shareOrCopy(content: ShareContent, options: ShareOptions = {}): Promise<ShareOutcome> {\n const mode = resolveMode(options.mode);\n if (typeof mode !== 'string') return { status: 'error', method: 'copy', error: mode };\n const resolved = resolveContent(content, options);\n if ('type' in resolved) return { status: 'error', method: 'copy', error: resolved };\n const environment = options.environment ?? defaultEnvironment();\n if (mode === 'copy' || (mode === 'auto' && !isTouchFirst(environment))) return copyContent(resolved, 'preferred', options);\n const data = shareData(resolved);\n if (!canShareNatively(environment, data)) return copyContent(resolved, 'unsupported', options);\n try {\n // Called before any await: the share sheet needs the click's user activation.\n await (environment?.navigator?.share as (data: ShareData) => Promise<void>)(data);\n return { status: 'shared', method: 'native', content: resolved };\n } catch (error) {\n if (readName(error) === 'AbortError') return { status: 'cancelled', method: 'native' };\n if (options.fallback === false) return { status: 'error', method: 'native', error: shareError(error) };\n return copyContent(resolved, 'fallback', options);\n }\n}\n\nfunction readName(error: unknown): string | undefined {\n const name: unknown = typeof error === 'object' && error !== null ? (error as { name?: unknown }).name : undefined;\n return typeof name === 'string' ? name : undefined;\n}\n\n/** Classifies a share sheet failure. */\nfunction shareError(cause: unknown): CopyError {\n switch (readName(cause)) {\n case 'NotAllowedError':\n return createCopyError('permission-denied', 'The share sheet was blocked: it needs a click, and an iframe needs the web-share permission.', cause);\n case 'InvalidStateError':\n return createCopyError('unknown', 'Another share sheet is already open.', cause);\n case 'DataError':\n case 'TypeError':\n return createCopyError('unsupported-format', 'The share sheet rejected this content.', cause);\n default:\n return toCopyError(cause);\n }\n}\n\nconst SHARE_DESCRIPTIONS: Partial<Readonly<Record<CopyErrorType, string>>> = {\n 'permission-denied': \"Sharing isn't allowed here.\",\n 'unsupported-format': \"This can't be shared from this browser.\",\n timeout: 'Sharing took too long. Try again.',\n};\n\n/**\n * Default English, user-facing sentence for a failed share: a share sheet\n * failure is described as sharing, a failed copy as copying. Replace for i18n.\n */\nexport function describeShareError(error: CopyError, method: ShareMethod): string {\n if (method === 'copy') return describeCopyError(error);\n return SHARE_DESCRIPTIONS[error.type] ?? \"Couldn't share. Try again.\";\n}\n"],"mappings":";;;;;;;;AA+EA,MAAa,cAAc;AAE3B,MAAM,2BAA0D,OAAO,WAAW,cAAc,KAAA,IAAY;AAE5G,MAAM,WAAW,YAA+BA,eAAAA,gBAAgB,mBAAmB,OAAO;;AAG1F,SAAS,eAAe,SAAuB,SAAoD;CACjG,MAAM,QAAiB;CACvB,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO,QAAQ,4DAA4D;CAC5H,MAAM,EAAE,KAAK,OAAO,MAAM,UAAU;CACpC,IAAI,OAAsB;CAC1B,IAAI,QAAQ,KAAA,KAAa,QAAQ,MAC/B,IAAI;EACF,OAAOC,YAAAA,gBAAgB,OAAO,CAAC,CAAC,GAAmB;CACrD,SAAS,OAAO;EACd,OAAOC,eAAAA,YAAY,KAAK;CAC1B;CAEF,IAAI,UAAU,KAAA,KAAa,OAAO,UAAU,UAAU,OAAO,QAAQ,2BAA2B;CAChG,IAAI,SAAS,KAAA,KAAa,OAAO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OAAO;GAAE,QAAQ;GAAS,QAAQ;GAAU,OAAO,WAAW,KAAK;EAAE;EACrG,OAAO,YAAY,UAAU,YAAY,OAAO;CAClD;AACF;AAEA,SAAS,SAAS,OAAoC;CACpD,MAAM,OAAgB,OAAO,UAAU,YAAY,UAAU,OAAQ,MAA6B,OAAO,KAAA;CACzG,OAAO,OAAO,SAAS,WAAW,OAAO,KAAA;AAC3C;;AAGA,SAAS,WAAW,OAA2B;CAC7C,QAAQ,SAAS,KAAK,GAAtB;EACE,KAAK,mBACH,OAAOF,eAAAA,gBAAgB,qBAAqB,gGAAgG,KAAK;EACnJ,KAAK,qBACH,OAAOA,eAAAA,gBAAgB,WAAW,wCAAwC,KAAK;EACjF,KAAK;EACL,KAAK,aACH,OAAOA,eAAAA,gBAAgB,sBAAsB,0CAA0C,KAAK;EAC9F,SACE,OAAOE,eAAAA,YAAY,KAAK;CAC5B;AACF;AAEA,MAAM,qBAAuE;CAC3E,qBAAqB;CACrB,sBAAsB;CACtB,SAAS;AACX;;;;;AAMA,SAAgB,mBAAmB,OAAkB,QAA6B;CAChF,IAAI,WAAW,QAAQ,OAAOM,eAAAA,kBAAkB,KAAK;CACrD,OAAO,mBAAmB,MAAM,SAAS;AAC3C"}
|
package/dist/code.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require_errors = require("./chunks/errors-CF2EQNbc.cjs");
|
|
4
4
|
const require_limits = require("./chunks/limits-Vy-Xv26D.cjs");
|
|
5
|
-
const require_inert_html = require("./chunks/inert-html-
|
|
5
|
+
const require_inert_html = require("./chunks/inert-html-aAsKvgJC.cjs");
|
|
6
6
|
const require_text_field = require("./chunks/text-field-BEzUVOag.cjs");
|
|
7
7
|
//#region src/code/inspect.ts
|
|
8
8
|
/** Every finding kind, in a stable order. */
|
package/dist/code.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { n as copyFailure, o as isCopyFailure } from "./chunks/errors-CGcMvbhJ.js";
|
|
3
3
|
import { t as positiveLimit } from "./chunks/limits-DvJZJn0V.js";
|
|
4
|
-
import {
|
|
4
|
+
import { n as parseInertHtml } from "./chunks/inert-html-BxuTrb6R.js";
|
|
5
5
|
import { n as insertText, t as asTextField } from "./chunks/text-field-D7PF2WlX.js";
|
|
6
6
|
//#region src/code/inspect.ts
|
|
7
7
|
/** Every finding kind, in a stable order. */
|
package/dist/core.cjs
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const require_errors = require("./chunks/errors-CF2EQNbc.cjs");
|
|
4
4
|
const require_payload = require("./chunks/payload-DjSSLonm.cjs");
|
|
5
5
|
const require_mime = require("./chunks/mime--LB7kdqG.cjs");
|
|
6
|
-
const require_clipboard_adapter = require("./chunks/clipboard-adapter-
|
|
7
|
-
const require_core = require("./chunks/core-
|
|
6
|
+
const require_clipboard_adapter = require("./chunks/clipboard-adapter-q_pp9q_x.cjs");
|
|
7
|
+
const require_core = require("./chunks/core-Bi4HUuRs.cjs");
|
|
8
8
|
const require_paste_reader = require("./chunks/paste-reader-BL51Jt1y.cjs");
|
|
9
9
|
exports.CopyFailure = require_errors.CopyFailure;
|
|
10
10
|
exports.DEFAULT_INTERCEPTED_EVENTS = require_core.DEFAULT_INTERCEPTED_EVENTS;
|
package/dist/core.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { a as describePasteError, c as toCopyError, i as describeCopyError, n as copyFailure, o as isCopyFailure, r as createCopyError, s as isRetryableError, t as CopyFailure } from "./chunks/errors-CGcMvbhJ.js";
|
|
3
3
|
import { a as validatePayload, i as serializeJson, n as isBlob, r as normalizePayload, t as IMAGE_MIME_TYPE } from "./chunks/payload-5uJedhwz.js";
|
|
4
4
|
import { a as matchesMimePattern, c as sniffImageBytes, i as isWebCustomFormat, l as sniffImageType, n as WEB_CUSTOM_FORMAT_PREFIX, o as normalizeClipboardType, r as isTextualMimeType, s as normalizeMimeType, t as SVG_MIME_TYPE } from "./chunks/mime-aa-HA2dm.js";
|
|
5
|
-
import { t as createBrowserClipboardAdapter } from "./chunks/clipboard-adapter-
|
|
6
|
-
import { _ as DEFAULT_MAX_RETRIES, a as readClipboardPermission, b as createCopyCoordinator, c as registerDragCopy, d as readCopySelection, f as registerCopyInterceptor, g as createCopyMachine, h as canRetryState, i as createBrowserPasteAdapter, l as DEFAULT_INTERCEPTED_EVENTS, m as IDLE_STATE, n as canRetryPasteState, o as watchClipboardPermission, p as DEFAULT_RESET_AFTER_MS, r as createPasteMachine, s as applyDragCopy, t as PASTE_IDLE_STATE, u as interceptCopyEvent, y as resolveMaxRetries } from "./chunks/core-
|
|
5
|
+
import { t as createBrowserClipboardAdapter } from "./chunks/clipboard-adapter-B-9XTqUp.js";
|
|
6
|
+
import { _ as DEFAULT_MAX_RETRIES, a as readClipboardPermission, b as createCopyCoordinator, c as registerDragCopy, d as readCopySelection, f as registerCopyInterceptor, g as createCopyMachine, h as canRetryState, i as createBrowserPasteAdapter, l as DEFAULT_INTERCEPTED_EVENTS, m as IDLE_STATE, n as canRetryPasteState, o as watchClipboardPermission, p as DEFAULT_RESET_AFTER_MS, r as createPasteMachine, s as applyDragCopy, t as PASTE_IDLE_STATE, u as interceptCopyEvent, y as resolveMaxRetries } from "./chunks/core-BrmkVinL.js";
|
|
7
7
|
import { i as canAcceptDrag, l as resolvePasteReadOptions, n as DEFAULT_PASTE_MAX_BYTES, r as DEFAULT_PASTE_MAX_ITEMS, t as DEFAULT_PASTE_ACCEPT } from "./chunks/paste-reader-BpXOH_Px.js";
|
|
8
8
|
export { CopyFailure, DEFAULT_INTERCEPTED_EVENTS, DEFAULT_MAX_RETRIES, DEFAULT_PASTE_ACCEPT, DEFAULT_PASTE_MAX_BYTES, DEFAULT_PASTE_MAX_ITEMS, DEFAULT_RESET_AFTER_MS, IDLE_STATE, IMAGE_MIME_TYPE, PASTE_IDLE_STATE, SVG_MIME_TYPE, WEB_CUSTOM_FORMAT_PREFIX, applyDragCopy, canAcceptDrag, canRetryPasteState, canRetryState, copyFailure, createBrowserClipboardAdapter, createBrowserPasteAdapter, createCopyCoordinator, createCopyError, createCopyMachine, createPasteMachine, describeCopyError, describePasteError, interceptCopyEvent, isBlob, isCopyFailure, isRetryableError, isTextualMimeType, isWebCustomFormat, matchesMimePattern, normalizeClipboardType, normalizeMimeType, normalizePayload, readClipboardPermission, readCopySelection, registerCopyInterceptor, registerDragCopy, resolveMaxRetries, resolvePasteReadOptions, serializeJson, sniffImageBytes, sniffImageType, toCopyError, validatePayload, watchClipboardPermission };
|
package/dist/index.cjs
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const require_errors = require("./chunks/errors-CF2EQNbc.cjs");
|
|
4
4
|
const require_payload = require("./chunks/payload-DjSSLonm.cjs");
|
|
5
5
|
const require_mime = require("./chunks/mime--LB7kdqG.cjs");
|
|
6
|
-
const require_clipboard_adapter = require("./chunks/clipboard-adapter-
|
|
7
|
-
const require_core = require("./chunks/core-
|
|
6
|
+
const require_clipboard_adapter = require("./chunks/clipboard-adapter-q_pp9q_x.cjs");
|
|
7
|
+
const require_core = require("./chunks/core-Bi4HUuRs.cjs");
|
|
8
8
|
const require_paste_reader = require("./chunks/paste-reader-BL51Jt1y.cjs");
|
|
9
|
-
const require_share = require("./chunks/share-
|
|
9
|
+
const require_share = require("./chunks/share-K1GpVQdH.cjs");
|
|
10
10
|
const require_field = require("./chunks/field-C8A5Yxln.cjs");
|
|
11
11
|
let react = require("react");
|
|
12
12
|
let react_jsx_runtime = require("react/jsx-runtime");
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { a as describePasteError, c as toCopyError, i as describeCopyError, n as copyFailure, o as isCopyFailure, r as createCopyError, s as isRetryableError, t as CopyFailure } from "./chunks/errors-CGcMvbhJ.js";
|
|
3
3
|
import { a as validatePayload, i as serializeJson, n as isBlob, r as normalizePayload, t as IMAGE_MIME_TYPE } from "./chunks/payload-5uJedhwz.js";
|
|
4
4
|
import { a as matchesMimePattern, c as sniffImageBytes, i as isWebCustomFormat, l as sniffImageType, n as WEB_CUSTOM_FORMAT_PREFIX, o as normalizeClipboardType, r as isTextualMimeType, s as normalizeMimeType, t as SVG_MIME_TYPE } from "./chunks/mime-aa-HA2dm.js";
|
|
5
|
-
import { t as createBrowserClipboardAdapter } from "./chunks/clipboard-adapter-
|
|
6
|
-
import { _ as DEFAULT_MAX_RETRIES, a as readClipboardPermission, b as createCopyCoordinator, c as registerDragCopy, d as readCopySelection, f as registerCopyInterceptor, g as createCopyMachine, h as canRetryState, i as createBrowserPasteAdapter, l as DEFAULT_INTERCEPTED_EVENTS, m as IDLE_STATE, n as canRetryPasteState, o as watchClipboardPermission, p as DEFAULT_RESET_AFTER_MS, r as createPasteMachine, s as applyDragCopy, t as PASTE_IDLE_STATE, u as interceptCopyEvent, v as invoke, y as resolveMaxRetries } from "./chunks/core-
|
|
5
|
+
import { t as createBrowserClipboardAdapter } from "./chunks/clipboard-adapter-B-9XTqUp.js";
|
|
6
|
+
import { _ as DEFAULT_MAX_RETRIES, a as readClipboardPermission, b as createCopyCoordinator, c as registerDragCopy, d as readCopySelection, f as registerCopyInterceptor, g as createCopyMachine, h as canRetryState, i as createBrowserPasteAdapter, l as DEFAULT_INTERCEPTED_EVENTS, m as IDLE_STATE, n as canRetryPasteState, o as watchClipboardPermission, p as DEFAULT_RESET_AFTER_MS, r as createPasteMachine, s as applyDragCopy, t as PASTE_IDLE_STATE, u as interceptCopyEvent, v as invoke, y as resolveMaxRetries } from "./chunks/core-BrmkVinL.js";
|
|
7
7
|
import { i as canAcceptDrag, l as resolvePasteReadOptions, n as DEFAULT_PASTE_MAX_BYTES, r as DEFAULT_PASTE_MAX_ITEMS, t as DEFAULT_PASTE_ACCEPT } from "./chunks/paste-reader-BpXOH_Px.js";
|
|
8
|
-
import { i as shareOrCopy, r as shareMethod, t as TOUCH_FIRST } from "./chunks/share-
|
|
8
|
+
import { i as shareOrCopy, r as shareMethod, t as TOUCH_FIRST } from "./chunks/share-CW1SnFz5.js";
|
|
9
9
|
import { t as createOtpField } from "./chunks/field-CDCN9x0L.js";
|
|
10
10
|
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
11
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
package/dist/link.cjs
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const require_errors = require("./chunks/errors-CF2EQNbc.cjs");
|
|
4
4
|
const require_url = require("./chunks/url-CL4YTCvM.cjs");
|
|
5
5
|
const require_payload = require("./chunks/payload-DzHhs6Ey.cjs");
|
|
6
|
-
const require_inert_html = require("./chunks/inert-html-
|
|
6
|
+
const require_inert_html = require("./chunks/inert-html-aAsKvgJC.cjs");
|
|
7
7
|
const require_text_field = require("./chunks/text-field-BEzUVOag.cjs");
|
|
8
8
|
//#region src/link/fragment.ts
|
|
9
9
|
const invalid = (message) => require_errors.copyFailure("invalid-payload", message);
|
package/dist/link.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { n as copyFailure } from "./chunks/errors-CGcMvbhJ.js";
|
|
3
3
|
import { a as resolveLinkUrl, i as linkUrlResolver, n as TRACKING_PARAMETERS, r as cleanLinkUrl, t as DEFAULT_LINK_PROTOCOLS } from "./chunks/url-zB_krkuF.js";
|
|
4
4
|
import { a as resolveLink, i as markdownLink, n as cleanTitle, r as linkPayload, t as DEFAULT_LINK_TITLE_LENGTH } from "./chunks/payload-DZnXoBmF.js";
|
|
5
|
-
import {
|
|
5
|
+
import { n as parseInertHtml } from "./chunks/inert-html-BxuTrb6R.js";
|
|
6
6
|
import { n as insertText, t as asTextField } from "./chunks/text-field-D7PF2WlX.js";
|
|
7
7
|
//#region src/link/fragment.ts
|
|
8
8
|
const invalid = (message) => copyFailure("invalid-payload", message);
|
package/dist/markdown.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require_errors = require("./chunks/errors-CF2EQNbc.cjs");
|
|
4
|
-
const require_inert_html = require("./chunks/inert-html-
|
|
4
|
+
const require_inert_html = require("./chunks/inert-html-aAsKvgJC.cjs");
|
|
5
5
|
const require_url = require("./chunks/url-B9jdFGQy.cjs");
|
|
6
6
|
const require_text_field = require("./chunks/text-field-BEzUVOag.cjs");
|
|
7
7
|
//#region src/markdown/escape.ts
|
package/dist/markdown.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { n as copyFailure } from "./chunks/errors-CGcMvbhJ.js";
|
|
3
|
-
import {
|
|
3
|
+
import { n as parseInertHtml } from "./chunks/inert-html-BxuTrb6R.js";
|
|
4
4
|
import { i as safeUrl, n as DEFAULT_LINK_PROTOCOLS, r as linkDestination, t as DEFAULT_IMAGE_PROTOCOLS } from "./chunks/url-vJaFPbNL.js";
|
|
5
5
|
import { n as insertText, t as asTextField } from "./chunks/text-field-D7PF2WlX.js";
|
|
6
6
|
//#region src/markdown/escape.ts
|
package/dist/rich.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require_errors = require("./chunks/errors-CF2EQNbc.cjs");
|
|
4
4
|
const require_url = require("./chunks/url-CL4YTCvM.cjs");
|
|
5
|
-
const require_inert_html = require("./chunks/inert-html-
|
|
5
|
+
const require_inert_html = require("./chunks/inert-html-aAsKvgJC.cjs");
|
|
6
6
|
const require_url$1 = require("./chunks/url-B9jdFGQy.cjs");
|
|
7
7
|
const require_contrast = require("./chunks/contrast-BatHkv8j.cjs");
|
|
8
8
|
//#region src/rich/policy.ts
|
package/dist/rich.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { n as copyFailure } from "./chunks/errors-CGcMvbhJ.js";
|
|
3
3
|
import { i as linkUrlResolver } from "./chunks/url-zB_krkuF.js";
|
|
4
|
-
import {
|
|
4
|
+
import { n as parseInertHtml } from "./chunks/inert-html-BxuTrb6R.js";
|
|
5
5
|
import { a as unwrapRedirect } from "./chunks/url-vJaFPbNL.js";
|
|
6
6
|
import { i as formatColor, l as toGamut, n as contrastRatio, o as parseColor, s as color } from "./chunks/contrast-DnCunIr1.js";
|
|
7
7
|
//#region src/rich/policy.ts
|
package/dist/share.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const require_share = require("./chunks/share-
|
|
3
|
+
const require_share = require("./chunks/share-K1GpVQdH.cjs");
|
|
4
4
|
exports.describeShareError = require_share.describeShareError;
|
|
5
5
|
exports.shareMethod = require_share.shareMethod;
|
|
6
6
|
exports.shareOrCopy = require_share.shareOrCopy;
|
package/dist/share.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
|
|
2
|
-
export { n as describeShareError, r as shareMethod, i as shareOrCopy } from "./chunks/share-
|
|
2
|
+
export { n as describeShareError, r as shareMethod, i as shareOrCopy } from "./chunks/share-CW1SnFz5.js";
|
package/dist/table.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require_errors = require("./chunks/errors-CF2EQNbc.cjs");
|
|
4
|
-
const require_inert_html = require("./chunks/inert-html-
|
|
4
|
+
const require_inert_html = require("./chunks/inert-html-aAsKvgJC.cjs");
|
|
5
5
|
//#region src/table/serialize.ts
|
|
6
6
|
const DEFAULT_TABLE_MAX_CELLS = 1e6;
|
|
7
7
|
const FORMULA_START = /^[=+\-@\t\r\n=+-@]/;
|
|
@@ -432,7 +432,14 @@ function collectText(node, out) {
|
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
434
|
/** The text of one cell as it reads on screen: collapsed spaces, `<br>` and blocks as line breaks. */
|
|
435
|
+
/** Characters the slow path gives a meaning to: markers it uses, and the whitespace it rewrites. */
|
|
436
|
+
const NEEDS_SLOW_PATH = /[\uE000\uE001]/;
|
|
435
437
|
function cellText(cell) {
|
|
438
|
+
const only = cell.firstChild;
|
|
439
|
+
if (only !== null && only === cell.lastChild && only.nodeType === 3) {
|
|
440
|
+
const data = only.data;
|
|
441
|
+
if (!NEEDS_SLOW_PATH.test(data)) return data.replace(/[ \t\n\r\f]+/g, " ").replace(/^ +| +$/g, "").replace(/\u00A0/g, " ");
|
|
442
|
+
}
|
|
436
443
|
const parts = [];
|
|
437
444
|
collectText(cell, parts);
|
|
438
445
|
return parts.join("").replace(/ {2,}/g, " ").replace(/ *\uE001[\uE001 ]*/g, SOFT_BREAK).replace(/^\uE001|\uE001$/g, "").replace(/[\uE000\uE001]/g, "\n").split("\n").map((line) => line.replace(/^ +| +$/g, "").replace(/\u00A0/g, " ")).join("\n").replace(/^\n+|\n+$/g, "");
|
|
@@ -502,7 +509,7 @@ function readGrid(table, repeat, limits) {
|
|
|
502
509
|
}
|
|
503
510
|
function parseHtmlString(html) {
|
|
504
511
|
if (typeof DOMParser === "undefined") return null;
|
|
505
|
-
return require_inert_html.
|
|
512
|
+
return require_inert_html.parseHtmlToRead(html);
|
|
506
513
|
}
|
|
507
514
|
/**
|
|
508
515
|
* Reads the first non-empty `<table>` from an HTML string (such as Excel, Google Sheets,
|