@crosscopy/clipboard 0.2.8 → 0.3.4

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/package.json CHANGED
@@ -1,52 +1,100 @@
1
1
  {
2
2
  "name": "@crosscopy/clipboard",
3
- "version": "0.2.8",
3
+ "version": "0.3.4",
4
+ "description": "Cross-platform clipboard operations for Node.js",
4
5
  "main": "index.js",
5
6
  "types": "index.d.ts",
6
- "napi": {
7
- "name": "clipboard",
8
- "triples": {
9
- "additional": [
10
- "aarch64-apple-darwin",
11
- "aarch64-unknown-linux-gnu",
12
- "aarch64-pc-windows-msvc",
13
- "universal-apple-darwin",
14
- "riscv64gc-unknown-linux-gnu"
15
- ]
16
- }
17
- },
18
- "license": "MIT",
19
7
  "repository": {
20
8
  "type": "git",
21
9
  "url": "https://github.com/CrossCopy/clipboard.git"
22
10
  },
23
- "devDependencies": {
24
- "@napi-rs/cli": "^2.18.0",
25
- "ava": "^6.0.1"
26
- },
27
- "ava": {
28
- "timeout": "3m"
11
+ "license": "MIT",
12
+ "files": [
13
+ "index.d.ts",
14
+ "index.js",
15
+ "*.node"
16
+ ],
17
+ "napi": {
18
+ "binaryName": "clipboard",
19
+ "targets": [
20
+ "x86_64-pc-windows-msvc",
21
+ "x86_64-apple-darwin",
22
+ "x86_64-unknown-linux-gnu",
23
+ "aarch64-apple-darwin"
24
+ ]
29
25
  },
30
26
  "engines": {
31
- "node": ">= 10"
27
+ "node": ">= 10.20.0 < 11 || >= 12.17.0 < 13 || >= 14.0.0"
28
+ },
29
+ "publishConfig": {
30
+ "registry": "https://registry.npmjs.org/",
31
+ "access": "public"
32
32
  },
33
33
  "scripts": {
34
34
  "artifacts": "napi artifacts",
35
35
  "build": "napi build --platform --release",
36
36
  "build:debug": "napi build --platform",
37
+ "format": "run-p format:prettier format:rs format:toml",
38
+ "format:prettier": "prettier . -w",
39
+ "format:toml": "taplo format",
40
+ "format:rs": "cargo fmt",
41
+ "lint": "oxlint .",
37
42
  "prepublishOnly": "napi prepublish -t npm",
43
+ "demo": "OXC_TSCONFIG_PATH=./examples/tsconfig.json node --import @oxc-node/core/register examples/demo.ts",
38
44
  "test": "ava",
39
- "universal": "napi universal",
40
- "version": "napi version"
45
+ "preversion": "napi build --platform && git add .",
46
+ "version": "napi version",
47
+ "prepare": "husky"
48
+ },
49
+ "devDependencies": {
50
+ "@napi-rs/cli": "^3.2.0",
51
+ "@oxc-node/core": "^0.0.35",
52
+ "@taplo/cli": "^0.7.0",
53
+ "ava": "^6.4.1",
54
+ "husky": "^9.1.7",
55
+ "lint-staged": "^16.1.6",
56
+ "npm-run-all2": "^8.0.4",
57
+ "oxlint": "^1.14.0",
58
+ "prettier": "^3.6.2",
59
+ "typescript": "^5.9.2"
60
+ },
61
+ "lint-staged": {
62
+ "*.@(js|ts|tsx)": [
63
+ "oxlint --fix"
64
+ ],
65
+ "*.@(js|ts|tsx|yml|yaml|md|json)": [
66
+ "prettier --write"
67
+ ],
68
+ "*.toml": [
69
+ "taplo format"
70
+ ]
71
+ },
72
+ "ava": {
73
+ "extensions": {
74
+ "ts": "module"
75
+ },
76
+ "timeout": "2m",
77
+ "workerThreads": false,
78
+ "environmentVariables": {
79
+ "OXC_TSCONFIG_PATH": "./__test__/tsconfig.json"
80
+ },
81
+ "nodeArguments": [
82
+ "--import",
83
+ "@oxc-node/core/register"
84
+ ]
85
+ },
86
+ "prettier": {
87
+ "printWidth": 120,
88
+ "semi": false,
89
+ "trailingComma": "all",
90
+ "singleQuote": true,
91
+ "arrowParens": "always"
41
92
  },
93
+ "packageManager": "yarn@4.12.0",
42
94
  "optionalDependencies": {
43
- "@crosscopy/clipboard-win32-x64-msvc": "0.2.8",
44
- "@crosscopy/clipboard-darwin-x64": "0.2.8",
45
- "@crosscopy/clipboard-linux-x64-gnu": "0.2.8",
46
- "@crosscopy/clipboard-darwin-arm64": "0.2.8",
47
- "@crosscopy/clipboard-linux-arm64-gnu": "0.2.8",
48
- "@crosscopy/clipboard-win32-arm64-msvc": "0.2.8",
49
- "@crosscopy/clipboard-darwin-universal": "0.2.8",
50
- "@crosscopy/clipboard-linux-riscv64-gnu": "0.2.8"
95
+ "@crosscopy/clipboard-win32-x64-msvc": "0.3.4",
96
+ "@crosscopy/clipboard-darwin-x64": "0.3.4",
97
+ "@crosscopy/clipboard-linux-x64-gnu": "0.3.4",
98
+ "@crosscopy/clipboard-darwin-arm64": "0.3.4"
51
99
  }
52
100
  }
package/.yarnrc.yml DELETED
@@ -1 +0,0 @@
1
- nodeLinker: node-modules
package/Cargo.toml DELETED
@@ -1,24 +0,0 @@
1
- [package]
2
- edition = "2021"
3
- name = "crosscopy_clipboard"
4
- version = "0.0.0"
5
-
6
- [lib]
7
- crate-type = ["cdylib"]
8
-
9
- [dependencies]
10
- base64 = "0.22.0"
11
- clipboard-rs = "0.1.7"
12
- futures = "0.3.30"
13
- # Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
14
- napi = { version = "2.12.2", default-features = false, features = ["napi4", "tokio_rt"] }
15
- napi-derive = "2.12.2"
16
- tokio = "1.36.0"
17
-
18
- [build-dependencies]
19
- napi-build = "2.0.1"
20
-
21
- [profile.release]
22
- lto = true
23
- strip = "symbols"
24
-
package/build.rs DELETED
@@ -1,5 +0,0 @@
1
- extern crate napi_build;
2
-
3
- fn main() {
4
- napi_build::setup();
5
- }
package/exp.ts DELETED
@@ -1,12 +0,0 @@
1
- import Clipboard from "./index.js";
2
-
3
- console.log(await Clipboard.getText());
4
-
5
- console.log(await Clipboard.getHtml());
6
-
7
-
8
- if (await Clipboard.hasImage()) {
9
- console.log(await Clipboard.getImageBase64());
10
- } else {
11
- console.log("No Image");
12
- }
package/src/lib.rs DELETED
@@ -1,191 +0,0 @@
1
- #![deny(clippy::all)]
2
- use base64::{engine::general_purpose, Engine as _};
3
- use clipboard_rs::{
4
- common::RustImage, Clipboard, ClipboardContext, ClipboardHandler, ClipboardWatcher,
5
- ClipboardWatcherContext, ContentFormat, RustImageData,
6
- };
7
- use napi::{
8
- bindgen_prelude::*,
9
- threadsafe_function::{ErrorStrategy, ThreadsafeFunction, ThreadsafeFunctionCallMode},
10
- JsFunction,
11
- };
12
- use std::{thread, time::Duration};
13
-
14
- #[macro_use]
15
- extern crate napi_derive;
16
-
17
- #[napi]
18
- pub fn available_formats() -> Vec<String> {
19
- let ctx = ClipboardContext::new().unwrap();
20
- let types = ctx.available_formats().unwrap();
21
- types
22
- }
23
-
24
- #[napi]
25
- pub async fn get_text() -> String {
26
- let ctx = ClipboardContext::new().unwrap();
27
- ctx.get_text().unwrap()
28
- }
29
-
30
- #[napi]
31
- pub async fn set_text(text: String) {
32
- let ctx = ClipboardContext::new().unwrap();
33
- ctx.set_text(text).unwrap()
34
- }
35
-
36
- #[napi]
37
- pub fn has_text() -> bool {
38
- let ctx = ClipboardContext::new().unwrap();
39
- ctx.has(ContentFormat::Text)
40
- }
41
-
42
- #[napi]
43
- pub async fn get_image_binary() -> Vec<u8> {
44
- let ctx = ClipboardContext::new().unwrap();
45
- let image = ctx.get_image().unwrap();
46
- let image_bytes = image.to_png().unwrap().get_bytes().to_vec();
47
- image_bytes
48
- }
49
-
50
- #[napi]
51
- pub async fn get_image_base64() -> String {
52
- let image_bytes = get_image_binary().await;
53
- let base64_str = general_purpose::STANDARD_NO_PAD.encode(&image_bytes);
54
- base64_str
55
- }
56
-
57
- #[napi]
58
- pub async fn set_image_binary(image_bytes: Vec<u8>) {
59
- let ctx = ClipboardContext::new().unwrap();
60
- let img = RustImageData::from_bytes(&image_bytes).unwrap();
61
- ctx.set_image(img).unwrap()
62
- }
63
-
64
- #[napi]
65
- pub async fn set_image_base64(base64_str: String) {
66
- let decoded: Vec<u8> = general_purpose::STANDARD_NO_PAD.decode(base64_str).unwrap();
67
- set_image_binary(decoded).await;
68
- }
69
-
70
- #[napi]
71
- pub fn has_image() -> bool {
72
- let ctx = ClipboardContext::new().unwrap();
73
- ctx.has(ContentFormat::Image)
74
- }
75
-
76
- #[napi]
77
- pub async fn get_html() -> String {
78
- let ctx = ClipboardContext::new().unwrap();
79
- ctx.get_html().unwrap()
80
- }
81
-
82
- #[napi]
83
- pub async fn set_html(html: String) {
84
- let ctx = ClipboardContext::new().unwrap();
85
- ctx.set_html(html).unwrap()
86
- }
87
-
88
- #[napi]
89
- fn has_html() -> bool {
90
- let ctx = ClipboardContext::new().unwrap();
91
- ctx.has(ContentFormat::Html)
92
- }
93
-
94
- #[napi]
95
- pub async fn get_rtf() -> String {
96
- let ctx = ClipboardContext::new().unwrap();
97
- ctx.get_rich_text().unwrap()
98
- }
99
-
100
- #[napi]
101
- pub async fn set_rtf(rtf: String) {
102
- let ctx = ClipboardContext::new().unwrap();
103
- ctx.set_rich_text(rtf).unwrap()
104
- }
105
-
106
- #[napi]
107
- pub fn has_rtf() -> bool {
108
- let ctx = ClipboardContext::new().unwrap();
109
- ctx.has(ContentFormat::Rtf)
110
- }
111
-
112
- #[napi]
113
- pub async fn clear() {
114
- let ctx = ClipboardContext::new().unwrap();
115
- ctx.clear().unwrap()
116
- }
117
-
118
- struct Manager {
119
- ctx: ClipboardContext,
120
- }
121
-
122
- impl Manager {
123
- pub fn new() -> Self {
124
- let ctx = ClipboardContext::new().unwrap();
125
- Manager { ctx }
126
- }
127
- }
128
-
129
- impl ClipboardHandler for Manager {
130
- fn on_clipboard_change(&mut self) {
131
- println!(
132
- "on_clipboard_change, txt = {}",
133
- self.ctx.get_text().unwrap()
134
- );
135
- }
136
- }
137
-
138
- #[napi]
139
- pub fn watch() {
140
- let manager = Manager::new();
141
-
142
- let mut watcher = ClipboardWatcherContext::new().unwrap();
143
-
144
- let watcher_shutdown = watcher.add_handler(manager).get_shutdown_channel();
145
-
146
- thread::spawn(move || {
147
- thread::sleep(Duration::from_secs(5));
148
- println!("stop watch!");
149
- watcher_shutdown.stop();
150
- });
151
-
152
- println!("start watch!");
153
- watcher.start_watch();
154
- }
155
-
156
- #[napi]
157
- pub fn call_threadsafe_function(callback: JsFunction) -> Result<()> {
158
- let tsfn: ThreadsafeFunction<u32, ErrorStrategy::CalleeHandled> = callback
159
- .create_threadsafe_function(0, |ctx| {
160
- ctx.env.create_uint32(ctx.value + 1).map(|v| vec![v])
161
- })?;
162
- for n in 0..10 {
163
- let tsfn = tsfn.clone();
164
- thread::spawn(move || {
165
- tsfn.call(Ok(n), ThreadsafeFunctionCallMode::Blocking);
166
- });
167
- }
168
- Ok(())
169
- }
170
-
171
- // #[js_function(1)]
172
- // fn hello(ctx: CallContext) -> Result<JsString, String> {
173
- // let argument_one = ctx
174
- // .get::<JsString>(0)
175
- // .map_err(|err| err.to_string())?
176
- // .into_utf8()
177
- // .map_err(|err| err.to_string())?;
178
- // ctx
179
- // .env
180
- // .create_string_from_std(format!("{} world!", argument_one.as_str()?))
181
- // }
182
-
183
- #[cfg(test)]
184
- mod tests {
185
- use super::*;
186
-
187
- #[test]
188
- fn it_works() {
189
- watch();
190
- }
191
- }