@aspiresys/visor 1.3.2 → 1.3.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/types.d.ts CHANGED
@@ -59,6 +59,128 @@ export declare class Region {
59
59
  */
60
60
  click(offset?: Offset): Promise<void>;
61
61
  /**
62
+ * Finds an image in the Region using OpenCV
63
+ * and performs a left mouse click
64
+ * on the matched region.
65
+ *
66
+ * @param image Optional image filename or path.
67
+ *
68
+ * @param confidence Match confidence threshold.
69
+ *
70
+ * Accepted range:
71
+ * 0.0 to 1.0
72
+ *
73
+ * Default:
74
+ * 0.8
75
+ *
76
+ * Recommended values:
77
+ * - 0.7 for dynamic UI
78
+ * - 0.8 for standard usage
79
+ * - 0.9+ for strict matching
80
+ *
81
+ * Lower confidence increases
82
+ * flexibility but may increase
83
+ * false positives.
84
+ *
85
+ * @example
86
+ * await region.clickImg("save.png");
87
+ *
88
+ * @example
89
+ * await region.clickImg("./images/save.png", 0.9);
90
+ */
91
+ clickImg(image?: string, confidence?: number, offset?: Offset): Promise<void>;
92
+ /**
93
+ * Finds the image in the Region and
94
+ * moves the mouse to the matched region
95
+ * before performing the click.
96
+ *
97
+ * @param image Image filename or path.
98
+ * @param confidence Match confidence threshold.
99
+ *
100
+ * Accepted range:
101
+ * 0.0 to 1.0
102
+ *
103
+ * Default:
104
+ * 0.8
105
+ * @throws Error if image is not found.
106
+ *
107
+ * @example
108
+ * await region.rightClickImg("file.png");
109
+ *
110
+ * @example
111
+ * await region.rightClickImg();
112
+ */
113
+ rightClickImg(image?: string, confidence?: number, offset?: Offset): Promise<void>;
114
+ private sleep;
115
+ /**
116
+ * Finds an image in the Region using OpenCV
117
+ * and performs a double left mouse click
118
+ * on the matched region.
119
+ *
120
+ * @param image Optional image filename or path.
121
+ *
122
+ * @param confidence Match confidence threshold.
123
+ *
124
+ * Accepted range:
125
+ * 0.0 to 1.0
126
+ *
127
+ * Default:
128
+ * 0.8
129
+ *
130
+ * Recommended values:
131
+ * - 0.7 for dynamic UI
132
+ * - 0.8 for standard usage
133
+ * - 0.9+ for strict matching
134
+ *
135
+ * Lower confidence increases
136
+ * flexibility but may increase
137
+ * false positives.
138
+ *
139
+ * @example
140
+ * await region.doubleClickImg("save.png");
141
+ *
142
+ * @example
143
+ * await region.doubleClickImg("./images/save.png", 0.9);
144
+ */
145
+ doubleClickImg(image?: string, confidence?: number, offset?: Offset): Promise<void>;
146
+ /**
147
+ * Waits until an image appears
148
+ * in the Region.
149
+ *
150
+ * @param image Image filename or path.
151
+ *
152
+ * @param confidence Match confidence threshold.
153
+ *
154
+ * Accepted range:
155
+ * 0.0 to 1.0
156
+ *
157
+ * Default:
158
+ * 0.8
159
+ *
160
+ * Recommended values:
161
+ * - 0.7 for dynamic UI
162
+ * - 0.8 for standard usage
163
+ * - 0.9+ for strict matching
164
+ *
165
+ * @param timeout Timeout duration
166
+ * in milliseconds.
167
+ *
168
+ * Default:
169
+ * 5000ms
170
+ *
171
+ * Recommended range:
172
+ * 1000ms to 30000ms
173
+ *
174
+ * @throws Error if timeout occurs.
175
+ *
176
+ * @example
177
+ * await region.waitImg("loading-done.png");
178
+ */
179
+ waitImg(image: string, { confidence, timeout }?: {
180
+ confidence?: number;
181
+ timeout?: number;
182
+ }): Promise<boolean>;
183
+ /**
62
184
  * Performs a double left click on the region.
63
185
  *
64
186
  * Optional offset can be supplied to click
package/dist/types.js CHANGED
@@ -103,6 +103,159 @@ class Region {
103
103
  await (0, mouse_1.clickRegion)(this, offset);
104
104
  }
105
105
  /**
106
+ * Finds an image in the Region using OpenCV
107
+ * and performs a left mouse click
108
+ * on the matched region.
109
+ *
110
+ * @param image Optional image filename or path.
111
+ *
112
+ * @param confidence Match confidence threshold.
113
+ *
114
+ * Accepted range:
115
+ * 0.0 to 1.0
116
+ *
117
+ * Default:
118
+ * 0.8
119
+ *
120
+ * Recommended values:
121
+ * - 0.7 for dynamic UI
122
+ * - 0.8 for standard usage
123
+ * - 0.9+ for strict matching
124
+ *
125
+ * Lower confidence increases
126
+ * flexibility but may increase
127
+ * false positives.
128
+ *
129
+ * @example
130
+ * await region.clickImg("save.png");
131
+ *
132
+ * @example
133
+ * await region.clickImg("./images/save.png", 0.9);
134
+ */
135
+ async clickImg(image, confidence = 0.8, offset) {
136
+ this.checkConfig();
137
+ const region = await this.find(image, confidence);
138
+ if (!region) {
139
+ throw new Error(`Image not found: ${image}`);
140
+ }
141
+ await region.click(offset);
142
+ }
143
+ /**
144
+ * Finds the image in the Region and
145
+ * moves the mouse to the matched region
146
+ * before performing the click.
147
+ *
148
+ * @param image Image filename or path.
149
+ * @param confidence Match confidence threshold.
150
+ *
151
+ * Accepted range:
152
+ * 0.0 to 1.0
153
+ *
154
+ * Default:
155
+ * 0.8
156
+ * @throws Error if image is not found.
157
+ *
158
+ * @example
159
+ * await region.rightClickImg("file.png");
160
+ *
161
+ * @example
162
+ * await region.rightClickImg();
163
+ */
164
+ async rightClickImg(image, confidence = 0.8, offset) {
165
+ this.checkConfig();
166
+ const region = await this.find(image, confidence);
167
+ if (!region) {
168
+ throw new Error(`Image not found: ${image}`);
169
+ }
170
+ await region.rightClick(offset);
171
+ }
172
+ async sleep(ms) {
173
+ return new Promise((r) => setTimeout(r, ms));
174
+ }
175
+ /**
176
+ * Finds an image in the Region using OpenCV
177
+ * and performs a double left mouse click
178
+ * on the matched region.
179
+ *
180
+ * @param image Optional image filename or path.
181
+ *
182
+ * @param confidence Match confidence threshold.
183
+ *
184
+ * Accepted range:
185
+ * 0.0 to 1.0
186
+ *
187
+ * Default:
188
+ * 0.8
189
+ *
190
+ * Recommended values:
191
+ * - 0.7 for dynamic UI
192
+ * - 0.8 for standard usage
193
+ * - 0.9+ for strict matching
194
+ *
195
+ * Lower confidence increases
196
+ * flexibility but may increase
197
+ * false positives.
198
+ *
199
+ * @example
200
+ * await region.doubleClickImg("save.png");
201
+ *
202
+ * @example
203
+ * await region.doubleClickImg("./images/save.png", 0.9);
204
+ */
205
+ async doubleClickImg(image, confidence = 0.8, offset) {
206
+ this.checkConfig();
207
+ const region = await this.find(image, confidence);
208
+ if (!region) {
209
+ throw new Error(`Image not found: ${image}`);
210
+ }
211
+ await region.doubleClick(offset);
212
+ }
213
+ /**
214
+ * Waits until an image appears
215
+ * in the Region.
216
+ *
217
+ * @param image Image filename or path.
218
+ *
219
+ * @param confidence Match confidence threshold.
220
+ *
221
+ * Accepted range:
222
+ * 0.0 to 1.0
223
+ *
224
+ * Default:
225
+ * 0.8
226
+ *
227
+ * Recommended values:
228
+ * - 0.7 for dynamic UI
229
+ * - 0.8 for standard usage
230
+ * - 0.9+ for strict matching
231
+ *
232
+ * @param timeout Timeout duration
233
+ * in milliseconds.
234
+ *
235
+ * Default:
236
+ * 5000ms
237
+ *
238
+ * Recommended range:
239
+ * 1000ms to 30000ms
240
+ *
241
+ * @throws Error if timeout occurs.
242
+ *
243
+ * @example
244
+ * await region.waitImg("loading-done.png");
245
+ */
246
+ async waitImg(image, { confidence = 0.8, timeout = 5000 } = {}) {
247
+ this.checkConfig();
248
+ const interval = 300;
249
+ const attempts = Math.ceil(timeout / interval);
250
+ for (let i = 0; i < attempts; i++) {
251
+ if (await this.exists(image, confidence)) {
252
+ return true;
253
+ }
254
+ await this.sleep(interval);
255
+ }
256
+ throw new Error(`Timeout waiting for image: ${image}`);
257
+ }
258
+ /**
106
259
  * Performs a double left click on the region.
107
260
  *
108
261
  * Optional offset can be supplied to click
@@ -219,7 +372,7 @@ class Region {
219
372
  const croppedScreenshot = await (0, matcher_1.cropMat)(screenshot, this);
220
373
  const template = await (0, matcher_1.loadTemplate)((0, path_1.resolveImagePath)(image));
221
374
  try {
222
- const match = (0, matcher_1.matchInspectorTemplate)(croppedScreenshot, template, confidence, false);
375
+ const match = (0, matcher_1.matchTemplate)(croppedScreenshot, template, confidence);
223
376
  if (!match) {
224
377
  return null;
225
378
  }
@@ -39,7 +39,7 @@
39
39
  </section>
40
40
  <div class="capture-layout">
41
41
  <div class="capture-panel">
42
- <h3 class="section-title"> Current Capture (X:<span id="mousex"></span>, Y:<span id="mousey"></span>)</h3>
42
+ <h3 class="section-title"> Current Capture (X:<span id="mousex"></span>, Y:<span id="mousey"></span>, Width:<span id="mousew"></span>, Height:<span id="mouseh"></span>)</h3>
43
43
  <canvas id="screenCanvas" class="canvas"></canvas>
44
44
  </div>
45
45
  <div class="result-panel">
@@ -90,6 +90,8 @@ canvas.addEventListener("mousemove",
90
90
  canvas.addEventListener("mouseup",
91
91
  () => {
92
92
  selecting = false;
93
+ document.getElementById("mousew").innerHTML = Math.round(Math.abs(endX - startX));
94
+ document.getElementById("mouseh").innerHTML = Math.round(Math.abs(endY - startY));
93
95
  console.log(startX, startY, endX, endY);
94
96
  }
95
97
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aspiresys/visor",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {