@tooee/clipboard 0.2.4 → 0.3.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/clipboard.d.ts +5 -5
- package/dist/clipboard.d.ts.map +1 -1
- package/dist/clipboard.js +137 -119
- package/dist/clipboard.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/clipboard.ts +202 -168
- package/src/index.ts +2 -2
package/dist/clipboard.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ export interface ClipboardContent {
|
|
|
2
2
|
data: string;
|
|
3
3
|
mime: string;
|
|
4
4
|
}
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
7
|
-
export declare
|
|
8
|
-
export declare
|
|
9
|
-
export declare
|
|
5
|
+
export declare const readClipboardText: () => Promise<string | undefined>;
|
|
6
|
+
export declare const readClipboard: () => Promise<ClipboardContent | undefined>;
|
|
7
|
+
export declare const readPrimaryText: () => Promise<string | undefined>;
|
|
8
|
+
export declare const copyToClipboard: (text: string) => Promise<void>;
|
|
9
|
+
export declare const copyToPrimary: (text: string) => Promise<void>;
|
|
10
10
|
//# sourceMappingURL=clipboard.d.ts.map
|
package/dist/clipboard.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAoBD,eAAO,MAAM,iBAAiB,QAAuC,OAAO,CAAC,MAAM,GAAG,SAAS,CAkB9F,CAAC;AAuDF,eAAO,MAAM,aAAa,QAAmC,OAAO,CAAC,gBAAgB,GAAG,SAAS,CA8BhG,CAAC;AAEF,eAAO,MAAM,eAAe,QAAqC,OAAO,CAAC,MAAM,GAAG,SAAS,CAuB1F,CAAC;AA2EF,eAAO,MAAM,eAAe,GAAkC,MAAM,MAAM,KAAG,OAAO,CAAC,IAAI,CAExF,CAAC;AA0DF,eAAO,MAAM,aAAa,GAAgC,MAAM,MAAM,KAAG,OAAO,CAAC,IAAI,CAEpF,CAAC"}
|
package/dist/clipboard.js
CHANGED
|
@@ -1,167 +1,184 @@
|
|
|
1
1
|
import { $ } from "bun";
|
|
2
|
-
import { platform, release, tmpdir } from "os";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
2
|
+
import { platform, release, tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const readLinuxClipboardText = async function readLinuxClipboardText() {
|
|
5
|
+
if ((process.env.WAYLAND_DISPLAY?.length ?? 0) > 0 && (Bun.which("wl-paste")?.length ?? 0) > 0) {
|
|
6
|
+
const result = await $ `wl-paste`.nothrow().quiet().text();
|
|
7
|
+
return result || undefined;
|
|
8
|
+
}
|
|
9
|
+
if ((Bun.which("xclip")?.length ?? 0) > 0) {
|
|
10
|
+
const result = await $ `xclip -selection clipboard -o`.nothrow().quiet().text();
|
|
11
|
+
return result || undefined;
|
|
12
|
+
}
|
|
13
|
+
if ((Bun.which("xsel")?.length ?? 0) > 0) {
|
|
14
|
+
const result = await $ `xsel --clipboard --output`.nothrow().quiet().text();
|
|
15
|
+
return result || undefined;
|
|
16
|
+
}
|
|
17
|
+
return undefined;
|
|
18
|
+
};
|
|
19
|
+
export const readClipboardText = async function readClipboardText() {
|
|
5
20
|
const os = platform();
|
|
6
21
|
if (os === "darwin") {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const result = await $ `pbpaste`.nothrow().quiet().text();
|
|
23
|
+
return result || undefined;
|
|
24
|
+
}
|
|
25
|
+
if (os === "linux") {
|
|
26
|
+
return await readLinuxClipboardText();
|
|
27
|
+
}
|
|
28
|
+
if (os === "win32") {
|
|
29
|
+
const result = await $ `powershell -command "Get-Clipboard"`.nothrow().quiet().text();
|
|
30
|
+
return result || undefined;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
};
|
|
34
|
+
const readMacClipboardImage = async function readMacClipboardImage() {
|
|
35
|
+
const tmpfile = path.join(tmpdir(), "tooee-clipboard.png");
|
|
36
|
+
try {
|
|
37
|
+
await $ `osascript -e 'set imageData to the clipboard as "PNGf"' -e 'set fileRef to open for access POSIX file "${tmpfile}" with write permission' -e 'set eof fileRef to 0' -e 'write imageData to fileRef' -e 'close access fileRef'`
|
|
38
|
+
.nothrow()
|
|
39
|
+
.quiet();
|
|
40
|
+
const buffer = await Bun.file(tmpfile).arrayBuffer();
|
|
41
|
+
if (buffer.byteLength > 0) {
|
|
42
|
+
return { data: Buffer.from(buffer).toString("base64"), mime: "image/png" };
|
|
26
43
|
}
|
|
27
44
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
catch {
|
|
46
|
+
// Image read failed, try text below
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
await $ `rm -f "${tmpfile}"`.nothrow().quiet();
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
};
|
|
53
|
+
const readWindowsClipboardImage = async function readWindowsClipboardImage() {
|
|
54
|
+
const script = "Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }";
|
|
55
|
+
const base64 = await $ `powershell.exe -command "${script}"`.nothrow().text();
|
|
56
|
+
if (base64) {
|
|
57
|
+
const imageBuffer = Buffer.from(base64.trim(), "base64");
|
|
58
|
+
if (imageBuffer.length > 0) {
|
|
59
|
+
return { data: imageBuffer.toString("base64"), mime: "image/png" };
|
|
36
60
|
}
|
|
37
61
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (Bun.which("xclip")) {
|
|
49
|
-
const x11 = await $ `xclip -selection clipboard -t image/png -o`.nothrow().arrayBuffer();
|
|
50
|
-
if (x11 && x11.byteLength > 0) {
|
|
51
|
-
return {
|
|
52
|
-
data: Buffer.from(x11).toString("base64"),
|
|
53
|
-
mime: "image/png",
|
|
54
|
-
};
|
|
55
|
-
}
|
|
62
|
+
return undefined;
|
|
63
|
+
};
|
|
64
|
+
const readLinuxClipboardImage = async function readLinuxClipboardImage() {
|
|
65
|
+
if ((process.env.WAYLAND_DISPLAY?.length ?? 0) > 0 && (Bun.which("wl-paste")?.length ?? 0) > 0) {
|
|
66
|
+
const wayland = await $ `wl-paste -t image/png`.nothrow().arrayBuffer();
|
|
67
|
+
if (wayland.byteLength > 0) {
|
|
68
|
+
return { data: Buffer.from(wayland).toString("base64"), mime: "image/png" };
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
if ((Bun.which("xclip")?.length ?? 0) > 0) {
|
|
72
|
+
const x11 = await $ `xclip -selection clipboard -t image/png -o`.nothrow().arrayBuffer();
|
|
73
|
+
if (x11.byteLength > 0) {
|
|
74
|
+
return { data: Buffer.from(x11).toString("base64"), mime: "image/png" };
|
|
75
|
+
}
|
|
61
76
|
}
|
|
62
77
|
return undefined;
|
|
63
|
-
}
|
|
64
|
-
export async function
|
|
78
|
+
};
|
|
79
|
+
export const readClipboard = async function readClipboard() {
|
|
65
80
|
const os = platform();
|
|
66
81
|
if (os === "darwin") {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (os === "linux") {
|
|
71
|
-
if (process.env["WAYLAND_DISPLAY"] && Bun.which("wl-paste")) {
|
|
72
|
-
const result = await $ `wl-paste`.nothrow().quiet().text();
|
|
73
|
-
return result || undefined;
|
|
82
|
+
const image = await readMacClipboardImage();
|
|
83
|
+
if (image) {
|
|
84
|
+
return image;
|
|
74
85
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
86
|
+
}
|
|
87
|
+
if (os === "win32" || release().includes("WSL")) {
|
|
88
|
+
const image = await readWindowsClipboardImage();
|
|
89
|
+
if (image) {
|
|
90
|
+
return image;
|
|
78
91
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
92
|
+
}
|
|
93
|
+
if (os === "linux") {
|
|
94
|
+
const image = await readLinuxClipboardImage();
|
|
95
|
+
if (image) {
|
|
96
|
+
return image;
|
|
82
97
|
}
|
|
83
98
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return
|
|
99
|
+
const text = await readClipboardText();
|
|
100
|
+
if (text !== undefined && text !== "") {
|
|
101
|
+
return { data: text, mime: "text/plain" };
|
|
87
102
|
}
|
|
88
103
|
return undefined;
|
|
89
|
-
}
|
|
90
|
-
export async function readPrimaryText() {
|
|
104
|
+
};
|
|
105
|
+
export const readPrimaryText = async function readPrimaryText() {
|
|
91
106
|
const os = platform();
|
|
92
107
|
if (os === "linux") {
|
|
93
|
-
if (process.env
|
|
108
|
+
if ((process.env.WAYLAND_DISPLAY?.length ?? 0) > 0 &&
|
|
109
|
+
(Bun.which("wl-paste")?.length ?? 0) > 0) {
|
|
94
110
|
const result = await $ `wl-paste --primary`.nothrow().quiet().text();
|
|
95
111
|
return result || undefined;
|
|
96
112
|
}
|
|
97
|
-
if (Bun.which("xclip")) {
|
|
113
|
+
if ((Bun.which("xclip")?.length ?? 0) > 0) {
|
|
98
114
|
const result = await $ `xclip -selection primary -o`.nothrow().quiet().text();
|
|
99
115
|
return result || undefined;
|
|
100
116
|
}
|
|
101
|
-
if (Bun.which("xsel")) {
|
|
117
|
+
if ((Bun.which("xsel")?.length ?? 0) > 0) {
|
|
102
118
|
const result = await $ `xsel --primary --output`.nothrow().quiet().text();
|
|
103
119
|
return result || undefined;
|
|
104
120
|
}
|
|
105
121
|
}
|
|
106
122
|
// macOS/Windows don't have PRIMARY selection — fall back to clipboard
|
|
107
|
-
return readClipboardText();
|
|
108
|
-
}
|
|
123
|
+
return await readClipboardText();
|
|
124
|
+
};
|
|
109
125
|
let copyMethod = null;
|
|
110
|
-
function getCopyMethod() {
|
|
111
|
-
if (copyMethod)
|
|
126
|
+
const getCopyMethod = function getCopyMethod() {
|
|
127
|
+
if (copyMethod) {
|
|
112
128
|
return copyMethod;
|
|
129
|
+
}
|
|
113
130
|
const os = platform();
|
|
114
|
-
if (os === "darwin" && Bun.which("osascript")) {
|
|
131
|
+
if (os === "darwin" && (Bun.which("osascript")?.length ?? 0) > 0) {
|
|
115
132
|
copyMethod = async (text) => {
|
|
116
|
-
const escaped = text.
|
|
133
|
+
const escaped = text.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
|
117
134
|
await $ `osascript -e 'set the clipboard to "${escaped}"'`.nothrow().quiet();
|
|
118
135
|
};
|
|
119
136
|
return copyMethod;
|
|
120
137
|
}
|
|
121
138
|
if (os === "linux") {
|
|
122
|
-
if (process.env
|
|
139
|
+
if ((process.env.WAYLAND_DISPLAY?.length ?? 0) > 0 && (Bun.which("wl-copy")?.length ?? 0) > 0) {
|
|
123
140
|
copyMethod = async (text) => {
|
|
124
141
|
const proc = Bun.spawn(["wl-copy"], {
|
|
142
|
+
stderr: "ignore",
|
|
125
143
|
stdin: "pipe",
|
|
126
144
|
stdout: "ignore",
|
|
127
|
-
stderr: "ignore",
|
|
128
145
|
});
|
|
129
|
-
proc.stdin.write(text);
|
|
130
|
-
proc.stdin.end();
|
|
131
|
-
await proc.exited.catch(() =>
|
|
146
|
+
await proc.stdin.write(text);
|
|
147
|
+
await proc.stdin.end();
|
|
148
|
+
await proc.exited.catch(() => null);
|
|
132
149
|
};
|
|
133
150
|
return copyMethod;
|
|
134
151
|
}
|
|
135
|
-
if (Bun.which("xclip")) {
|
|
152
|
+
if ((Bun.which("xclip")?.length ?? 0) > 0) {
|
|
136
153
|
copyMethod = async (text) => {
|
|
137
154
|
const proc = Bun.spawn(["xclip", "-selection", "clipboard"], {
|
|
155
|
+
stderr: "ignore",
|
|
138
156
|
stdin: "pipe",
|
|
139
157
|
stdout: "ignore",
|
|
140
|
-
stderr: "ignore",
|
|
141
158
|
});
|
|
142
|
-
proc.stdin.write(text);
|
|
143
|
-
proc.stdin.end();
|
|
144
|
-
await proc.exited.catch(() =>
|
|
159
|
+
await proc.stdin.write(text);
|
|
160
|
+
await proc.stdin.end();
|
|
161
|
+
await proc.exited.catch(() => null);
|
|
145
162
|
};
|
|
146
163
|
return copyMethod;
|
|
147
164
|
}
|
|
148
|
-
if (Bun.which("xsel")) {
|
|
165
|
+
if ((Bun.which("xsel")?.length ?? 0) > 0) {
|
|
149
166
|
copyMethod = async (text) => {
|
|
150
167
|
const proc = Bun.spawn(["xsel", "--clipboard", "--input"], {
|
|
168
|
+
stderr: "ignore",
|
|
151
169
|
stdin: "pipe",
|
|
152
170
|
stdout: "ignore",
|
|
153
|
-
stderr: "ignore",
|
|
154
171
|
});
|
|
155
|
-
proc.stdin.write(text);
|
|
156
|
-
proc.stdin.end();
|
|
157
|
-
await proc.exited.catch(() =>
|
|
172
|
+
await proc.stdin.write(text);
|
|
173
|
+
await proc.stdin.end();
|
|
174
|
+
await proc.exited.catch(() => null);
|
|
158
175
|
};
|
|
159
176
|
return copyMethod;
|
|
160
177
|
}
|
|
161
178
|
}
|
|
162
179
|
if (os === "win32") {
|
|
163
180
|
copyMethod = async (text) => {
|
|
164
|
-
const escaped = text.
|
|
181
|
+
const escaped = text.replaceAll('"', '""');
|
|
165
182
|
await $ `powershell -command "Set-Clipboard -Value \"${escaped}\""`.nothrow().quiet();
|
|
166
183
|
};
|
|
167
184
|
return copyMethod;
|
|
@@ -170,52 +187,53 @@ function getCopyMethod() {
|
|
|
170
187
|
// Silent no-op — no clipboard support available
|
|
171
188
|
};
|
|
172
189
|
return copyMethod;
|
|
173
|
-
}
|
|
174
|
-
export async function copyToClipboard(text) {
|
|
190
|
+
};
|
|
191
|
+
export const copyToClipboard = async function copyToClipboard(text) {
|
|
175
192
|
await getCopyMethod()(text);
|
|
176
|
-
}
|
|
193
|
+
};
|
|
177
194
|
let primaryCopyMethod = null;
|
|
178
|
-
function getPrimaryCopyMethod() {
|
|
179
|
-
if (primaryCopyMethod)
|
|
195
|
+
const getPrimaryCopyMethod = function getPrimaryCopyMethod() {
|
|
196
|
+
if (primaryCopyMethod) {
|
|
180
197
|
return primaryCopyMethod;
|
|
198
|
+
}
|
|
181
199
|
const os = platform();
|
|
182
200
|
if (os === "linux") {
|
|
183
|
-
if (process.env
|
|
201
|
+
if ((process.env.WAYLAND_DISPLAY?.length ?? 0) > 0 && (Bun.which("wl-copy")?.length ?? 0) > 0) {
|
|
184
202
|
primaryCopyMethod = async (text) => {
|
|
185
203
|
const proc = Bun.spawn(["wl-copy", "--primary"], {
|
|
204
|
+
stderr: "ignore",
|
|
186
205
|
stdin: "pipe",
|
|
187
206
|
stdout: "ignore",
|
|
188
|
-
stderr: "ignore",
|
|
189
207
|
});
|
|
190
|
-
proc.stdin.write(text);
|
|
191
|
-
proc.stdin.end();
|
|
192
|
-
await proc.exited.catch(() =>
|
|
208
|
+
await proc.stdin.write(text);
|
|
209
|
+
await proc.stdin.end();
|
|
210
|
+
await proc.exited.catch(() => null);
|
|
193
211
|
};
|
|
194
212
|
return primaryCopyMethod;
|
|
195
213
|
}
|
|
196
|
-
if (Bun.which("xclip")) {
|
|
214
|
+
if ((Bun.which("xclip")?.length ?? 0) > 0) {
|
|
197
215
|
primaryCopyMethod = async (text) => {
|
|
198
216
|
const proc = Bun.spawn(["xclip", "-selection", "primary"], {
|
|
217
|
+
stderr: "ignore",
|
|
199
218
|
stdin: "pipe",
|
|
200
219
|
stdout: "ignore",
|
|
201
|
-
stderr: "ignore",
|
|
202
220
|
});
|
|
203
|
-
proc.stdin.write(text);
|
|
204
|
-
proc.stdin.end();
|
|
205
|
-
await proc.exited.catch(() =>
|
|
221
|
+
await proc.stdin.write(text);
|
|
222
|
+
await proc.stdin.end();
|
|
223
|
+
await proc.exited.catch(() => null);
|
|
206
224
|
};
|
|
207
225
|
return primaryCopyMethod;
|
|
208
226
|
}
|
|
209
|
-
if (Bun.which("xsel")) {
|
|
227
|
+
if ((Bun.which("xsel")?.length ?? 0) > 0) {
|
|
210
228
|
primaryCopyMethod = async (text) => {
|
|
211
229
|
const proc = Bun.spawn(["xsel", "--primary", "--input"], {
|
|
230
|
+
stderr: "ignore",
|
|
212
231
|
stdin: "pipe",
|
|
213
232
|
stdout: "ignore",
|
|
214
|
-
stderr: "ignore",
|
|
215
233
|
});
|
|
216
|
-
proc.stdin.write(text);
|
|
217
|
-
proc.stdin.end();
|
|
218
|
-
await proc.exited.catch(() =>
|
|
234
|
+
await proc.stdin.write(text);
|
|
235
|
+
await proc.stdin.end();
|
|
236
|
+
await proc.exited.catch(() => null);
|
|
219
237
|
};
|
|
220
238
|
return primaryCopyMethod;
|
|
221
239
|
}
|
|
@@ -223,8 +241,8 @@ function getPrimaryCopyMethod() {
|
|
|
223
241
|
// macOS/Windows don't have PRIMARY selection — fall back to clipboard
|
|
224
242
|
primaryCopyMethod = getCopyMethod();
|
|
225
243
|
return primaryCopyMethod;
|
|
226
|
-
}
|
|
227
|
-
export async function copyToPrimary(text) {
|
|
244
|
+
};
|
|
245
|
+
export const copyToPrimary = async function copyToPrimary(text) {
|
|
228
246
|
await getPrimaryCopyMethod()(text);
|
|
229
|
-
}
|
|
247
|
+
};
|
|
230
248
|
//# sourceMappingURL=clipboard.js.map
|
package/dist/clipboard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../src/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,IAAI,MAAM,WAAW,CAAC;AAO7B,MAAM,sBAAsB,GAAG,KAAK,UAAU,sBAAsB;IAGlE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/F,MAAM,MAAM,GAAG,MAAM,CAAC,CAAA,UAAU,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;QAC1D,OAAO,MAAM,IAAI,SAAS,CAAC;IAC7B,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,CAAA,+BAA+B,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;QAC/E,OAAO,MAAM,IAAI,SAAS,CAAC;IAC7B,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI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G,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;YACzC,iBAAiB,GAAG,KAAK,EAAE,IAAY,EAAE,EAAE;gBACzC,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE;oBACvD,MAAM,EAAE,QAAQ;oBAChB,KAAK,EAAE,MAAM;oBACb,MAAM,EAAE,QAAQ;iBACjB,CAAC,CAAC;gBACH,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC7B,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;gBACvB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;YACtC,CAAC,CAAC;YACF,OAAO,iBAAiB,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,sEAAsE;IACtE,iBAAiB,GAAG,aAAa,EAAE,CAAC;IACpC,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,UAAU,aAAa,CAAC,IAAY;IACpE,MAAM,oBAAoB,EAAE,CAAC,IAAI,CAAC,CAAC;AACrC,CAAC,CAAC"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,GAChB,MAAM,gBAAgB,CAAC"}
|
package/package.json
CHANGED
package/src/clipboard.ts
CHANGED
|
@@ -1,259 +1,293 @@
|
|
|
1
|
-
import { $ } from "bun"
|
|
2
|
-
import { platform, release, tmpdir } from "os"
|
|
3
|
-
import path from "path"
|
|
1
|
+
import { $ } from "bun";
|
|
2
|
+
import { platform, release, tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
4
|
|
|
5
5
|
export interface ClipboardContent {
|
|
6
|
-
data: string
|
|
7
|
-
mime: string
|
|
6
|
+
data: string;
|
|
7
|
+
mime: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const readLinuxClipboardText = async function readLinuxClipboardText(): Promise<
|
|
11
|
+
string | undefined
|
|
12
|
+
> {
|
|
13
|
+
if ((process.env.WAYLAND_DISPLAY?.length ?? 0) > 0 && (Bun.which("wl-paste")?.length ?? 0) > 0) {
|
|
14
|
+
const result = await $`wl-paste`.nothrow().quiet().text();
|
|
15
|
+
return result || undefined;
|
|
16
|
+
}
|
|
17
|
+
if ((Bun.which("xclip")?.length ?? 0) > 0) {
|
|
18
|
+
const result = await $`xclip -selection clipboard -o`.nothrow().quiet().text();
|
|
19
|
+
return result || undefined;
|
|
20
|
+
}
|
|
21
|
+
if ((Bun.which("xsel")?.length ?? 0) > 0) {
|
|
22
|
+
const result = await $`xsel --clipboard --output`.nothrow().quiet().text();
|
|
23
|
+
return result || undefined;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const readClipboardText = async function readClipboardText(): Promise<string | undefined> {
|
|
29
|
+
const os = platform();
|
|
12
30
|
|
|
13
31
|
if (os === "darwin") {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
await $`osascript -e 'set imageData to the clipboard as "PNGf"' -e 'set fileRef to open for access POSIX file "${tmpfile}" with write permission' -e 'set eof fileRef to 0' -e 'write imageData to fileRef' -e 'close access fileRef'`
|
|
17
|
-
.nothrow()
|
|
18
|
-
.quiet()
|
|
19
|
-
const file = Bun.file(tmpfile)
|
|
20
|
-
const buffer = await file.arrayBuffer()
|
|
21
|
-
if (buffer.byteLength > 0) {
|
|
22
|
-
return {
|
|
23
|
-
data: Buffer.from(buffer).toString("base64"),
|
|
24
|
-
mime: "image/png",
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
} catch {
|
|
28
|
-
// Image read failed, try text below
|
|
29
|
-
} finally {
|
|
30
|
-
await $`rm -f "${tmpfile}"`.nothrow().quiet()
|
|
31
|
-
}
|
|
32
|
+
const result = await $`pbpaste`.nothrow().quiet().text();
|
|
33
|
+
return result || undefined;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
if (os === "
|
|
35
|
-
|
|
36
|
-
"Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }"
|
|
37
|
-
const base64 = await $`powershell.exe -command "${script}"`.nothrow().text()
|
|
38
|
-
if (base64) {
|
|
39
|
-
const imageBuffer = Buffer.from(base64.trim(), "base64")
|
|
40
|
-
if (imageBuffer.length > 0) {
|
|
41
|
-
return { data: imageBuffer.toString("base64"), mime: "image/png" }
|
|
42
|
-
}
|
|
43
|
-
}
|
|
36
|
+
if (os === "linux") {
|
|
37
|
+
return await readLinuxClipboardText();
|
|
44
38
|
}
|
|
45
39
|
|
|
46
|
-
if (os === "
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
40
|
+
if (os === "win32") {
|
|
41
|
+
const result = await $`powershell -command "Get-Clipboard"`.nothrow().quiet().text();
|
|
42
|
+
return result || undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return undefined;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const readMacClipboardImage = async function readMacClipboardImage(): Promise<
|
|
49
|
+
ClipboardContent | undefined
|
|
50
|
+
> {
|
|
51
|
+
const tmpfile = path.join(tmpdir(), "tooee-clipboard.png");
|
|
52
|
+
try {
|
|
53
|
+
await $`osascript -e 'set imageData to the clipboard as "PNGf"' -e 'set fileRef to open for access POSIX file "${tmpfile}" with write permission' -e 'set eof fileRef to 0' -e 'write imageData to fileRef' -e 'close access fileRef'`
|
|
54
|
+
.nothrow()
|
|
55
|
+
.quiet();
|
|
56
|
+
const buffer = await Bun.file(tmpfile).arrayBuffer();
|
|
57
|
+
if (buffer.byteLength > 0) {
|
|
58
|
+
return { data: Buffer.from(buffer).toString("base64"), mime: "image/png" };
|
|
64
59
|
}
|
|
60
|
+
} catch {
|
|
61
|
+
// Image read failed, try text below
|
|
62
|
+
} finally {
|
|
63
|
+
await $`rm -f "${tmpfile}"`.nothrow().quiet();
|
|
65
64
|
}
|
|
65
|
+
return undefined;
|
|
66
|
+
};
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
const readWindowsClipboardImage = async function readWindowsClipboardImage(): Promise<
|
|
69
|
+
ClipboardContent | undefined
|
|
70
|
+
> {
|
|
71
|
+
const script =
|
|
72
|
+
"Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }";
|
|
73
|
+
const base64 = await $`powershell.exe -command "${script}"`.nothrow().text();
|
|
74
|
+
if (base64) {
|
|
75
|
+
const imageBuffer = Buffer.from(base64.trim(), "base64");
|
|
76
|
+
if (imageBuffer.length > 0) {
|
|
77
|
+
return { data: imageBuffer.toString("base64"), mime: "image/png" };
|
|
78
|
+
}
|
|
70
79
|
}
|
|
80
|
+
return undefined;
|
|
81
|
+
};
|
|
71
82
|
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
const readLinuxClipboardImage = async function readLinuxClipboardImage(): Promise<
|
|
84
|
+
ClipboardContent | undefined
|
|
85
|
+
> {
|
|
86
|
+
if ((process.env.WAYLAND_DISPLAY?.length ?? 0) > 0 && (Bun.which("wl-paste")?.length ?? 0) > 0) {
|
|
87
|
+
const wayland = await $`wl-paste -t image/png`.nothrow().arrayBuffer();
|
|
88
|
+
if (wayland.byteLength > 0) {
|
|
89
|
+
return { data: Buffer.from(wayland).toString("base64"), mime: "image/png" };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if ((Bun.which("xclip")?.length ?? 0) > 0) {
|
|
93
|
+
const x11 = await $`xclip -selection clipboard -t image/png -o`.nothrow().arrayBuffer();
|
|
94
|
+
if (x11.byteLength > 0) {
|
|
95
|
+
return { data: Buffer.from(x11).toString("base64"), mime: "image/png" };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
};
|
|
74
100
|
|
|
75
|
-
export async function
|
|
76
|
-
const os = platform()
|
|
101
|
+
export const readClipboard = async function readClipboard(): Promise<ClipboardContent | undefined> {
|
|
102
|
+
const os = platform();
|
|
77
103
|
|
|
78
104
|
if (os === "darwin") {
|
|
79
|
-
const
|
|
80
|
-
|
|
105
|
+
const image = await readMacClipboardImage();
|
|
106
|
+
if (image) {
|
|
107
|
+
return image;
|
|
108
|
+
}
|
|
81
109
|
}
|
|
82
110
|
|
|
83
|
-
if (os === "
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
if (Bun.which("xclip")) {
|
|
89
|
-
const result = await $`xclip -selection clipboard -o`.nothrow().quiet().text()
|
|
90
|
-
return result || undefined
|
|
111
|
+
if (os === "win32" || release().includes("WSL")) {
|
|
112
|
+
const image = await readWindowsClipboardImage();
|
|
113
|
+
if (image) {
|
|
114
|
+
return image;
|
|
91
115
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (os === "linux") {
|
|
119
|
+
const image = await readLinuxClipboardImage();
|
|
120
|
+
if (image) {
|
|
121
|
+
return image;
|
|
95
122
|
}
|
|
96
123
|
}
|
|
97
124
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
125
|
+
const text = await readClipboardText();
|
|
126
|
+
if (text !== undefined && text !== "") {
|
|
127
|
+
return { data: text, mime: "text/plain" };
|
|
101
128
|
}
|
|
102
129
|
|
|
103
|
-
return undefined
|
|
104
|
-
}
|
|
130
|
+
return undefined;
|
|
131
|
+
};
|
|
105
132
|
|
|
106
|
-
export async function readPrimaryText(): Promise<string | undefined> {
|
|
107
|
-
const os = platform()
|
|
133
|
+
export const readPrimaryText = async function readPrimaryText(): Promise<string | undefined> {
|
|
134
|
+
const os = platform();
|
|
108
135
|
|
|
109
136
|
if (os === "linux") {
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
137
|
+
if (
|
|
138
|
+
(process.env.WAYLAND_DISPLAY?.length ?? 0) > 0 &&
|
|
139
|
+
(Bun.which("wl-paste")?.length ?? 0) > 0
|
|
140
|
+
) {
|
|
141
|
+
const result = await $`wl-paste --primary`.nothrow().quiet().text();
|
|
142
|
+
return result || undefined;
|
|
113
143
|
}
|
|
114
|
-
if (Bun.which("xclip")) {
|
|
115
|
-
const result = await $`xclip -selection primary -o`.nothrow().quiet().text()
|
|
116
|
-
return result || undefined
|
|
144
|
+
if ((Bun.which("xclip")?.length ?? 0) > 0) {
|
|
145
|
+
const result = await $`xclip -selection primary -o`.nothrow().quiet().text();
|
|
146
|
+
return result || undefined;
|
|
117
147
|
}
|
|
118
|
-
if (Bun.which("xsel")) {
|
|
119
|
-
const result = await $`xsel --primary --output`.nothrow().quiet().text()
|
|
120
|
-
return result || undefined
|
|
148
|
+
if ((Bun.which("xsel")?.length ?? 0) > 0) {
|
|
149
|
+
const result = await $`xsel --primary --output`.nothrow().quiet().text();
|
|
150
|
+
return result || undefined;
|
|
121
151
|
}
|
|
122
152
|
}
|
|
123
153
|
|
|
124
154
|
// macOS/Windows don't have PRIMARY selection — fall back to clipboard
|
|
125
|
-
return readClipboardText()
|
|
126
|
-
}
|
|
155
|
+
return await readClipboardText();
|
|
156
|
+
};
|
|
127
157
|
|
|
128
|
-
let copyMethod: ((text: string) => Promise<void>) | null = null
|
|
158
|
+
let copyMethod: ((text: string) => Promise<void>) | null = null;
|
|
129
159
|
|
|
130
|
-
function getCopyMethod(): (text: string) => Promise<void> {
|
|
131
|
-
if (copyMethod)
|
|
160
|
+
const getCopyMethod = function getCopyMethod(): (text: string) => Promise<void> {
|
|
161
|
+
if (copyMethod) {
|
|
162
|
+
return copyMethod;
|
|
163
|
+
}
|
|
132
164
|
|
|
133
|
-
const os = platform()
|
|
165
|
+
const os = platform();
|
|
134
166
|
|
|
135
|
-
if (os === "darwin" && Bun.which("osascript")) {
|
|
167
|
+
if (os === "darwin" && (Bun.which("osascript")?.length ?? 0) > 0) {
|
|
136
168
|
copyMethod = async (text: string) => {
|
|
137
|
-
const escaped = text.
|
|
138
|
-
await $`osascript -e 'set the clipboard to "${escaped}"'`.nothrow().quiet()
|
|
139
|
-
}
|
|
140
|
-
return copyMethod
|
|
169
|
+
const escaped = text.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
|
|
170
|
+
await $`osascript -e 'set the clipboard to "${escaped}"'`.nothrow().quiet();
|
|
171
|
+
};
|
|
172
|
+
return copyMethod;
|
|
141
173
|
}
|
|
142
174
|
|
|
143
175
|
if (os === "linux") {
|
|
144
|
-
if (process.env
|
|
176
|
+
if ((process.env.WAYLAND_DISPLAY?.length ?? 0) > 0 && (Bun.which("wl-copy")?.length ?? 0) > 0) {
|
|
145
177
|
copyMethod = async (text: string) => {
|
|
146
178
|
const proc = Bun.spawn(["wl-copy"], {
|
|
179
|
+
stderr: "ignore",
|
|
147
180
|
stdin: "pipe",
|
|
148
181
|
stdout: "ignore",
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
proc.stdin.
|
|
152
|
-
proc.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return copyMethod
|
|
182
|
+
});
|
|
183
|
+
await proc.stdin.write(text);
|
|
184
|
+
await proc.stdin.end();
|
|
185
|
+
await proc.exited.catch(() => null);
|
|
186
|
+
};
|
|
187
|
+
return copyMethod;
|
|
156
188
|
}
|
|
157
|
-
if (Bun.which("xclip")) {
|
|
189
|
+
if ((Bun.which("xclip")?.length ?? 0) > 0) {
|
|
158
190
|
copyMethod = async (text: string) => {
|
|
159
191
|
const proc = Bun.spawn(["xclip", "-selection", "clipboard"], {
|
|
192
|
+
stderr: "ignore",
|
|
160
193
|
stdin: "pipe",
|
|
161
194
|
stdout: "ignore",
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
proc.stdin.
|
|
165
|
-
proc.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return copyMethod
|
|
195
|
+
});
|
|
196
|
+
await proc.stdin.write(text);
|
|
197
|
+
await proc.stdin.end();
|
|
198
|
+
await proc.exited.catch(() => null);
|
|
199
|
+
};
|
|
200
|
+
return copyMethod;
|
|
169
201
|
}
|
|
170
|
-
if (Bun.which("xsel")) {
|
|
202
|
+
if ((Bun.which("xsel")?.length ?? 0) > 0) {
|
|
171
203
|
copyMethod = async (text: string) => {
|
|
172
204
|
const proc = Bun.spawn(["xsel", "--clipboard", "--input"], {
|
|
205
|
+
stderr: "ignore",
|
|
173
206
|
stdin: "pipe",
|
|
174
207
|
stdout: "ignore",
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
proc.stdin.
|
|
178
|
-
proc.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return copyMethod
|
|
208
|
+
});
|
|
209
|
+
await proc.stdin.write(text);
|
|
210
|
+
await proc.stdin.end();
|
|
211
|
+
await proc.exited.catch(() => null);
|
|
212
|
+
};
|
|
213
|
+
return copyMethod;
|
|
182
214
|
}
|
|
183
215
|
}
|
|
184
216
|
|
|
185
217
|
if (os === "win32") {
|
|
186
218
|
copyMethod = async (text: string) => {
|
|
187
|
-
const escaped = text.
|
|
188
|
-
await $`powershell -command "Set-Clipboard -Value \"${escaped}\""`.nothrow().quiet()
|
|
189
|
-
}
|
|
190
|
-
return copyMethod
|
|
219
|
+
const escaped = text.replaceAll('"', '""');
|
|
220
|
+
await $`powershell -command "Set-Clipboard -Value \"${escaped}\""`.nothrow().quiet();
|
|
221
|
+
};
|
|
222
|
+
return copyMethod;
|
|
191
223
|
}
|
|
192
224
|
|
|
193
225
|
copyMethod = async () => {
|
|
194
226
|
// Silent no-op — no clipboard support available
|
|
195
|
-
}
|
|
196
|
-
return copyMethod
|
|
197
|
-
}
|
|
227
|
+
};
|
|
228
|
+
return copyMethod;
|
|
229
|
+
};
|
|
198
230
|
|
|
199
|
-
export async function copyToClipboard(text: string): Promise<void> {
|
|
200
|
-
await getCopyMethod()(text)
|
|
201
|
-
}
|
|
231
|
+
export const copyToClipboard = async function copyToClipboard(text: string): Promise<void> {
|
|
232
|
+
await getCopyMethod()(text);
|
|
233
|
+
};
|
|
202
234
|
|
|
203
|
-
let primaryCopyMethod: ((text: string) => Promise<void>) | null = null
|
|
235
|
+
let primaryCopyMethod: ((text: string) => Promise<void>) | null = null;
|
|
204
236
|
|
|
205
|
-
function getPrimaryCopyMethod(): (text: string) => Promise<void> {
|
|
206
|
-
if (primaryCopyMethod)
|
|
237
|
+
const getPrimaryCopyMethod = function getPrimaryCopyMethod(): (text: string) => Promise<void> {
|
|
238
|
+
if (primaryCopyMethod) {
|
|
239
|
+
return primaryCopyMethod;
|
|
240
|
+
}
|
|
207
241
|
|
|
208
|
-
const os = platform()
|
|
242
|
+
const os = platform();
|
|
209
243
|
|
|
210
244
|
if (os === "linux") {
|
|
211
|
-
if (process.env
|
|
245
|
+
if ((process.env.WAYLAND_DISPLAY?.length ?? 0) > 0 && (Bun.which("wl-copy")?.length ?? 0) > 0) {
|
|
212
246
|
primaryCopyMethod = async (text: string) => {
|
|
213
247
|
const proc = Bun.spawn(["wl-copy", "--primary"], {
|
|
248
|
+
stderr: "ignore",
|
|
214
249
|
stdin: "pipe",
|
|
215
250
|
stdout: "ignore",
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
proc.stdin.
|
|
219
|
-
proc.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
return primaryCopyMethod
|
|
251
|
+
});
|
|
252
|
+
await proc.stdin.write(text);
|
|
253
|
+
await proc.stdin.end();
|
|
254
|
+
await proc.exited.catch(() => null);
|
|
255
|
+
};
|
|
256
|
+
return primaryCopyMethod;
|
|
223
257
|
}
|
|
224
|
-
if (Bun.which("xclip")) {
|
|
258
|
+
if ((Bun.which("xclip")?.length ?? 0) > 0) {
|
|
225
259
|
primaryCopyMethod = async (text: string) => {
|
|
226
260
|
const proc = Bun.spawn(["xclip", "-selection", "primary"], {
|
|
261
|
+
stderr: "ignore",
|
|
227
262
|
stdin: "pipe",
|
|
228
263
|
stdout: "ignore",
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
proc.stdin.
|
|
232
|
-
proc.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return primaryCopyMethod
|
|
264
|
+
});
|
|
265
|
+
await proc.stdin.write(text);
|
|
266
|
+
await proc.stdin.end();
|
|
267
|
+
await proc.exited.catch(() => null);
|
|
268
|
+
};
|
|
269
|
+
return primaryCopyMethod;
|
|
236
270
|
}
|
|
237
|
-
if (Bun.which("xsel")) {
|
|
271
|
+
if ((Bun.which("xsel")?.length ?? 0) > 0) {
|
|
238
272
|
primaryCopyMethod = async (text: string) => {
|
|
239
273
|
const proc = Bun.spawn(["xsel", "--primary", "--input"], {
|
|
274
|
+
stderr: "ignore",
|
|
240
275
|
stdin: "pipe",
|
|
241
276
|
stdout: "ignore",
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
proc.stdin.
|
|
245
|
-
proc.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return primaryCopyMethod
|
|
277
|
+
});
|
|
278
|
+
await proc.stdin.write(text);
|
|
279
|
+
await proc.stdin.end();
|
|
280
|
+
await proc.exited.catch(() => null);
|
|
281
|
+
};
|
|
282
|
+
return primaryCopyMethod;
|
|
249
283
|
}
|
|
250
284
|
}
|
|
251
285
|
|
|
252
286
|
// macOS/Windows don't have PRIMARY selection — fall back to clipboard
|
|
253
|
-
primaryCopyMethod = getCopyMethod()
|
|
254
|
-
return primaryCopyMethod
|
|
255
|
-
}
|
|
287
|
+
primaryCopyMethod = getCopyMethod();
|
|
288
|
+
return primaryCopyMethod;
|
|
289
|
+
};
|
|
256
290
|
|
|
257
|
-
export async function copyToPrimary(text: string): Promise<void> {
|
|
258
|
-
await getPrimaryCopyMethod()(text)
|
|
259
|
-
}
|
|
291
|
+
export const copyToPrimary = async function copyToPrimary(text: string): Promise<void> {
|
|
292
|
+
await getPrimaryCopyMethod()(text);
|
|
293
|
+
};
|
package/src/index.ts
CHANGED