@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 36 lines 1.24 KB
Raw
1 import {
2 COMPOSER_CONTEXT_CLIPBOARD_MIME,
3 encodeComposerContextClipboardHtml,
4 } from "@t3tools/shared/composerContextClipboard";
5 import { msg } from "gt-react";
6
7 import { m } from "../../i18n/messages";
8
9 import { readMediaPng } from "../media/mediaContent";
10
11 export async function copySnapshot(src: string, text: string, fragment: string): Promise<void> {
12 if (!navigator.clipboard?.write || typeof ClipboardItem === "undefined") {
13 throw new Error(m(msg("Snapshot copying requires a secure browser connection.")));
14 }
15 const formats = {
16 "image/png": readMediaPng(src),
17 "text/plain": new Blob([text], { type: "text/plain" }),
18 "text/html": new Blob([encodeComposerContextClipboardHtml(text, fragment)], {
19 type: "text/html",
20 }),
21 };
22 // Start writing within the click gesture, before the image fetch or decode completes.
23 try {
24 await navigator.clipboard.write([
25 new ClipboardItem({
26 ...formats,
27 [COMPOSER_CONTEXT_CLIPBOARD_MIME]: new Blob([fragment], {
28 type: COMPOSER_CONTEXT_CLIPBOARD_MIME,
29 }),
30 }),
31 ]);
32 } catch {
33 // HTML carries the same snapshot metadata when custom clipboard formats are unsupported.
34 await navigator.clipboard.write([new ClipboardItem(formats)]);
35 }
36 }