@appium/images-plugin 4.2.8 → 6.0.0-beta.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright OpenJS Foundation and other contributors, https://openjsf.org/
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -1,5 +1,5 @@
1
1
  import { type MatchingOptions, type OccurrenceOptions, type SimilarityOptions } from '@appium/opencv';
2
- import type { ComparisonResult } from './types';
2
+ import type { ComparisonResult } from './types.js';
3
3
  /**
4
4
  * Performs images comparison using OpenCV framework features.
5
5
  * It is expected that both OpenCV framework and opencv4nodejs
@@ -1 +1 @@
1
- {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../lib/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,EAEvB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GAAG,MAAM,EAC3B,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,OAAO,GAAE,eAAe,GAAG,iBAAiB,GAAG,iBAAsB,GACpE,OAAO,CAAC,gBAAgB,CAAC,CAmC3B"}
1
+ {"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../lib/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EAEtB,KAAK,iBAAiB,EAEvB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,YAAY,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GAAG,MAAM,EAC3B,WAAW,EAAE,MAAM,GAAG,MAAM,EAC5B,OAAO,GAAE,eAAe,GAAG,iBAAiB,GAAG,iBAAsB,GACpE,OAAO,CAAC,gBAAgB,CAAC,CAmC3B"}
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compareImages = compareImages;
4
- const opencv_1 = require("@appium/opencv");
5
- const driver_1 = require("appium/driver");
6
- const constants_1 = require("./constants");
1
+ import { getImageOccurrence, getImagesMatches, getImagesSimilarity, } from '@appium/opencv';
2
+ import { errors } from 'appium/driver.js';
3
+ import { GET_SIMILARITY_MODE, MATCH_FEATURES_MODE, MATCH_TEMPLATE_MODE } from './constants.js';
7
4
  /**
8
5
  * Performs images comparison using OpenCV framework features.
9
6
  * It is expected that both OpenCV framework and opencv4nodejs
@@ -25,27 +22,27 @@ const constants_1 = require("./constants");
25
22
  * if `mode` value is incorrect or if there was an unexpected issue while
26
23
  * matching the images.
27
24
  */
