@teddyzhu/clipboard 0.0.2 → 0.0.3

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/README.md CHANGED
@@ -26,10 +26,51 @@ const { ClipboardListener } = require('@teddyzhu/clipboard')
26
26
 
27
27
  const listener = new ClipboardListener()
28
28
 
29
- listener.watch((text) => {
30
- console.log('剪贴板内容变化:', text)
29
+ listener.watch((data) => {
30
+ console.log('剪贴板数据变化:', data)
31
+ console.log('可用格式:', data.availableFormats)
32
+
33
+ if (data.text) {
34
+ console.log('文本:', data.text)
35
+ }
36
+
37
+ if (data.image) {
38
+ console.log('图片信息:')
39
+ console.log(' 尺寸:', data.image.width + 'x' + data.image.height + 'px')
40
+ console.log(' 大小:', data.image.size + ' bytes')
41
+ console.log(' Base64 数据长度:', data.image.base64Data.length + ' 字符')
42
+ }
43
+
44
+ if (data.files) {
45
+ console.log('文件:', data.files)
46
+ }
31
47
  })
32
48
 
33
49
  // stop listen
34
50
  listener.stop()
35
51
  ```
52
+
53
+ ## 图片功能增强
54
+
55
+ 现在图片字段包含详细信息:
56
+
57
+ ```javascript
58
+ const { ClipboardManager, getClipboardImageData } = require('@teddyzhu/clipboard')
59
+
60
+ const clipboard = new ClipboardManager()
61
+
62
+ // 获取图片详细信息
63
+ if (clipboard.hasFormat('image')) {
64
+ const imageData = clipboard.getImageData()
65
+ console.log('图片宽度:', imageData.width + 'px')
66
+ console.log('图片高度:', imageData.height + 'px')
67
+ console.log('图片大小:', imageData.size + ' bytes')
68
+ console.log('Base64 数据:', imageData.base64Data)
69
+ }
70
+
71
+ // 异步获取图片数据
72
+ const imageDataAsync = await clipboard.getImageDataAsync()
73
+
74
+ // 快速获取图片数据
75
+ const quickImageData = getClipboardImageData()
76
+ ```
package/index.d.ts CHANGED
@@ -52,6 +52,8 @@ export declare class ClipboardManager {
52
52
  setRichText(text: string): void
53
53
  /** 获取剪贴板中的图片数据(以 base64 编码返回) */
54
54
  getImageBase64(): string
55
+ /** 获取剪贴板中的图片详细信息(包含宽度、高度、大小和 base64 数据) */
56
+ getImageData(): ImageData
55
57
  /** 从 base64 编码的图片数据设置剪贴板图片 */
56
58
  setImageBase64(base64Data: string): void
57
59
  /** 获取剪贴板中的文件列表 */
@@ -70,6 +72,8 @@ export declare class ClipboardManager {
70
72
  setTextAsync(text: string): Promise<void>
71
73
  /** 异步获取剪贴板图片数据(以 base64 编码返回) */
72
74
  getImageBase64Async(): Promise<string>
75
+ /** 异步获取剪贴板图片详细信息(包含宽度、高度、大小和 base64 数据) */
76
+ getImageDataAsync(): Promise<ImageData>
73
77
  }
74
78
 
75
79
  /** 快速清空剪贴板 */
@@ -85,8 +89,8 @@ export interface ClipboardData {
85
89
  rtf?: string
86
90
  /** HTML 内容 */
87
91
  html?: string
88
- /** 图片数据(base64 编码) */
89
- image?: string
92
+ /** 图片数据 */
93
+ image?: ImageData
90
94
  /** 文件列表 */
91
95
  files?: Array<string>
92
96
  }
@@ -97,9 +101,24 @@ export declare function getClipboardHtml(): string
97
101
  /** 快速获取剪贴板图片(base64 编码) */
98
102
  export declare function getClipboardImage(): string
99
103
 
104
+ /** 快速获取剪贴板图片详细信息(包含宽度、高度、大小和 base64 数据) */
105
+ export declare function getClipboardImageData(): ImageData
106
+
100
107
  /** 快速获取剪贴板文本内容 */
101
108
  export declare function getClipboardText(): string
102
109
 
110
+ /** 图片数据结构,包含图片的详细信息 */
111
+ export interface ImageData {
112
+ /** 图片宽度(像素) */
113
+ width: number
114
+ /** 图片高度(像素) */
115
+ height: number
116
+ /** 图片数据大小(字节) */
117
+ size: number
118
+ /** 图片数据(base64 编码) */
119
+ base64Data: string
120
+ }
121
+
103
122
  /** 快速设置剪贴板 HTML 内容 */
104
123
  export declare function setClipboardHtml(html: string): void
105
124
 
package/index.js CHANGED
@@ -398,6 +398,7 @@ module.exports.ClipboardManager = nativeBinding.ClipboardManager
398
398
  module.exports.clearClipboard = nativeBinding.clearClipboard
399
399
  module.exports.getClipboardHtml = nativeBinding.getClipboardHtml
400
400
  module.exports.getClipboardImage = nativeBinding.getClipboardImage
401
+ module.exports.getClipboardImageData = nativeBinding.getClipboardImageData
401
402
  module.exports.getClipboardText = nativeBinding.getClipboardText
402
403
  module.exports.setClipboardHtml = nativeBinding.setClipboardHtml
403
404
  module.exports.setClipboardImage = nativeBinding.setClipboardImage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teddyzhu/clipboard",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "it's a node package with napi-rs wrapper clipboard-rs",
5
5
  "main": "index.js",
6
6
  "repository": "git@github.com:Teddy-Zhu/node-clipboard-rs.git",
@@ -101,11 +101,11 @@
101
101
  },
102
102
  "packageManager": "yarn@4.9.2",
103
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"
104
+ "@teddyzhu/clipboard-win32-x64-msvc": "0.0.3",
105
+ "@teddyzhu/clipboard-darwin-x64": "0.0.3",
106
+ "@teddyzhu/clipboard-linux-x64-gnu": "0.0.3",
107
+ "@teddyzhu/clipboard-linux-arm64-gnu": "0.0.3",
108
+ "@teddyzhu/clipboard-darwin-arm64": "0.0.3",
109
+ "@teddyzhu/clipboard-win32-arm64-msvc": "0.0.3"
110
110
  }
111
111
  }