@teddyzhu/clipboard 0.0.2
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/LICENSE +21 -0
- package/README.md +35 -0
- package/index.d.ts +110 -0
- package/index.js +404 -0
- package/package.json +111 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 N-API for Rust
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# `@teddyzhu/clipboard`
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
> it's a node package with napi-rs wrapper clipboard-rs
|
|
6
|
+
|
|
7
|
+
# Usage
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @teddyzhu/clipboard
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
const { ClipboardManager } = require('@teddyzhu/clipboard')
|
|
15
|
+
|
|
16
|
+
const clipboard = new ClipboardManager()
|
|
17
|
+
|
|
18
|
+
clipboard.setText('Hello World!')
|
|
19
|
+
console.log(clipboard.getText())
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
listen
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
const { ClipboardListener } = require('@teddyzhu/clipboard')
|
|
26
|
+
|
|
27
|
+
const listener = new ClipboardListener()
|
|
28
|
+
|
|
29
|
+
listener.watch((text) => {
|
|
30
|
+
console.log('剪贴板内容变化:', text)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// stop listen
|
|
34
|
+
listener.stop()
|
|
35
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* 剪贴板监听器实例,用于监听剪贴板变化并支持停止
|
|
5
|
+
* 使用方法:
|
|
6
|
+
* ```javascript
|
|
7
|
+
* const { ClipboardListener } = require('./index.node');
|
|
8
|
+
* const listener = new ClipboardListener();
|
|
9
|
+
* listener.watch((data) => {
|
|
10
|
+
* console.log('剪贴板数据变化:', data);
|
|
11
|
+
* console.log('可用格式:', data.available_formats);
|
|
12
|
+
* if (data.text) console.log('文本:', data.text);
|
|
13
|
+
* if (data.html) console.log('HTML:', data.html);
|
|
14
|
+
* if (data.rtf) console.log('RTF:', data.rtf);
|
|
15
|
+
* if (data.image) console.log('图片 (base64):', data.image.substring(0, 50) + '...');
|
|
16
|
+
* if (data.files) console.log('文件:', data.files);
|
|
17
|
+
* if (data.other) console.log('其他格式:', data.other);
|
|
18
|
+
* });
|
|
19
|
+
* // 停止监听
|
|
20
|
+
* listener.stop();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class ClipboardListener {
|
|
24
|
+
/** 创建新的剪贴板监听器实例 */
|
|
25
|
+
constructor()
|
|
26
|
+
/**
|
|
27
|
+
* 开始监听剪贴板变化
|
|
28
|
+
* callback: 当剪贴板变化时调用的回调函数,参数为包含所有格式数据的复杂对象
|
|
29
|
+
*/
|
|
30
|
+
watch(callback: (arg: ClipboardData) => void): void
|
|
31
|
+
/** 停止监听剪贴板变化 */
|
|
32
|
+
stop(): void
|
|
33
|
+
/** 检查是否正在监听 */
|
|
34
|
+
isWatching(): boolean
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 剪贴板管理器,提供跨平台的剪贴板操作功能 */
|
|
38
|
+
export declare class ClipboardManager {
|
|
39
|
+
/** 创建新的剪贴板管理器实例 */
|
|
40
|
+
constructor()
|
|
41
|
+
/** 获取剪贴板中的纯文本内容 */
|
|
42
|
+
getText(): string
|
|
43
|
+
/** 设置剪贴板中的纯文本内容 */
|
|
44
|
+
setText(text: string): void
|
|
45
|
+
/** 获取剪贴板中的 HTML 内容 */
|
|
46
|
+
getHtml(): string
|
|
47
|
+
/** 设置剪贴板中的 HTML 内容 */
|
|
48
|
+
setHtml(html: string): void
|
|
49
|
+
/** 获取剪贴板中的富文本内容 */
|
|
50
|
+
getRichText(): string
|
|
51
|
+
/** 设置剪贴板中的富文本内容 */
|
|
52
|
+
setRichText(text: string): void
|
|
53
|
+
/** 获取剪贴板中的图片数据(以 base64 编码返回) */
|
|
54
|
+
getImageBase64(): string
|
|
55
|
+
/** 从 base64 编码的图片数据设置剪贴板图片 */
|
|
56
|
+
setImageBase64(base64Data: string): void
|
|
57
|
+
/** 获取剪贴板中的文件列表 */
|
|
58
|
+
getFiles(): Array<string>
|
|
59
|
+
/** 设置剪贴板中的文件列表 */
|
|
60
|
+
setFiles(files: Array<string>): void
|
|
61
|
+
/** 检查剪贴板是否包含指定格式的内容 */
|
|
62
|
+
hasFormat(format: string): boolean
|
|
63
|
+
/** 获取剪贴板中所有可用的格式 */
|
|
64
|
+
getAvailableFormats(): Array<string>
|
|
65
|
+
/** 清空剪贴板 */
|
|
66
|
+
clear(): void
|
|
67
|
+
/** 异步获取剪贴板文本内容 */
|
|
68
|
+
getTextAsync(): Promise<string>
|
|
69
|
+
/** 异步设置剪贴板文本内容 */
|
|
70
|
+
setTextAsync(text: string): Promise<void>
|
|
71
|
+
/** 异步获取剪贴板图片数据(以 base64 编码返回) */
|
|
72
|
+
getImageBase64Async(): Promise<string>
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** 快速清空剪贴板 */
|
|
76
|
+
export declare function clearClipboard(): void
|
|
77
|
+
|
|
78
|
+
/** 剪贴板数据结构,包含所有可用格式的数据 */
|
|
79
|
+
export interface ClipboardData {
|
|
80
|
+
/** 可用的格式列表 */
|
|
81
|
+
availableFormats: Array<string>
|
|
82
|
+
/** 纯文本内容 */
|
|
83
|
+
text?: string
|
|
84
|
+
/** RTF 富文本内容 */
|
|
85
|
+
rtf?: string
|
|
86
|
+
/** HTML 内容 */
|
|
87
|
+
html?: string
|
|
88
|
+
/** 图片数据(base64 编码) */
|
|
89
|
+
image?: string
|
|
90
|
+
/** 文件列表 */
|
|
91
|
+
files?: Array<string>
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 快速获取剪贴板 HTML 内容 */
|
|
95
|
+
export declare function getClipboardHtml(): string
|
|
96
|
+
|
|
97
|
+
/** 快速获取剪贴板图片(base64 编码) */
|
|
98
|
+
export declare function getClipboardImage(): string
|
|
99
|
+
|
|
100
|
+
/** 快速获取剪贴板文本内容 */
|
|
101
|
+
export declare function getClipboardText(): string
|
|
102
|
+
|
|
103
|
+
/** 快速设置剪贴板 HTML 内容 */
|
|
104
|
+
export declare function setClipboardHtml(html: string): void
|
|
105
|
+
|
|
106
|
+
/** 快速设置剪贴板图片(从 base64 编码) */
|
|
107
|
+
export declare function setClipboardImage(base64Data: string): void
|
|
108
|
+
|
|
109
|
+
/** 快速设置剪贴板文本内容 */
|
|
110
|
+
export declare function setClipboardText(text: string): void
|
package/index.js
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const { createRequire } = require('node:module')
|
|
7
|
+
require = createRequire(__filename)
|
|
8
|
+
|
|
9
|
+
const { readFileSync } = require('node:fs')
|
|
10
|
+
let nativeBinding = null
|
|
11
|
+
const loadErrors = []
|
|
12
|
+
|
|
13
|
+
const isMusl = () => {
|
|
14
|
+
let musl = false
|
|
15
|
+
if (process.platform === 'linux') {
|
|
16
|
+
musl = isMuslFromFilesystem()
|
|
17
|
+
if (musl === null) {
|
|
18
|
+
musl = isMuslFromReport()
|
|
19
|
+
}
|
|
20
|
+
if (musl === null) {
|
|
21
|
+
musl = isMuslFromChildProcess()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return musl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
28
|
+
|
|
29
|
+
const isMuslFromFilesystem = () => {
|
|
30
|
+
try {
|
|
31
|
+
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
32
|
+
} catch {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isMuslFromReport = () => {
|
|
38
|
+
let report = null
|
|
39
|
+
if (typeof process.report?.getReport === 'function') {
|
|
40
|
+
process.report.excludeNetwork = true
|
|
41
|
+
report = process.report.getReport()
|
|
42
|
+
}
|
|
43
|
+
if (!report) {
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
50
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
51
|
+
return true
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const isMuslFromChildProcess = () => {
|
|
58
|
+
try {
|
|
59
|
+
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function requireNative() {
|
|
67
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
68
|
+
try {
|
|
69
|
+
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
loadErrors.push(err)
|
|
72
|
+
}
|
|
73
|
+
} else if (process.platform === 'android') {
|
|
74
|
+
if (process.arch === 'arm64') {
|
|
75
|
+
try {
|
|
76
|
+
return require('./clipboard.android-arm64.node')
|
|
77
|
+
} catch (e) {
|
|
78
|
+
loadErrors.push(e)
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return require('@teddyzhu/clipboard-android-arm64')
|
|
82
|
+
} catch (e) {
|
|
83
|
+
loadErrors.push(e)
|
|
84
|
+
}
|
|
85
|
+
} else if (process.arch === 'arm') {
|
|
86
|
+
try {
|
|
87
|
+
return require('./clipboard.android-arm-eabi.node')
|
|
88
|
+
} catch (e) {
|
|
89
|
+
loadErrors.push(e)
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
return require('@teddyzhu/clipboard-android-arm-eabi')
|
|
93
|
+
} catch (e) {
|
|
94
|
+
loadErrors.push(e)
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
98
|
+
}
|
|
99
|
+
} else if (process.platform === 'win32') {
|
|
100
|
+
if (process.arch === 'x64') {
|
|
101
|
+
try {
|
|
102
|
+
return require('./clipboard.win32-x64-msvc.node')
|
|
103
|
+
} catch (e) {
|
|
104
|
+
loadErrors.push(e)
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
return require('@teddyzhu/clipboard-win32-x64-msvc')
|
|
108
|
+
} catch (e) {
|
|
109
|
+
loadErrors.push(e)
|
|
110
|
+
}
|
|
111
|
+
} else if (process.arch === 'ia32') {
|
|
112
|
+
try {
|
|
113
|
+
return require('./clipboard.win32-ia32-msvc.node')
|
|
114
|
+
} catch (e) {
|
|
115
|
+
loadErrors.push(e)
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return require('@teddyzhu/clipboard-win32-ia32-msvc')
|
|
119
|
+
} catch (e) {
|
|
120
|
+
loadErrors.push(e)
|
|
121
|
+
}
|
|
122
|
+
} else if (process.arch === 'arm64') {
|
|
123
|
+
try {
|
|
124
|
+
return require('./clipboard.win32-arm64-msvc.node')
|
|
125
|
+
} catch (e) {
|
|
126
|
+
loadErrors.push(e)
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
return require('@teddyzhu/clipboard-win32-arm64-msvc')
|
|
130
|
+
} catch (e) {
|
|
131
|
+
loadErrors.push(e)
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
135
|
+
}
|
|
136
|
+
} else if (process.platform === 'darwin') {
|
|
137
|
+
try {
|
|
138
|
+
return require('./clipboard.darwin-universal.node')
|
|
139
|
+
} catch (e) {
|
|
140
|
+
loadErrors.push(e)
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
return require('@teddyzhu/clipboard-darwin-universal')
|
|
144
|
+
} catch (e) {
|
|
145
|
+
loadErrors.push(e)
|
|
146
|
+
}
|
|
147
|
+
if (process.arch === 'x64') {
|
|
148
|
+
try {
|
|
149
|
+
return require('./clipboard.darwin-x64.node')
|
|
150
|
+
} catch (e) {
|
|
151
|
+
loadErrors.push(e)
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
return require('@teddyzhu/clipboard-darwin-x64')
|
|
155
|
+
} catch (e) {
|
|
156
|
+
loadErrors.push(e)
|
|
157
|
+
}
|
|
158
|
+
} else if (process.arch === 'arm64') {
|
|
159
|
+
try {
|
|
160
|
+
return require('./clipboard.darwin-arm64.node')
|
|
161
|
+
} catch (e) {
|
|
162
|
+
loadErrors.push(e)
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
return require('@teddyzhu/clipboard-darwin-arm64')
|
|
166
|
+
} catch (e) {
|
|
167
|
+
loadErrors.push(e)
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
171
|
+
}
|
|
172
|
+
} else if (process.platform === 'freebsd') {
|
|
173
|
+
if (process.arch === 'x64') {
|
|
174
|
+
try {
|
|
175
|
+
return require('./clipboard.freebsd-x64.node')
|
|
176
|
+
} catch (e) {
|
|
177
|
+
loadErrors.push(e)
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
return require('@teddyzhu/clipboard-freebsd-x64')
|
|
181
|
+
} catch (e) {
|
|
182
|
+
loadErrors.push(e)
|
|
183
|
+
}
|
|
184
|
+
} else if (process.arch === 'arm64') {
|
|
185
|
+
try {
|
|
186
|
+
return require('./clipboard.freebsd-arm64.node')
|
|
187
|
+
} catch (e) {
|
|
188
|
+
loadErrors.push(e)
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
return require('@teddyzhu/clipboard-freebsd-arm64')
|
|
192
|
+
} catch (e) {
|
|
193
|
+
loadErrors.push(e)
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
197
|
+
}
|
|
198
|
+
} else if (process.platform === 'linux') {
|
|
199
|
+
if (process.arch === 'x64') {
|
|
200
|
+
if (isMusl()) {
|
|
201
|
+
try {
|
|
202
|
+
return require('./clipboard.linux-x64-musl.node')
|
|
203
|
+
} catch (e) {
|
|
204
|
+
loadErrors.push(e)
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
return require('@teddyzhu/clipboard-linux-x64-musl')
|
|
208
|
+
} catch (e) {
|
|
209
|
+
loadErrors.push(e)
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
try {
|
|
213
|
+
return require('./clipboard.linux-x64-gnu.node')
|
|
214
|
+
} catch (e) {
|
|
215
|
+
loadErrors.push(e)
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
return require('@teddyzhu/clipboard-linux-x64-gnu')
|
|
219
|
+
} catch (e) {
|
|
220
|
+
loadErrors.push(e)
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
} else if (process.arch === 'arm64') {
|
|
224
|
+
if (isMusl()) {
|
|
225
|
+
try {
|
|
226
|
+
return require('./clipboard.linux-arm64-musl.node')
|
|
227
|
+
} catch (e) {
|
|
228
|
+
loadErrors.push(e)
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
return require('@teddyzhu/clipboard-linux-arm64-musl')
|
|
232
|
+
} catch (e) {
|
|
233
|
+
loadErrors.push(e)
|
|
234
|
+
}
|
|
235
|
+
} else {
|
|
236
|
+
try {
|
|
237
|
+
return require('./clipboard.linux-arm64-gnu.node')
|
|
238
|
+
} catch (e) {
|
|
239
|
+
loadErrors.push(e)
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
return require('@teddyzhu/clipboard-linux-arm64-gnu')
|
|
243
|
+
} catch (e) {
|
|
244
|
+
loadErrors.push(e)
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} else if (process.arch === 'arm') {
|
|
248
|
+
if (isMusl()) {
|
|
249
|
+
try {
|
|
250
|
+
return require('./clipboard.linux-arm-musleabihf.node')
|
|
251
|
+
} catch (e) {
|
|
252
|
+
loadErrors.push(e)
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
return require('@teddyzhu/clipboard-linux-arm-musleabihf')
|
|
256
|
+
} catch (e) {
|
|
257
|
+
loadErrors.push(e)
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
try {
|
|
261
|
+
return require('./clipboard.linux-arm-gnueabihf.node')
|
|
262
|
+
} catch (e) {
|
|
263
|
+
loadErrors.push(e)
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
return require('@teddyzhu/clipboard-linux-arm-gnueabihf')
|
|
267
|
+
} catch (e) {
|
|
268
|
+
loadErrors.push(e)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
} else if (process.arch === 'riscv64') {
|
|
272
|
+
if (isMusl()) {
|
|
273
|
+
try {
|
|
274
|
+
return require('./clipboard.linux-riscv64-musl.node')
|
|
275
|
+
} catch (e) {
|
|
276
|
+
loadErrors.push(e)
|
|
277
|
+
}
|
|
278
|
+
try {
|
|
279
|
+
return require('@teddyzhu/clipboard-linux-riscv64-musl')
|
|
280
|
+
} catch (e) {
|
|
281
|
+
loadErrors.push(e)
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
try {
|
|
285
|
+
return require('./clipboard.linux-riscv64-gnu.node')
|
|
286
|
+
} catch (e) {
|
|
287
|
+
loadErrors.push(e)
|
|
288
|
+
}
|
|
289
|
+
try {
|
|
290
|
+
return require('@teddyzhu/clipboard-linux-riscv64-gnu')
|
|
291
|
+
} catch (e) {
|
|
292
|
+
loadErrors.push(e)
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
} else if (process.arch === 'ppc64') {
|
|
296
|
+
try {
|
|
297
|
+
return require('./clipboard.linux-ppc64-gnu.node')
|
|
298
|
+
} catch (e) {
|
|
299
|
+
loadErrors.push(e)
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
return require('@teddyzhu/clipboard-linux-ppc64-gnu')
|
|
303
|
+
} catch (e) {
|
|
304
|
+
loadErrors.push(e)
|
|
305
|
+
}
|
|
306
|
+
} else if (process.arch === 's390x') {
|
|
307
|
+
try {
|
|
308
|
+
return require('./clipboard.linux-s390x-gnu.node')
|
|
309
|
+
} catch (e) {
|
|
310
|
+
loadErrors.push(e)
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
return require('@teddyzhu/clipboard-linux-s390x-gnu')
|
|
314
|
+
} catch (e) {
|
|
315
|
+
loadErrors.push(e)
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
319
|
+
}
|
|
320
|
+
} else if (process.platform === 'openharmony') {
|
|
321
|
+
if (process.arch === 'arm64') {
|
|
322
|
+
try {
|
|
323
|
+
return require('./clipboard.linux-arm64-ohos.node')
|
|
324
|
+
} catch (e) {
|
|
325
|
+
loadErrors.push(e)
|
|
326
|
+
}
|
|
327
|
+
try {
|
|
328
|
+
return require('@teddyzhu/clipboard-linux-arm64-ohos')
|
|
329
|
+
} catch (e) {
|
|
330
|
+
loadErrors.push(e)
|
|
331
|
+
}
|
|
332
|
+
} else if (process.arch === 'x64') {
|
|
333
|
+
try {
|
|
334
|
+
return require('./clipboard.linux-x64-ohos.node')
|
|
335
|
+
} catch (e) {
|
|
336
|
+
loadErrors.push(e)
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
return require('@teddyzhu/clipboard-linux-x64-ohos')
|
|
340
|
+
} catch (e) {
|
|
341
|
+
loadErrors.push(e)
|
|
342
|
+
}
|
|
343
|
+
} else if (process.arch === 'arm') {
|
|
344
|
+
try {
|
|
345
|
+
return require('./clipboard.linux-arm-ohos.node')
|
|
346
|
+
} catch (e) {
|
|
347
|
+
loadErrors.push(e)
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
return require('@teddyzhu/clipboard-linux-arm-ohos')
|
|
351
|
+
} catch (e) {
|
|
352
|
+
loadErrors.push(e)
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
356
|
+
}
|
|
357
|
+
} else {
|
|
358
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
nativeBinding = requireNative()
|
|
363
|
+
|
|
364
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
365
|
+
try {
|
|
366
|
+
nativeBinding = require('./clipboard.wasi.cjs')
|
|
367
|
+
} catch (err) {
|
|
368
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
369
|
+
loadErrors.push(err)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
if (!nativeBinding) {
|
|
373
|
+
try {
|
|
374
|
+
nativeBinding = require('@teddyzhu/clipboard-wasm32-wasi')
|
|
375
|
+
} catch (err) {
|
|
376
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
377
|
+
loadErrors.push(err)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
if (!nativeBinding) {
|
|
384
|
+
if (loadErrors.length > 0) {
|
|
385
|
+
throw new Error(
|
|
386
|
+
`Cannot find native binding. ` +
|
|
387
|
+
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
388
|
+
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
389
|
+
{ cause: loadErrors }
|
|
390
|
+
)
|
|
391
|
+
}
|
|
392
|
+
throw new Error(`Failed to load native binding`)
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
module.exports = nativeBinding
|
|
396
|
+
module.exports.ClipboardListener = nativeBinding.ClipboardListener
|
|
397
|
+
module.exports.ClipboardManager = nativeBinding.ClipboardManager
|
|
398
|
+
module.exports.clearClipboard = nativeBinding.clearClipboard
|
|
399
|
+
module.exports.getClipboardHtml = nativeBinding.getClipboardHtml
|
|
400
|
+
module.exports.getClipboardImage = nativeBinding.getClipboardImage
|
|
401
|
+
module.exports.getClipboardText = nativeBinding.getClipboardText
|
|
402
|
+
module.exports.setClipboardHtml = nativeBinding.setClipboardHtml
|
|
403
|
+
module.exports.setClipboardImage = nativeBinding.setClipboardImage
|
|
404
|
+
module.exports.setClipboardText = nativeBinding.setClipboardText
|
package/package.json
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teddyzhu/clipboard",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "it's a node package with napi-rs wrapper clipboard-rs",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": "git@github.com:Teddy-Zhu/node-clipboard-rs.git",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"napi-rs",
|
|
10
|
+
"NAPI",
|
|
11
|
+
"N-API",
|
|
12
|
+
"Rust",
|
|
13
|
+
"node-addon",
|
|
14
|
+
"node-addon-api"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
"index.d.ts",
|
|
18
|
+
"index.js"
|
|
19
|
+
],
|
|
20
|
+
"napi": {
|
|
21
|
+
"binaryName": "clipboard",
|
|
22
|
+
"targets": [
|
|
23
|
+
"x86_64-pc-windows-msvc",
|
|
24
|
+
"x86_64-apple-darwin",
|
|
25
|
+
"x86_64-unknown-linux-gnu",
|
|
26
|
+
"aarch64-unknown-linux-gnu",
|
|
27
|
+
"aarch64-apple-darwin",
|
|
28
|
+
"aarch64-pc-windows-msvc"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">= 10.16.0 < 11 || >= 11.8.0 < 12 || >= 12.0.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org/",
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"artifacts": "napi artifacts",
|
|
40
|
+
"bench": "node --import @oxc-node/core/register benchmark/bench.ts",
|
|
41
|
+
"build": "napi build --platform --release",
|
|
42
|
+
"build:debug": "napi build --platform",
|
|
43
|
+
"format": "run-p format:prettier format:rs format:toml",
|
|
44
|
+
"format:prettier": "prettier . -w",
|
|
45
|
+
"format:toml": "taplo format",
|
|
46
|
+
"format:rs": "cargo fmt",
|
|
47
|
+
"lint": "oxlint .",
|
|
48
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
49
|
+
"test": "ava",
|
|
50
|
+
"version": "napi version",
|
|
51
|
+
"prepare": "husky"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@emnapi/core": "^1.4.3",
|
|
55
|
+
"@emnapi/runtime": "^1.4.3",
|
|
56
|
+
"@napi-rs/cli": "^3.0.0",
|
|
57
|
+
"@oxc-node/core": "^0.0.29",
|
|
58
|
+
"@taplo/cli": "^0.7.0",
|
|
59
|
+
"@tybys/wasm-util": "^0.10.0",
|
|
60
|
+
"ava": "^6.4.0",
|
|
61
|
+
"chalk": "^5.4.1",
|
|
62
|
+
"husky": "^9.1.7",
|
|
63
|
+
"lint-staged": "^16.1.2",
|
|
64
|
+
"npm-run-all2": "^8.0.4",
|
|
65
|
+
"oxlint": "^1.3.0",
|
|
66
|
+
"prettier": "^3.6.0",
|
|
67
|
+
"tinybench": "^4.0.1",
|
|
68
|
+
"typescript": "^5.8.3"
|
|
69
|
+
},
|
|
70
|
+
"lint-staged": {
|
|
71
|
+
"*.@(js|ts|tsx)": [
|
|
72
|
+
"oxlint --fix"
|
|
73
|
+
],
|
|
74
|
+
"*.@(js|ts|tsx|yml|yaml|md|json)": [
|
|
75
|
+
"prettier --write"
|
|
76
|
+
],
|
|
77
|
+
"*.toml": [
|
|
78
|
+
"taplo format"
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
"ava": {
|
|
82
|
+
"extensions": {
|
|
83
|
+
"ts": "module"
|
|
84
|
+
},
|
|
85
|
+
"timeout": "2m",
|
|
86
|
+
"workerThreads": false,
|
|
87
|
+
"environmentVariables": {
|
|
88
|
+
"OXC_TSCONFIG_PATH": "./__test__/tsconfig.json"
|
|
89
|
+
},
|
|
90
|
+
"nodeArguments": [
|
|
91
|
+
"--import",
|
|
92
|
+
"@oxc-node/core/register"
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
"prettier": {
|
|
96
|
+
"printWidth": 120,
|
|
97
|
+
"semi": false,
|
|
98
|
+
"trailingComma": "all",
|
|
99
|
+
"singleQuote": true,
|
|
100
|
+
"arrowParens": "always"
|
|
101
|
+
},
|
|
102
|
+
"packageManager": "yarn@4.9.2",
|
|
103
|
+
"optionalDependencies": {
|
|
104
|
+
"@teddyzhu/clipboard-win32-x64-msvc": "0.0.2",
|
|
105
|
+
"@teddyzhu/clipboard-darwin-x64": "0.0.2",
|
|
106
|
+
"@teddyzhu/clipboard-linux-x64-gnu": "0.0.2",
|
|
107
|
+
"@teddyzhu/clipboard-linux-arm64-gnu": "0.0.2",
|
|
108
|
+
"@teddyzhu/clipboard-darwin-arm64": "0.0.2",
|
|
109
|
+
"@teddyzhu/clipboard-win32-arm64-msvc": "0.0.2"
|
|
110
|
+
}
|
|
111
|
+
}
|