@aspiresys/visor 1.3.5 → 1.4.0

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Region = exports.visor = void 0;
3
+ exports.initializeOCR = exports.Region = exports.visor = void 0;
4
4
  const screen_1 = require("./screen");
5
5
  const matcher_1 = require("./matcher");
6
6
  const mouse_1 = require("./mouse");
@@ -15,6 +15,7 @@ const display_1 = require("./display");
15
15
  const logger_1 = require("./logger");
16
16
  const console_1 = require("console");
17
17
  const templateMetadata_1 = require("./templateMetadata");
18
+ const version_1 = require("./version");
18
19
  class Visor {
19
20
  constructor() {
20
21
  this.mouse = nut_js_1.mouse;
@@ -29,138 +30,154 @@ class Visor {
29
30
  }
30
31
  const missing = [];
31
32
  if (!config_1.visorConfig.imagePath) {
32
- missing.push("imagePath");
33
+ missing.push('imagePath');
33
34
  }
34
35
  if (!config_1.visorConfig.outputPath) {
35
- missing.push("outputPath");
36
+ missing.push('outputPath');
36
37
  }
37
38
  if (missing.length > 0) {
38
39
  (0, console_1.warn)(`[VISOR] Configuration incomplete.\n` +
39
- `Missing: ${missing.join(", ")}\n\n` +
40
+ `Missing: ${missing.join(', ')}\n\n` +
40
41
  `Relative paths may not work correctly.\n` +
41
42
  `Use visor.loadConfig(...) or provide absolute paths directly to functions.`);
42
43
  }
43
44
  if (!config_1.visorConfig.initialized) {
44
45
  config_1.visorConfig.scaleFactor = (0, display_1.getWindowsScaleFactor)();
45
- (0, console_1.warn)(`[VISOR] Configuration not loaded.\n` +
46
- `Auto-detected scaleFactor=${config_1.visorConfig.scaleFactor}.\n`);
46
+ (0, console_1.warn)(`[VISOR] Configuration not loaded.\n` + `Auto-detected scaleFactor=${config_1.visorConfig.scaleFactor}.\n`);
47
47
  }
48
48
  if (missing.length > 0 || !config_1.visorConfig.initialized) {
49
49
  this.configWarningShown = true;
50
50
  }
51
51
  }
52
52
  /**
53
- * Moves the mouse cursor to the
54
- * center of a specific screen region.
55
- *
56
- * Region coordinates typically come from:
57
- * - visor.find()
58
- * - visor.findAll()
59
- * - OCR text matching
60
- * - Visor Inspector
61
- *
62
- * Display scaling is automatically
63
- * applied using the configured
64
- * scale factor.
65
- *
66
- * @param region Screen region coordinates.
67
- * @param offset Offset coords.
68
- *
69
- * @example
70
- * await visor.moveToRegion({
71
- * x: 100,
72
- * y: 200,
73
- * width: 150,
74
- * height: 50
75
- * });
76
- */
53
+ * Returns the currently installed
54
+ * Visor package version.
55
+ *
56
+ * Useful for:
57
+ * - debugging
58
+ * - support tickets
59
+ * - framework validation
60
+ *
61
+ * @returns Package version string.
62
+ *
63
+ * @example
64
+ * console.log(visor.version());
65
+ */
66
+ version() {
67
+ return (0, version_1.getVersion)();
68
+ }
69
+ /**
70
+ * Moves the mouse cursor to the
71
+ * center of a specific screen region.
72
+ *
73
+ * Region coordinates typically come from:
74
+ * - visor.find()
75
+ * - visor.findAll()
76
+ * - OCR text matching
77
+ * - Visor Inspector
78
+ *
79
+ * Display scaling is automatically
80
+ * applied using the configured
81
+ * scale factor.
82
+ *
83
+ * @param region Screen region coordinates.
84
+ * @param offset Offset coords.
85
+ *
86
+ * @example
87
+ * await visor.moveToRegion({
88
+ * x: 100,
89
+ * y: 200,
90
+ * width: 150,
91
+ * height: 50
92
+ * });
93
+ */
77
94
  async moveToRegion(region, offset) {
78
95
  await (0, mouse_1.moveToRegion)(region, offset);
79
96
  }
80
97
  /**
81
- * Performs a left mouse click at the
82
- * center of a specific screen region.
83
- *
84
- * Region coordinates typically come from:
85
- * - visor.find()
86
- * - visor.findAll()
87
- * - OCR text matching
88
- * - Visor Inspector
89
- *
90
- * Display scaling is automatically
91
- * applied using the configured
92
- * scale factor.
93
- *
94
- * @param region Screen region coordinates.
95
- * @param offset Offset coords.
96
- *
97
- * @example
98
- * await visor.clickRegion({
99
- * x: 100,
100
- * y: 200,
101
- * width: 150,
102
- * height: 50
103
- * });
104
- */
98
+ * Performs a left mouse click at the
99
+ * center of a specific screen region.
100
+ *
101
+ * Region coordinates typically come from:
102
+ * - visor.find()
103
+ * - visor.findAll()
104
+ * - OCR text matching
105
+ * - Visor Inspector
106
+ *
107
+ * Display scaling is automatically
108
+ * applied using the configured
109
+ * scale factor.
110
+ *
111
+ * @param region Screen region coordinates.
112
+ * @param offset Offset coords.
113
+ *
114
+ * @example
115
+ * await visor.clickRegion({
116
+ * x: 100,
117
+ * y: 200,
118
+ * width: 150,
119
+ * height: 50
120
+ * });
121
+ */
105
122
  async clickRegion(region, offset) {
106
123
  await (0, mouse_1.moveToRegion)(region, offset);
107
124
  await this.mouse.click(this.Button.LEFT);
108
125
  }
109
126
  /**
110
- * Performs a double left mouse click
111
- * at the center of a specific
112
- * screen region.
113
- *
114
- * Region coordinates typically come from:
115
- * - visor.find()
116
- * - visor.findAll()
117
- * - OCR text matching
118
- * - Visor Inspector
119
- *
120
- * Display scaling is automatically
121
- * applied using the configured
122
- * scale factor.
123
- *
124
- * @param region Screen region coordinates.
125
- * @param offset Offset coords.
126
- *
127
- * @example
128
- * await visor.doubleClickRegion({
129
- * x: 100,
130
- * y: 200,
131
- * width: 150,
132
- * height: 50
133
- * });
134
- */
127
+ * Performs a double left mouse click
128
+ * at the center of a specific
129
+ * screen region.
130
+ *
131
+ * Region coordinates typically come from:
132
+ * - visor.find()
133
+ * - visor.findAll()
134
+ * - OCR text matching
135
+ * - Visor Inspector
136
+ *
137
+ * Display scaling is automatically
138
+ * applied using the configured
139
+ * scale factor.
140
+ *
141
+ * @param region Screen region coordinates.
142
+ * @param offset Offset coords.
143
+ *
144
+ * @example
145
+ * await visor.doubleClickRegion({
146
+ * x: 100,
147
+ * y: 200,
148
+ * width: 150,
149
+ * height: 50
150
+ * });
151
+ */
135
152
  async doubleClickRegion(region, offset) {
136
153
  await (0, mouse_1.moveToRegion)(region, offset);
137
154
  await this.mouse.doubleClick(this.Button.LEFT);
138
155
  }
139
156
  /**
140
- * Performs a right mouse click at the
141
- * center of a specific screen region.
142
- *
143
- * Region coordinates typically come from:
144
- * - visor.find()
145
- * - visor.findAll()
146
- * - OCR text matching
147
- * - Visor Inspector
148
- *
149
- * Display scaling is automatically
150
- * applied using the configured
151
- * scale factor.
152
- *
153
- * @param region Screen region coordinates.
154
- * @param offset Offset coords.
155
- *
156
- * @example
157
- * await visor.rightClickRegion({
158
- * x: 100,
159
- * y: 200,
160
- * width: 150,
161
- * height: 50
162
- * });
163
- */
157
+ * Performs a right mouse click at the
158
+ * center of a specific screen region.
159
+ *
160
+ * Region coordinates typically come from:
161
+ * - visor.find()
162
+ * - visor.findAll()
163
+ * - OCR text matching
164
+ * - Visor Inspector
165
+ *
166
+ * Display scaling is automatically
167
+ * applied using the configured
168
+ * scale factor.
169
+ *
170
+ * @param region Screen region coordinates.
171
+ * @param offset Offset coords.
172
+ *
173
+ * @example
174
+ * await visor.rightClickRegion({
175
+ * x: 100,
176
+ * y: 200,
177
+ * width: 150,
178
+ * height: 50
179
+ * });
180
+ */
164
181
  async rightClickRegion(region, offset) {
165
182
  await (0, mouse_1.moveToRegion)(region, offset);
166
183
  await this.mouse.click(this.Button.RIGHT);
@@ -199,14 +216,14 @@ class Visor {
199
216
  this.checkConfig();
200
217
  if (!image) {
201
218
  await this.mouse.click(this.Button.LEFT);
202
- (0, logger_1.log)("[MOUSE] Left click completed");
219
+ (0, logger_1.log)('[MOUSE] Left click completed');
203
220
  return;
204
221
  }
205
222
  const region = await this.find(image, confidence);
206
223
  if (!region) {
207
224
  throw new Error(`Image not found: ${image}`);
208
225
  }
209
- (0, logger_1.log)("[CV] Match found:", region);
226
+ (0, logger_1.log)('[CV] Match found:', region);
210
227
  await (0, mouse_1.clickRegion)(region, offset);
211
228
  }
212
229
  /**
@@ -243,7 +260,7 @@ class Visor {
243
260
  await (0, mouse_1.moveToRegion)(region, offset);
244
261
  }
245
262
  await this.mouse.click(this.Button.RIGHT);
246
- (0, logger_1.log)("[MOUSE] Right click completed");
263
+ (0, logger_1.log)('[MOUSE] Right click completed');
247
264
  }
248
265
  /**
249
266
  * Performs a double left mouse click.
@@ -280,7 +297,7 @@ class Visor {
280
297
  await (0, mouse_1.moveToRegion)(region, offset);
281
298
  }
282
299
  await this.mouse.doubleClick(this.Button.LEFT);
283
- (0, logger_1.log)("[MOUSE] Double click completed");
300
+ (0, logger_1.log)('[MOUSE] Double click completed');
284
301
  }
285
302
  /**
286
303
  * Finds the best matching image on screen
@@ -413,14 +430,14 @@ class Visor {
413
430
  async previewMatches(image, confidence = 0.8) {
414
431
  this.checkConfig();
415
432
  const matches = await this.findAll(image, confidence);
416
- (0, logger_1.log)("\n=== MATCH PREVIEW ===\n");
433
+ (0, logger_1.log)('\n=== MATCH PREVIEW ===\n');
417
434
  matches.forEach((m, i) => {
418
- (0, logger_1.log)(`#${i + 1}
419
- X:${m.x}
420
- Y:${m.y}
421
- W:${m.width}
422
- H:${m.height}
423
- CONF:${m.confidence.toFixed(3)}
435
+ (0, logger_1.log)(`#${i + 1}
436
+ X:${m.x}
437
+ Y:${m.y}
438
+ W:${m.width}
439
+ H:${m.height}
440
+ CONF:${m.confidence.toFixed(3)}
424
441
  `);
425
442
  });
426
443
  return matches;
@@ -709,10 +726,10 @@ CONF:${m.confidence.toFixed(3)}
709
726
  */
710
727
  async captureScreenshot(path) {
711
728
  this.checkConfig();
712
- path = config_1.visorConfig.outputPath + "/" + path;
729
+ path = config_1.visorConfig.outputPath + '/' + path;
713
730
  (0, logger_1.log)(`[VISOR] Saving screenshot: ${path}`);
714
731
  await (0, screen_1.saveScreenshot)(path);
715
- (0, logger_1.log)("[VISOR] Screenshot saved");
732
+ (0, logger_1.log)('[VISOR] Screenshot saved');
716
733
  }
717
734
  /**
718
735
  * Opens a desktop application,
@@ -773,13 +790,13 @@ CONF:${m.confidence.toFixed(3)}
773
790
  const src = await this.find(source, confidence);
774
791
  const dst = await this.find(target, confidence);
775
792
  if (!src || !dst) {
776
- throw new Error("Source or target not found");
793
+ throw new Error('Source or target not found');
777
794
  }
778
795
  await (0, mouse_1.moveToRegion)(src);
779
796
  await this.mouse.pressButton(this.Button.LEFT);
780
797
  await (0, mouse_1.moveToRegion)(dst);
781
798
  await this.mouse.releaseButton(this.Button.LEFT);
782
- (0, logger_1.log)("[MOUSE] Drag and drop completed");
799
+ (0, logger_1.log)('[MOUSE] Drag and drop completed');
783
800
  }
784
801
  /**
785
802
  * Moves the mouse cursor to the
@@ -807,7 +824,7 @@ CONF:${m.confidence.toFixed(3)}
807
824
  throw new Error(`Image not found: ${image}`);
808
825
  }
809
826
  await (0, mouse_1.moveToRegion)(region, offset);
810
- (0, logger_1.log)("[MOUSE] Hover completed");
827
+ (0, logger_1.log)('[MOUSE] Hover completed');
811
828
  }
812
829
  /**
813
830
  * Scrolls the mouse wheel downward.
@@ -1026,6 +1043,19 @@ CONF:${m.confidence.toFixed(3)}
1026
1043
  getImagePath() {
1027
1044
  return config_1.visorConfig.imagePath;
1028
1045
  }
1046
+ showConfig() {
1047
+ console.log(`
1048
+ === VISOR CONFIG ===
1049
+
1050
+ Scale Factor : ${config_1.visorConfig.scaleFactor}
1051
+ Image Path : ${config_1.visorConfig.imagePath}
1052
+ Output Path : ${config_1.visorConfig.outputPath}
1053
+ Debug : ${config_1.visorConfig.debug}
1054
+ Initialized : ${config_1.visorConfig.initialized}
1055
+
1056
+ ====================
1057
+ `);
1058
+ }
1029
1059
  /**
1030
1060
  * Sets the default output path
1031
1061
  * used for visual automation APIs.
@@ -1108,7 +1138,7 @@ CONF:${m.confidence.toFixed(3)}
1108
1138
  this.setDebug(config.debug);
1109
1139
  }
1110
1140
  config_1.visorConfig.initialized = true;
1111
- (0, logger_1.log)("[VISOR] Config loaded");
1141
+ (0, logger_1.log)('[VISOR] Config loaded');
1112
1142
  }
1113
1143
  /**
1114
1144
  * Finds the first matching image
@@ -1304,7 +1334,7 @@ CONF:${m.confidence.toFixed(3)}
1304
1334
  }
1305
1335
  await this.sleep(interval);
1306
1336
  }
1307
- throw new Error("Timeout waiting for images");
1337
+ throw new Error('Timeout waiting for images');
1308
1338
  }
1309
1339
  /**
1310
1340
  * Terminates shared OCR worker.
@@ -1323,24 +1353,24 @@ CONF:${m.confidence.toFixed(3)}
1323
1353
  await (0, ocr_1.terminateOCR)();
1324
1354
  }
1325
1355
  /**
1326
- * Executes a command and returns output.
1327
- *
1328
- * @example
1329
- * const output =
1330
- * await visor.exec("ipconfig");
1331
- */
1356
+ * Executes a command and returns output.
1357
+ *
1358
+ * @example
1359
+ * const output =
1360
+ * await visor.exec("ipconfig");
1361
+ */
1332
1362
  async exec(command) {
1333
1363
  return await (0, app_1.execCommand)(command);
1334
1364
  }
1335
1365
  /**
1336
- * Starts a command without waiting
1337
- * for completion.
1338
- *
1339
- * @example
1340
- * await visor.execDetached(
1341
- * "notepad"
1342
- * );
1343
- */
1366
+ * Starts a command without waiting
1367
+ * for completion.
1368
+ *
1369
+ * @example
1370
+ * await visor.execDetached(
1371
+ * "notepad"
1372
+ * );
1373
+ */
1344
1374
  async execDetached(command) {
1345
1375
  await (0, app_1.execDetached)(command);
1346
1376
  }
@@ -1358,42 +1388,44 @@ CONF:${m.confidence.toFixed(3)}
1358
1388
  await this.press(nut_js_1.Key.LeftControl, nut_js_1.Key.V);
1359
1389
  }
1360
1390
  /**
1361
- * Generates a alert box.
1362
- *
1363
- * @param message Text to display.
1364
- * @param title Title of the alert.
1365
- *
1366
- * @example
1367
- * await visor.alert("Execution Completed");
1368
- */
1369
- async alert(message, title = "Visor") {
1391
+ * Generates a alert box.
1392
+ *
1393
+ * @param message Text to display.
1394
+ * @param title Title of the alert.
1395
+ *
1396
+ * @example
1397
+ * await visor.alert("Execution Completed");
1398
+ */
1399
+ async alert(message, title = 'Visor') {
1370
1400
  await (0, dialog_1.alert)(message, title);
1371
1401
  }
1372
1402
  /**
1373
- * Generates a conform box with Yes/No.
1374
- *
1375
- * @param message Text to display.
1376
- * @param title Title of the window.
1377
- *
1378
- * @example
1379
- * await visor.conform("Continue Execution?");
1380
- */
1381
- async confirm(message, title = "Visor") {
1403
+ * Generates a conform box with Yes/No.
1404
+ *
1405
+ * @param message Text to display.
1406
+ * @param title Title of the window.
1407
+ *
1408
+ * @example
1409
+ * await visor.conform("Continue Execution?");
1410
+ */
1411
+ async confirm(message, title = 'Visor') {
1382
1412
  return await (0, dialog_1.confirm)(message, title);
1383
1413
  }
1384
1414
  /**
1385
- * Generates a input box.
1386
- *
1387
- * @param message Text to display.
1388
- * @param title Title of the window.
1389
- *
1390
- * @example
1391
- * await visor.input("Enter Email");
1392
- */
1393
- async input(message, title = "Visor") {
1415
+ * Generates a input box.
1416
+ *
1417
+ * @param message Text to display.
1418
+ * @param title Title of the window.
1419
+ *
1420
+ * @example
1421
+ * await visor.input("Enter Email");
1422
+ */
1423
+ async input(message, title = 'Visor') {
1394
1424
  return await (0, dialog_1.prompt)(message, title);
1395
1425
  }
1396
1426
  }
1397
1427
  exports.visor = new Visor();
1398
1428
  var types_1 = require("./types");
1399
1429
  Object.defineProperty(exports, "Region", { enumerable: true, get: function () { return types_1.Region; } });
1430
+ var ocr_2 = require("./ocr");
1431
+ Object.defineProperty(exports, "initializeOCR", { enumerable: true, get: function () { return ocr_2.initializeOCR; } });
@@ -1,11 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const express_1 = __importDefault(require("express"));
7
- const path_1 = __importDefault(require("path"));
8
- const app_1 = require("../app");
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, '__esModule', { value: true });
8
+ const express_1 = __importDefault(require('express'));
9
+ const path_1 = __importDefault(require('path'));
10
+ const app_1 = require('../app');
9
11
  const app = (0, express_1.default)();
10
12
  const PORT = 3000;
11
13
  app.use(express_1.default.static(path_1.default.join(__dirname)));
package/dist/matcher.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Region } from "./types";
1
+ import { Region } from './types';
2
2
  export declare function loadTemplate(path: string): Promise<any>;
3
3
  export declare function loadScreen(path: string): Promise<any>;
4
4
  export declare function matchTemplate(screen: any, template: any, confidence?: number, metadata?: any): Region | null;