simen-keyboard-listener 1.1.2 → 1.1.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/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +26 -2
- package/dist/index.mjs +23 -1
- package/package.json +6 -5
package/dist/index.d.mts
CHANGED
|
@@ -37,5 +37,17 @@ declare function createGlobalKeyboardListener(): IGlobalKeyboardListener;
|
|
|
37
37
|
declare function checkKeyboardPermission(): boolean;
|
|
38
38
|
declare function getFocusedInputValue(): string | null;
|
|
39
39
|
declare function getFocusedInputSelectedText(): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* 获取完整上下文信息(JSON 格式)
|
|
42
|
+
* 包含:应用信息、焦点元素、选中文本、DOM 信息等
|
|
43
|
+
* @returns JSON 字符串或 null
|
|
44
|
+
*/
|
|
45
|
+
declare function getContextJSON(): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* 智能获取选中文本
|
|
48
|
+
* 优先用 Accessibility API,失败则用模拟 Cmd+C(支持微信等)
|
|
49
|
+
* @returns 选中文本或 null
|
|
50
|
+
*/
|
|
51
|
+
declare function getSelectedTextSmart(): string | null;
|
|
40
52
|
|
|
41
|
-
export { type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPermissionLostListener, checkKeyboardPermission, createGlobalKeyboardListener, getFocusedInputSelectedText, getFocusedInputValue, getGlobalKeyboardListener };
|
|
53
|
+
export { type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPermissionLostListener, checkKeyboardPermission, createGlobalKeyboardListener, getContextJSON, getFocusedInputSelectedText, getFocusedInputValue, getGlobalKeyboardListener, getSelectedTextSmart };
|
package/dist/index.d.ts
CHANGED
|
@@ -37,5 +37,17 @@ declare function createGlobalKeyboardListener(): IGlobalKeyboardListener;
|
|
|
37
37
|
declare function checkKeyboardPermission(): boolean;
|
|
38
38
|
declare function getFocusedInputValue(): string | null;
|
|
39
39
|
declare function getFocusedInputSelectedText(): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* 获取完整上下文信息(JSON 格式)
|
|
42
|
+
* 包含:应用信息、焦点元素、选中文本、DOM 信息等
|
|
43
|
+
* @returns JSON 字符串或 null
|
|
44
|
+
*/
|
|
45
|
+
declare function getContextJSON(): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* 智能获取选中文本
|
|
48
|
+
* 优先用 Accessibility API,失败则用模拟 Cmd+C(支持微信等)
|
|
49
|
+
* @returns 选中文本或 null
|
|
50
|
+
*/
|
|
51
|
+
declare function getSelectedTextSmart(): string | null;
|
|
40
52
|
|
|
41
|
-
export { type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPermissionLostListener, checkKeyboardPermission, createGlobalKeyboardListener, getFocusedInputSelectedText, getFocusedInputValue, getGlobalKeyboardListener };
|
|
53
|
+
export { type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPermissionLostListener, checkKeyboardPermission, createGlobalKeyboardListener, getContextJSON, getFocusedInputSelectedText, getFocusedInputValue, getGlobalKeyboardListener, getSelectedTextSmart };
|
package/dist/index.js
CHANGED
|
@@ -32,9 +32,11 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
checkKeyboardPermission: () => checkKeyboardPermission,
|
|
34
34
|
createGlobalKeyboardListener: () => createGlobalKeyboardListener,
|
|
35
|
+
getContextJSON: () => getContextJSON,
|
|
35
36
|
getFocusedInputSelectedText: () => getFocusedInputSelectedText,
|
|
36
37
|
getFocusedInputValue: () => getFocusedInputValue,
|
|
37
|
-
getGlobalKeyboardListener: () => getGlobalKeyboardListener
|
|
38
|
+
getGlobalKeyboardListener: () => getGlobalKeyboardListener,
|
|
39
|
+
getSelectedTextSmart: () => getSelectedTextSmart
|
|
38
40
|
});
|
|
39
41
|
module.exports = __toCommonJS(index_exports);
|
|
40
42
|
var path = __toESM(require("path"));
|
|
@@ -267,11 +269,33 @@ function getFocusedInputSelectedText() {
|
|
|
267
269
|
return null;
|
|
268
270
|
}
|
|
269
271
|
}
|
|
272
|
+
function getContextJSON() {
|
|
273
|
+
if (process.platform !== "darwin") return null;
|
|
274
|
+
const addon = getNativeAddon();
|
|
275
|
+
if (!ensureAccessibilityPermission(addon)) return null;
|
|
276
|
+
try {
|
|
277
|
+
return addon.getContextJSON?.() ?? null;
|
|
278
|
+
} catch {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function getSelectedTextSmart() {
|
|
283
|
+
if (process.platform !== "darwin") return null;
|
|
284
|
+
const addon = getNativeAddon();
|
|
285
|
+
if (!ensureAccessibilityPermission(addon)) return null;
|
|
286
|
+
try {
|
|
287
|
+
return addon.getSelectedTextSmart?.() ?? null;
|
|
288
|
+
} catch {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
270
292
|
// Annotate the CommonJS export names for ESM import in node:
|
|
271
293
|
0 && (module.exports = {
|
|
272
294
|
checkKeyboardPermission,
|
|
273
295
|
createGlobalKeyboardListener,
|
|
296
|
+
getContextJSON,
|
|
274
297
|
getFocusedInputSelectedText,
|
|
275
298
|
getFocusedInputValue,
|
|
276
|
-
getGlobalKeyboardListener
|
|
299
|
+
getGlobalKeyboardListener,
|
|
300
|
+
getSelectedTextSmart
|
|
277
301
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -235,10 +235,32 @@ function getFocusedInputSelectedText() {
|
|
|
235
235
|
return null;
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
+
function getContextJSON() {
|
|
239
|
+
if (process.platform !== "darwin") return null;
|
|
240
|
+
const addon = getNativeAddon();
|
|
241
|
+
if (!ensureAccessibilityPermission(addon)) return null;
|
|
242
|
+
try {
|
|
243
|
+
return addon.getContextJSON?.() ?? null;
|
|
244
|
+
} catch {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function getSelectedTextSmart() {
|
|
249
|
+
if (process.platform !== "darwin") return null;
|
|
250
|
+
const addon = getNativeAddon();
|
|
251
|
+
if (!ensureAccessibilityPermission(addon)) return null;
|
|
252
|
+
try {
|
|
253
|
+
return addon.getSelectedTextSmart?.() ?? null;
|
|
254
|
+
} catch {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
238
258
|
export {
|
|
239
259
|
checkKeyboardPermission,
|
|
240
260
|
createGlobalKeyboardListener,
|
|
261
|
+
getContextJSON,
|
|
241
262
|
getFocusedInputSelectedText,
|
|
242
263
|
getFocusedInputValue,
|
|
243
|
-
getGlobalKeyboardListener
|
|
264
|
+
getGlobalKeyboardListener,
|
|
265
|
+
getSelectedTextSmart
|
|
244
266
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simen-keyboard-listener",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Native global keyboard listener for macOS and Windows",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build:
|
|
19
|
+
"build:swift": "cd src/native && swiftc -O -parse-as-library -c ContextHelper.swift -o ContextHelper.o",
|
|
20
|
+
"build:native": "npm run build:swift && node-gyp rebuild --directory=src/native",
|
|
20
21
|
"build:ts": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
21
22
|
"build": "npm run build:native && npm run build:ts",
|
|
22
|
-
"prebuild": "prebuildify --napi --strip --cwd src/native --out ../../prebuilds",
|
|
23
|
+
"prebuild": "npm run build:swift && prebuildify --napi --strip --cwd src/native --out ../../prebuilds",
|
|
23
24
|
"prepublishOnly": "npm run build:ts",
|
|
24
25
|
"publish:all": "node scripts/publish.js"
|
|
25
26
|
},
|
|
@@ -45,8 +46,8 @@
|
|
|
45
46
|
"node-addon-api": "^8.0.0"
|
|
46
47
|
},
|
|
47
48
|
"optionalDependencies": {
|
|
48
|
-
"@simen-keyboard-listener/darwin-arm64": "1.1.
|
|
49
|
-
"@simen-keyboard-listener/win32-x64": "1.1.
|
|
49
|
+
"@simen-keyboard-listener/darwin-arm64": "1.1.3",
|
|
50
|
+
"@simen-keyboard-listener/win32-x64": "1.1.3"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@types/node": "^20.0.0",
|