28
- async function compareImages(mode, firstImage, secondImage, options = {}) {
25
+ export async function compareImages(mode, firstImage, secondImage, options = {}) {
29
26
  const img1 = Buffer.isBuffer(firstImage) ? firstImage : Buffer.from(firstImage, 'base64');
30
27
  const img2 = Buffer.isBuffer(secondImage) ? secondImage : Buffer.from(secondImage, 'base64');
31
28
  let result;
32
29
  switch (mode.toLowerCase()) {
33
- case constants_1.MATCH_FEATURES_MODE.toLowerCase():
30
+ case MATCH_FEATURES_MODE.toLowerCase():
34
31
  try {
35
- result = await (0, opencv_1.getImagesMatches)(img1, img2, options);
32
+ result = await getImagesMatches(img1, img2, options);
36
33
  }
37
34
  catch {
38
35
  // might throw if no matches
39
36
  result = { count: 0 };
40
37
  }
41
38
  break;
42
- case constants_1.GET_SIMILARITY_MODE.toLowerCase():
43
- result = await (0, opencv_1.getImagesSimilarity)(img1, img2, options);
39
+ case GET_SIMILARITY_MODE.toLowerCase():
40
+ result = await getImagesSimilarity(img1, img2, options);
44
41
  break;
45
- case constants_1.MATCH_TEMPLATE_MODE.toLowerCase(): {
42
+ case MATCH_TEMPLATE_MODE.toLowerCase(): {
46
43
  const opts = options;
47
44
  // firstImage/img1 is the full image and secondImage/img2 is the partial one
48
- result = await (0, opencv_1.getImageOccurrence)(img1, img2, opts);
45
+ result = await getImageOccurrence(img1, img2, opts);
49
46
  if (opts.multiple && result.multiple) {
50
47
  const multipleResults = result.multiple;
51
48
  if (multipleResults) {
@@ -55,8 +52,8 @@ async function compareImages(mode, firstImage, secondImage, options = {}) {
55
52
  break;
56
53
  }
57
54
  default:
58
- throw new driver_1.errors.InvalidArgumentError(`'${mode}' images comparison mode is unknown. ` +
59
- `Only ${JSON.stringify([constants_1.MATCH_FEATURES_MODE, constants_1.GET_SIMILARITY_MODE, constants_1.MATCH_TEMPLATE_MODE])} modes are supported.`);
55
+ throw new errors.InvalidArgumentError(`'${mode}' images comparison mode is unknown. ` +
56
+ `Only ${JSON.stringify([MATCH_FEATURES_MODE, GET_SIMILARITY_MODE, MATCH_TEMPLATE_MODE])} modes are supported.`);
60
57
  }
61
58
  return convertVisualizationToBase64(result);
62
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"compare.js","sourceRoot":"","sources":["../../lib/compare.ts"],"names":[],"mappings":";;AAqCA,sCAwCC;AA7ED,2CAUwB;AACxB,0CAAqC;AAErC,2CAA0F;AAG1F;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,KAAK,UAAU,aAAa,CACjC,IAAY,EACZ,UAA2B,EAC3B,WAA4B,EAC5B,UAAmE,EAAE;IAErE,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC1F,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CA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,4 +1,4 @@
1
- import type { ImageSettings } from './types';
1
+ import type { ImageSettings } from './types.js';
2
2
  export declare const IMAGE_STRATEGY = "-image";
3
3
  export declare const IMAGE_ELEMENT_PREFIX = "appium-image-element-";
4
4
  export declare const IMAGE_EL_TAP_STRATEGY_W3C = "w3cActions";
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,cAAc,WAAW,CAAC;AAEvC,eAAO,MAAM,oBAAoB,0BAA0B,CAAC;AAC5D,eAAO,MAAM,yBAAyB,eAAe,CAAC;AACtD,eAAO,MAAM,6BAA6B,iBAAiB,CAAC;AAC5D,eAAO,MAAM,oBAAoB,yCAAsE,CAAC;AACxG,eAAO,MAAM,4BAA4B,IAAM,CAAC;AAEhD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AAEnD,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAElD,eAAO,MAAM,gBAAgB,EAWvB,aAAa,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,cAAc,WAAW,CAAC;AAEvC,eAAO,MAAM,oBAAoB,0BAA0B,CAAC;AAC5D,eAAO,MAAM,yBAAyB,eAAe,CAAC;AACtD,eAAO,MAAM,6BAA6B,iBAAiB,CAAC;AAC5D,eAAO,MAAM,oBAAoB,yCAAsE,CAAC;AACxG,eAAO,MAAM,4BAA4B,IAAM,CAAC;AAEhD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AAEnD,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAElD,eAAO,MAAM,gBAAgB,EAWvB,aAAa,CAAC"}
@@ -1,28 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_SETTINGS = exports.DEFAULT_FIX_IMAGE_TEMPLATE_SCALE = exports.DEFAULT_MATCH_THRESHOLD = exports.MATCH_TEMPLATE_MODE = exports.GET_SIMILARITY_MODE = exports.MATCH_FEATURES_MODE = exports.DEFAULT_TEMPLATE_IMAGE_SCALE = exports.IMAGE_TAP_STRATEGIES = exports.IMAGE_EL_TAP_STRATEGY_MJSONWP = exports.IMAGE_EL_TAP_STRATEGY_W3C = exports.IMAGE_ELEMENT_PREFIX = exports.IMAGE_STRATEGY = void 0;
4
- const support_1 = require("appium/support");
5
- exports.IMAGE_STRATEGY = '-image';
6
- exports.IMAGE_ELEMENT_PREFIX = 'appium-image-element-';
7
- exports.IMAGE_EL_TAP_STRATEGY_W3C = 'w3cActions';
8
- exports.IMAGE_EL_TAP_STRATEGY_MJSONWP = 'touchActions';
9
- exports.IMAGE_TAP_STRATEGIES = [exports.IMAGE_EL_TAP_STRATEGY_MJSONWP, exports.IMAGE_EL_TAP_STRATEGY_W3C];
10
- exports.DEFAULT_TEMPLATE_IMAGE_SCALE = 1.0;
11
- exports.MATCH_FEATURES_MODE = 'matchFeatures';
12
- exports.GET_SIMILARITY_MODE = 'getSimilarity';
13
- exports.MATCH_TEMPLATE_MODE = 'matchTemplate';
14
- exports.DEFAULT_MATCH_THRESHOLD = 0.4;
15
- exports.DEFAULT_FIX_IMAGE_TEMPLATE_SCALE = 1;
16
- exports.DEFAULT_SETTINGS = support_1.node.deepFreeze({
17
- imageMatchThreshold: exports.DEFAULT_MATCH_THRESHOLD,
1
+ import { node } from 'appium/support.js';
2
+ export const IMAGE_STRATEGY = '-image';
3
+ export const IMAGE_ELEMENT_PREFIX = 'appium-image-element-';
4
+ export const IMAGE_EL_TAP_STRATEGY_W3C = 'w3cActions';
5
+ export const IMAGE_EL_TAP_STRATEGY_MJSONWP = 'touchActions';
6
+ export const IMAGE_TAP_STRATEGIES = [IMAGE_EL_TAP_STRATEGY_MJSONWP, IMAGE_EL_TAP_STRATEGY_W3C];
7
+ export const DEFAULT_TEMPLATE_IMAGE_SCALE = 1.0;
8
+ export const MATCH_FEATURES_MODE = 'matchFeatures';
9
+ export const GET_SIMILARITY_MODE = 'getSimilarity';
10
+ export const MATCH_TEMPLATE_MODE = 'matchTemplate';
11
+ export const DEFAULT_MATCH_THRESHOLD = 0.4;
12
+ export const DEFAULT_FIX_IMAGE_TEMPLATE_SCALE = 1;
13
+ export const DEFAULT_SETTINGS = node.deepFreeze({
14
+ imageMatchThreshold: DEFAULT_MATCH_THRESHOLD,
18
15
  imageMatchMethod: '',
19
16
  fixImageFindScreenshotDims: true,
20
17
  fixImageTemplateSize: false,
21
18
  fixImageTemplateScale: false,
22
- defaultImageTemplateScale: exports.DEFAULT_TEMPLATE_IMAGE_SCALE,
19
+ defaultImageTemplateScale: DEFAULT_TEMPLATE_IMAGE_SCALE,
23
20
  checkForImageElementStaleness: true,
24
21
  autoUpdateImageElementPosition: false,
25
- imageElementTapStrategy: exports.IMAGE_EL_TAP_STRATEGY_W3C,
22
+ imageElementTapStrategy: IMAGE_EL_TAP_STRATEGY_W3C,
26
23
  getMatchedImageResult: false,
27
24
  });
28
25
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":";;;AAAA,4CAAoC;AAIvB,QAAA,cAAc,GAAG,QAAQ,CAAC;AAE1B,QAAA,oBAAoB,GAAG,uBAAuB,CAAC;AAC/C,QAAA,yBAAyB,GAAG,YAAY,CAAC;AACzC,QAA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e,CAAC;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAEnD,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,UAAU,CAAC;IAC9C,mBAAmB,EAAE,uBAAuB;IAC5C,gBAAgB,EAAE,EAAE;IACpB,0BAA0B,EAAE,IAAI;IAChC,oBAAoB,EAAE,KAAK;IAC3B,qBAAqB,EAAE,KAAK;IAC5B,yBAAyB,EAAE,4BAA4B;IACvD,6BAA6B,EAAE,IAAI;IACnC,8BAA8B,EAAE,KAAK;IACrC,uBAAuB,EAAE,yBAAyB;IAClD,qBAAqB,EAAE,KAAK;CAC7B,CAAkB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import type { Element, ExternalDriver, Size } from '@appium/types';
2
- import { ImageElement } from './image-element';
3
- import type { FindByImageOptions, ImageTemplateSettings, Screenshot, ScreenshotScale } from './types';
2
+ import { ImageElement } from './image-element.js';
3
+ import type { FindByImageOptions, ImageTemplateSettings, Screenshot, ScreenshotScale } from './types.js';
4
4
  export declare class ImageElementFinder {
5
5
  private _imgElCache;
6
6
  constructor(max?: number);
@@ -1 +1 @@
1
- {"version":3,"file":"finder.d.ts","sourceRoot":"","sources":["../../lib/finder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAE,cAAc,EAAQ,IAAI,EAAC,MAAM,eAAe,CAAC;AAYvE,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C,OAAO,KAAK,EACV,kBAAkB,EAElB,qBAAqB,EAErB,UAAU,EACV,eAAe,EAChB,MAAM,SAAS,CAAC;AA2BjB,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,WAAW,CAAiC;gBAExC,GAAG,GAAE,MAAwB;IAQzC,oBAAoB,CAAC,KAAK,EAAE,YAAY,G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kBAAkB,IAAI,IAAI;IAI1B;;;;;;;;;OASG;IACG,WAAW,CACf,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,cAAc,EACtB,EACE,oBAA4B,EAC5B,QAAgB,EAChB,+BAAuC,EACvC,aAAoB,GACrB,GAAE,kBAAuB,GACzB,OAAO,CAAC,OAAO,GAAG,OAAO,EAAE,GAAG,YAAY,CAAC;IAuI9C;;;;;;;OAOG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IA8B1E;;;;;;;;OAQG;IACG,yBAAyB,CAC7B,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,IAAI,GACf,OAAO,CAAC,UAAU,GAAG;QAAC,KAAK,CAAC,EAAE,eAAe,CAAA;KAAC,CAAC;IA+HlD;;;;;;;;OAQG;IACG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC;CAgE7F"}
@@ -1,16 +1,10 @@
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
- exports.ImageElementFinder = void 0;
7
- const driver_1 = require("appium/driver");
8
- const lru_cache_1 = require("lru-cache");
9
- const sharp_1 = __importDefault(require("sharp"));
10
- const compare_1 = require("./compare");
11
- const constants_1 = require("./constants");
12
- const image_element_1 = require("./image-element");
13
- const logger_1 = require("./logger");
1
+ import { errors } from 'appium/driver.js';
2
+ import { LRUCache } from 'lru-cache';
3
+ import sharp from 'sharp';
4
+ import { compareImages } from './compare.js';
5
+ import { DEFAULT_FIX_IMAGE_TEMPLATE_SCALE, DEFAULT_SETTINGS, DEFAULT_TEMPLATE_IMAGE_SCALE, MATCH_TEMPLATE_MODE, } from './constants.js';
6
+ import { ImageElement } from './image-element.js';
7
+ import { log } from './logger.js';
14
8
  // Used to compare ratio and screen width
15
9
  // Pixel is basically under 1080 for example. 100K is probably enough fo a while.
16
10
  const FLOAT_PRECISION = 100000;
@@ -31,10 +25,10 @@ function containsRect(templateRect, rect) {
31
25
  }
32
26
  const NO_OCCURRENCES_PATTERN = /Cannot find any occurrences/;
33
27
  const CONDITION_UNMET_PATTERN = /Condition unmet/;
34
- class ImageElementFinder {
28
+ export class ImageElementFinder {
35
29
  _imgElCache;
36
30
  constructor(max = MAX_CACHE_ITEMS) {
37
- this._imgElCache = new lru_cache_1.LRUCache({
31
+ this._imgElCache = new LRUCache({
38
32
  ttl: MAX_CACHE_AGE_MS,
39
33
  updateAgeOnGet: true,
40
34
  max,
@@ -61,25 +55,17 @@ class ImageElementFinder {
61
55
  * @returns WebDriver element with a special id prefix
62
56
  */
63
57
  async findByImage(template, driver, { shouldCheckStaleness = false, multiple = false, ignoreDefaultImageTemplateScale = false, containerRect = null, } = {}) {
64
- const settings = { ...constants_1.DEFAULT_SETTINGS, ...driver.settings.getSettings() };
58
+ const settings = { ...DEFAULT_SETTINGS, ...driver.settings.getSettings() };
65
59
  const { imageMatchThreshold: threshold, imageMatchMethod, fixImageTemplateSize, fixImageTemplateScale, defaultImageTemplateScale, getMatchedImageResult: visualize, } = settings;
66
- logger_1.log.info(`Finding image element with match threshold ${threshold}`);
67
- if (!driver.getWindowRect && !Object.hasOwn(driver, 'getWindowSize')) {
60
+ log.info(`Finding image element with match threshold ${threshold}`);
61
+ if (!driver.getWindowRect) {
68
62
  throw new Error("This driver does not support the required 'getWindowRect' command");
69
63
  }
70
- let screenSize;
71
- if (driver.getWindowRect) {
72
- const screenRect = await driver.getWindowRect();
73
- screenSize = {
74
- width: screenRect.width,
75
- height: screenRect.height,
76
- };
77
- }
78
- else {
79
- // TODO: Drop the deprecated endpoint
80
- // @ts-expect-error - deprecated getWindowSize method
81
- screenSize = await driver.getWindowSize();
82
- }
64
+ const screenRect = await driver.getWindowRect();
65
+ const screenSize = {
66
+ width: screenRect.width,
67
+ height: screenRect.height,
68
+ };
83
69
  // someone might have sent in a template that's larger than the screen
84
70
  // dimensions. If so let's check and cut it down to size since the algorithm
85
71
  // will not work unless we do. But because it requires some potentially
@@ -121,14 +107,14 @@ class ImageElementFinder {
121
107
  visualization: el.visualization,
122
108
  };
123
109
  if (containerRect && !containsRect(containerRect, result.rect)) {
124
- logger_1.log.debug(`The matched element rectangle ${JSON.stringify(result.rect)} is not located ` +
110
+ log.debug(`The matched element rectangle ${JSON.stringify(result.rect)} is not located ` +
125
111
  `inside of the bounding rectangle ${JSON.stringify(containerRect)}, thus rejected`);
126
112
  return false;
127
113
  }
128
114
  results.push(result);
129
115
  return true;
130
116
  };
131
- const elOrEls = await (0, compare_1.compareImages)(constants_1.MATCH_TEMPLATE_MODE, screenshot, template, comparisonOpts);
117
+ const elOrEls = await compareImages(MATCH_TEMPLATE_MODE, screenshot, template, comparisonOpts);
132
118
  return (Array.isArray(elOrEls) ? elOrEls : [elOrEls]).some(pushIfOk);
133
119
  }
134
120
  catch (err) {
@@ -160,11 +146,11 @@ class ImageElementFinder {
160
146
  if (multiple) {
161
147
  return [];
162
148
  }
163
- throw new driver_1.errors.NoSuchElementError();
149
+ throw new errors.NoSuchElementError();
164
150
  }
165
151
  const elements = results.map(({ rect, score, visualization }) => {
166
- logger_1.log.info(`Image template matched: ${JSON.stringify(rect)}`);
167
- return new image_element_1.ImageElement({
152
+ log.info(`Image template matched: ${JSON.stringify(rect)}`);
153
+ return new ImageElement({
168
154
  template,
169
155
  rect,
170
156
  score,
@@ -191,17 +177,17 @@ class ImageElementFinder {
191
177
  * @returns image, potentially resized
192
178
  */
193
179
  async ensureTemplateSize(template, maxSize) {
194
- const imgObj = (0, sharp_1.default)(template);
180
+ const imgObj = sharp(template);
195
181
  const { width: tplWidth, height: tplHeight } = await imgObj.metadata();
196
182
  if (tplWidth == null || tplHeight == null) {
197
183
  throw new Error(`Template width/height cannot be determined. Is it a valid image?`);
198
184
  }
199
- logger_1.log.info(`Template image is ${tplWidth}x${tplHeight}. Bounding rectangle size is ${maxSize.width}x${maxSize.height}`);
185
+ log.info(`Template image is ${tplWidth}x${tplHeight}. Bounding rectangle size is ${maxSize.width}x${maxSize.height}`);
200
186
  // if the template fits inside the screen dimensions, we're good
201
187
  if (tplWidth <= maxSize.width && tplHeight <= maxSize.height) {
202
188
  return template;
203
189
  }
204
- logger_1.log.info(`Scaling template image from ${tplWidth}x${tplHeight} to match ` +
190
+ log.info(`Scaling template image from ${tplWidth}x${tplHeight} to match ` +
205
191
  `the bounding rectangle at ${maxSize.width}x${maxSize.height}`);
206
192
  // otherwise, scale it to fit inside the bounding rectangle dimensions:
207
193
  // https://sharp.pixelplumbing.com/api-resize
@@ -226,34 +212,34 @@ class ImageElementFinder {
226
212
  if (!driver.getScreenshot) {
227
213
  throw new Error("This driver does not support the required 'getScreenshot' command");
228
214
  }
229
- const settings = { ...constants_1.DEFAULT_SETTINGS, ...driver.settings.getSettings() };
215
+ const settings = { ...DEFAULT_SETTINGS, ...driver.settings.getSettings() };
230
216
  const { fixImageFindScreenshotDims } = settings;
231
217
  const screenshot = Buffer.from(await driver.getScreenshot(), 'base64');
232
218
  // if the user has requested not to correct for aspect or size differences
233
219
  // between the screenshot and the screen, just return the screenshot now
234
220
  if (!fixImageFindScreenshotDims) {
235
- logger_1.log.info(`Not verifying screenshot dimensions match screen`);
221
+ log.info(`Not verifying screenshot dimensions match screen`);
236
222
  return { screenshot };
237
223
  }
238
224
  if (screenSize.width < 1 || screenSize.height < 1) {
239
- logger_1.log.warn(`The retrieved screen size ${screenSize.width}x${screenSize.height} does ` +
225
+ log.warn(`The retrieved screen size ${screenSize.width}x${screenSize.height} does ` +
240
226
  `not seem to be valid. No changes will be applied to the screenshot`);
241
227
  return { screenshot };
242
228
  }
243
229
  // otherwise, do some verification on the screenshot to make sure it matches
244
230
  // the screen size and aspect ratio
245
- logger_1.log.info('Verifying screenshot size and aspect ratio');
246
- let imgObj = (0, sharp_1.default)(screenshot);
231
+ log.info('Verifying screenshot size and aspect ratio');
232
+ let imgObj = sharp(screenshot);
247
233
  let { width: shotWidth, height: shotHeight } = await imgObj.metadata();
248
234
  if (!shotWidth || shotWidth < 1 || !shotHeight || shotHeight < 1) {
249
- logger_1.log.warn(`The retrieved screenshot size ${shotWidth}x${shotHeight} does ` +
235
+ log.warn(`The retrieved screenshot size ${shotWidth}x${shotHeight} does ` +
250
236
  `not seem to be valid. No changes will be applied to the screenshot`);
251
237
  return { screenshot };
252
238
  }
253
239
  if (screenSize.width === shotWidth && screenSize.height === shotHeight) {
254
240
  // the height and width of the screenshot and the device screen match, which
255
241
  // means we should be safe when doing template matches
256
- logger_1.log.info('Screenshot size matched screen size');
242
+ log.info('Screenshot size matched screen size');
257
243
  return { screenshot };
258
244
  }
259
245
  // otherwise, if they don't match, it could spell problems for the accuracy
@@ -265,11 +251,11 @@ class ImageElementFinder {
265
251
  const screenAR = screenSize.width / screenSize.height;
266
252
  const shotAR = shotWidth / shotHeight;
267
253
  if (Math.round(screenAR * FLOAT_PRECISION) === Math.round(shotAR * FLOAT_PRECISION)) {
268
- logger_1.log.info(`Screenshot aspect ratio '${shotAR}' (${shotWidth}x${shotHeight}) matched ` +
254
+ log.info(`Screenshot aspect ratio '${shotAR}' (${shotWidth}x${shotHeight}) matched ` +
269
255
  `screen aspect ratio '${screenAR}' (${screenSize.width}x${screenSize.height})`);
270
256
  }
271
257
  else {
272
- logger_1.log.warn(`When trying to find an element, determined that the screen ` +
258
+ log.warn(`When trying to find an element, determined that the screen ` +
273
259
  `aspect ratio and screenshot aspect ratio are different. Screen ` +
274
260
  `is ${screenSize.width}x${screenSize.height} whereas screenshot is ` +
275
261
  `${shotWidth}x${shotHeight}.`);
@@ -288,7 +274,7 @@ class ImageElementFinder {
288
274
  const yScale = (1.0 * shotHeight) / screenSize.height;
289
275
  const scaleFactor = Math.min(xScale, yScale);
290
276
  const [newWidth, newHeight] = [shotWidth * scaleFactor, shotHeight * scaleFactor].map(Math.trunc);
291
- logger_1.log.warn(`Resizing screenshot to ${newWidth}x${newHeight} to match ` +
277
+ log.warn(`Resizing screenshot to ${newWidth}x${newHeight} to match ` +
292
278
  `screen aspect ratio so that image element coordinates have a ` +
293
279
  `greater chance of being correct.`);
294
280
  imgObj = imgObj.resize({
@@ -306,7 +292,7 @@ class ImageElementFinder {
306
292
  // screenshot size like `@driver.window_rect #=>x=0, y=0, width=1080, height=1794` and
307
293
  // `"deviceScreenSize"=>"1080x1920"`
308
294
  if (screenSize.width !== shotWidth && screenSize.height !== shotHeight) {
309
- logger_1.log.info(`Scaling screenshot from ${shotWidth}x${shotHeight} to match ` +
295
+ log.info(`Scaling screenshot from ${shotWidth}x${shotHeight} to match ` +
310
296
  `screen at ${screenSize.width}x${screenSize.height}`);
311
297
  imgObj = imgObj.resize({
312
298
  width: Math.trunc(screenSize.width),
@@ -334,15 +320,15 @@ class ImageElementFinder {
334
320
  if (!opts) {
335
321
  return template;
336
322
  }
337
- const { fixImageTemplateScale: fixTplScale = false, defaultImageTemplateScale: initialDefaultImageTemplateScale = constants_1.DEFAULT_TEMPLATE_IMAGE_SCALE, ignoreDefaultImageTemplateScale = false, xScale: initialXScale = constants_1.DEFAULT_FIX_IMAGE_TEMPLATE_SCALE, yScale: initialYScale = constants_1.DEFAULT_FIX_IMAGE_TEMPLATE_SCALE, } = opts;
323
+ const { fixImageTemplateScale: fixTplScale = false, defaultImageTemplateScale: initialDefaultImageTemplateScale = DEFAULT_TEMPLATE_IMAGE_SCALE, ignoreDefaultImageTemplateScale = false, xScale: initialXScale = DEFAULT_FIX_IMAGE_TEMPLATE_SCALE, yScale: initialYScale = DEFAULT_FIX_IMAGE_TEMPLATE_SCALE, } = opts;
338
324
  let defaultImageTemplateScale = initialDefaultImageTemplateScale;
339
325
  let xScale = initialXScale;
340
326
  let yScale = initialYScale;
341
327
  if (ignoreDefaultImageTemplateScale) {
342
- defaultImageTemplateScale = constants_1.DEFAULT_TEMPLATE_IMAGE_SCALE;
328
+ defaultImageTemplateScale = DEFAULT_TEMPLATE_IMAGE_SCALE;
343
329
  }
344
330
  // Default
345
- if (defaultImageTemplateScale === constants_1.DEFAULT_TEMPLATE_IMAGE_SCALE && !fixTplScale) {
331
+ if (defaultImageTemplateScale === DEFAULT_TEMPLATE_IMAGE_SCALE && !fixTplScale) {
346
332
  return template;
347
333
  }
348
334
  // Calculate xScale and yScale Appium should scale
@@ -358,19 +344,19 @@ class ImageElementFinder {
358
344
  return template;
359
345
  }
360
346
  // Return if the scale is default, 1, value
361
- if (Math.round(xScale * FLOAT_PRECISION) === Math.round(constants_1.DEFAULT_FIX_IMAGE_TEMPLATE_SCALE * FLOAT_PRECISION) &&
362
- Math.round(Number(yScale * FLOAT_PRECISION === Math.round(constants_1.DEFAULT_FIX_IMAGE_TEMPLATE_SCALE * FLOAT_PRECISION)))) {
347
+ if (Math.round(xScale * FLOAT_PRECISION) === Math.round(DEFAULT_FIX_IMAGE_TEMPLATE_SCALE * FLOAT_PRECISION) &&
348
+ Math.round(yScale * FLOAT_PRECISION) === Math.round(DEFAULT_FIX_IMAGE_TEMPLATE_SCALE * FLOAT_PRECISION)) {
363
349
  return template;
364
350
  }
365
- let imgObj = (0, sharp_1.default)(template);
351
+ let imgObj = sharp(template);
366
352
  const { width: baseTempWidth, height: baseTempHeigh } = await imgObj.metadata();
367
353
  if (baseTempWidth == null || baseTempHeigh == null) {
368
354
  throw new Error(`Template width/height cannot be determined. Is it a valid image?`);
369
355
  }
370
356
  const scaledWidth = baseTempWidth * xScale;
371
357
  const scaledHeight = baseTempHeigh * yScale;
372
- logger_1.log.info(`Scaling template image from ${baseTempWidth}x${baseTempHeigh} to ${scaledWidth}x${scaledHeight}`);
373
- logger_1.log.info(`The ratio is ${xScale} and ${yScale}`);
358
+ log.info(`Scaling template image from ${baseTempWidth}x${baseTempHeigh} to ${scaledWidth}x${scaledHeight}`);
359
+ log.info(`The ratio is ${xScale} and ${yScale}`);
374
360
  imgObj = imgObj.resize({
375
361
  width: Math.trunc(scaledWidth),
376
362
  height: Math.trunc(scaledHeight),
@@ -379,5 +365,4 @@ class ImageElementFinder {
379
365
  return await imgObj.toBuffer();
380
366
  }
381
367
  }
382
- exports.ImageElementFinder = ImageElementFinder;
383
368
  //# sourceMappingURL=finder.js.map