@rpascene/shared 0.30.8

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.
Files changed (177) hide show
  1. package/README.md +9 -0
  2. package/dist/es/baseDB.mjs +109 -0
  3. package/dist/es/build/copy-static.mjs +29 -0
  4. package/dist/es/common.mjs +37 -0
  5. package/dist/es/constants/example-code.mjs +202 -0
  6. package/dist/es/constants/index.mjs +74 -0
  7. package/dist/es/env/basic.mjs +6 -0
  8. package/dist/es/env/constants.mjs +97 -0
  9. package/dist/es/env/decide-model-config.mjs +172 -0
  10. package/dist/es/env/global-config-manager.mjs +82 -0
  11. package/dist/es/env/helper.mjs +45 -0
  12. package/dist/es/env/index.mjs +5 -0
  13. package/dist/es/env/init-debug.mjs +18 -0
  14. package/dist/es/env/model-config-manager.mjs +99 -0
  15. package/dist/es/env/parse.mjs +69 -0
  16. package/dist/es/env/types.mjs +265 -0
  17. package/dist/es/env/utils.mjs +18 -0
  18. package/dist/es/extractor/constants.mjs +2 -0
  19. package/dist/es/extractor/cs_postmessage.mjs +61 -0
  20. package/dist/es/extractor/customLocator.mjs +646 -0
  21. package/dist/es/extractor/debug.mjs +6 -0
  22. package/dist/es/extractor/dom-util.mjs +92 -0
  23. package/dist/es/extractor/index.mjs +7 -0
  24. package/dist/es/extractor/locator.mjs +95 -0
  25. package/dist/es/extractor/tree.mjs +81 -0
  26. package/dist/es/extractor/util.mjs +244 -0
  27. package/dist/es/extractor/web-extractor.mjs +361 -0
  28. package/dist/es/img/box-select.mjs +184 -0
  29. package/dist/es/img/draw-box.mjs +42 -0
  30. package/dist/es/img/get-jimp.mjs +10 -0
  31. package/dist/es/img/get-photon.mjs +19 -0
  32. package/dist/es/img/get-sharp.mjs +11 -0
  33. package/dist/es/img/index.mjs +5 -0
  34. package/dist/es/img/info.mjs +32 -0
  35. package/dist/es/img/transform.mjs +192 -0
  36. package/dist/es/index.mjs +3 -0
  37. package/dist/es/logger.mjs +61 -0
  38. package/dist/es/node/fs.mjs +44 -0
  39. package/dist/es/node/index.mjs +1 -0
  40. package/dist/es/polyfills/async-hooks.mjs +2 -0
  41. package/dist/es/polyfills/index.mjs +1 -0
  42. package/dist/es/types/index.mjs +3 -0
  43. package/dist/es/us-keyboard-layout.mjs +1414 -0
  44. package/dist/es/us-keyboard-layout.mjs.LICENSE.txt +5 -0
  45. package/dist/es/utils.mjs +66 -0
  46. package/dist/lib/baseDB.js +149 -0
  47. package/dist/lib/build/copy-static.js +77 -0
  48. package/dist/lib/common.js +93 -0
  49. package/dist/lib/constants/example-code.js +239 -0
  50. package/dist/lib/constants/index.js +153 -0
  51. package/dist/lib/env/basic.js +40 -0
  52. package/dist/lib/env/constants.js +143 -0
  53. package/dist/lib/env/decide-model-config.js +212 -0
  54. package/dist/lib/env/global-config-manager.js +116 -0
  55. package/dist/lib/env/helper.js +85 -0
  56. package/dist/lib/env/index.js +94 -0
  57. package/dist/lib/env/init-debug.js +52 -0
  58. package/dist/lib/env/model-config-manager.js +133 -0
  59. package/dist/lib/env/parse.js +106 -0
  60. package/dist/lib/env/types.js +650 -0
  61. package/dist/lib/env/utils.js +61 -0
  62. package/dist/lib/extractor/constants.js +42 -0
  63. package/dist/lib/extractor/cs_postmessage.js +98 -0
  64. package/dist/lib/extractor/customLocator.js +698 -0
  65. package/dist/lib/extractor/debug.js +12 -0
  66. package/dist/lib/extractor/dom-util.js +150 -0
  67. package/dist/lib/extractor/index.js +153 -0
  68. package/dist/lib/extractor/locator.js +141 -0
  69. package/dist/lib/extractor/tree.js +127 -0
  70. package/dist/lib/extractor/util.js +335 -0
  71. package/dist/lib/extractor/web-extractor.js +407 -0
  72. package/dist/lib/img/box-select.js +232 -0
  73. package/dist/lib/img/draw-box.js +89 -0
  74. package/dist/lib/img/get-jimp.js +72 -0
  75. package/dist/lib/img/get-photon.js +76 -0
  76. package/dist/lib/img/get-sharp.js +63 -0
  77. package/dist/lib/img/index.js +102 -0
  78. package/dist/lib/img/info.js +86 -0
  79. package/dist/lib/img/transform.js +279 -0
  80. package/dist/lib/index.js +43 -0
  81. package/dist/lib/logger.js +114 -0
  82. package/dist/lib/node/fs.js +97 -0
  83. package/dist/lib/node/index.js +60 -0
  84. package/dist/lib/polyfills/async-hooks.js +36 -0
  85. package/dist/lib/polyfills/index.js +60 -0
  86. package/dist/lib/types/index.js +37 -0
  87. package/dist/lib/us-keyboard-layout.js +1457 -0
  88. package/dist/lib/us-keyboard-layout.js.LICENSE.txt +5 -0
  89. package/dist/lib/utils.js +136 -0
  90. package/dist/types/baseDB.d.ts +25 -0
  91. package/dist/types/build/copy-static.d.ts +31 -0
  92. package/dist/types/common.d.ts +12 -0
  93. package/dist/types/constants/example-code.d.ts +2 -0
  94. package/dist/types/constants/index.d.ts +23 -0
  95. package/dist/types/env/basic.d.ts +6 -0
  96. package/dist/types/env/constants.d.ts +40 -0
  97. package/dist/types/env/decide-model-config.d.ts +14 -0
  98. package/dist/types/env/global-config-manager.d.ts +32 -0
  99. package/dist/types/env/helper.d.ts +6 -0
  100. package/dist/types/env/index.d.ts +4 -0
  101. package/dist/types/env/init-debug.d.ts +1 -0
  102. package/dist/types/env/model-config-manager.d.ts +24 -0
  103. package/dist/types/env/parse.d.ts +12 -0
  104. package/dist/types/env/types.d.ts +295 -0
  105. package/dist/types/env/utils.d.ts +7 -0
  106. package/dist/types/extractor/constants.d.ts +1 -0
  107. package/dist/types/extractor/cs_postmessage.d.ts +2 -0
  108. package/dist/types/extractor/customLocator.d.ts +69 -0
  109. package/dist/types/extractor/debug.d.ts +1 -0
  110. package/dist/types/extractor/dom-util.d.ts +26 -0
  111. package/dist/types/extractor/index.d.ts +36 -0
  112. package/dist/types/extractor/locator.d.ts +7 -0
  113. package/dist/types/extractor/tree.d.ts +9 -0
  114. package/dist/types/extractor/util.d.ts +43 -0
  115. package/dist/types/extractor/web-extractor.d.ts +19 -0
  116. package/dist/types/img/box-select.d.ts +25 -0
  117. package/dist/types/img/draw-box.d.ts +15 -0
  118. package/dist/types/img/get-jimp.d.ts +2 -0
  119. package/dist/types/img/get-photon.d.ts +8 -0
  120. package/dist/types/img/get-sharp.d.ts +3 -0
  121. package/dist/types/img/index.d.ts +4 -0
  122. package/dist/types/img/info.d.ts +29 -0
  123. package/dist/types/img/transform.d.ts +88 -0
  124. package/dist/types/index.d.ts +3 -0
  125. package/dist/types/logger.d.ts +4 -0
  126. package/dist/types/node/fs.d.ts +15 -0
  127. package/dist/types/node/index.d.ts +1 -0
  128. package/dist/types/polyfills/async-hooks.d.ts +6 -0
  129. package/dist/types/polyfills/index.d.ts +4 -0
  130. package/dist/types/types/index.d.ts +37 -0
  131. package/dist/types/us-keyboard-layout.d.ts +32 -0
  132. package/dist/types/utils.d.ts +22 -0
  133. package/package.json +102 -0
  134. package/src/baseDB.ts +158 -0
  135. package/src/build/copy-static.ts +62 -0
  136. package/src/common.ts +67 -0
  137. package/src/constants/example-code.ts +202 -0
  138. package/src/constants/index.ts +81 -0
  139. package/src/env/basic.ts +12 -0
  140. package/src/env/constants.ts +291 -0
  141. package/src/env/decide-model-config.ts +319 -0
  142. package/src/env/global-config-manager.ts +174 -0
  143. package/src/env/helper.ts +80 -0
  144. package/src/env/index.ts +4 -0
  145. package/src/env/init-debug.ts +29 -0
  146. package/src/env/model-config-manager.ts +145 -0
  147. package/src/env/parse.ts +131 -0
  148. package/src/env/types.ts +573 -0
  149. package/src/env/utils.ts +39 -0
  150. package/src/extractor/constants.ts +5 -0
  151. package/src/extractor/cs_postmessage.ts +101 -0
  152. package/src/extractor/customLocator.ts +1138 -0
  153. package/src/extractor/debug.ts +10 -0
  154. package/src/extractor/dom-util.ts +141 -0
  155. package/src/extractor/index.ts +54 -0
  156. package/src/extractor/locator.ts +179 -0
  157. package/src/extractor/tree.ts +179 -0
  158. package/src/extractor/util.ts +468 -0
  159. package/src/extractor/web-extractor.ts +559 -0
  160. package/src/img/box-select.ts +346 -0
  161. package/src/img/draw-box.ts +60 -0
  162. package/src/img/get-jimp.ts +12 -0
  163. package/src/img/get-photon.ts +48 -0
  164. package/src/img/get-sharp.ts +18 -0
  165. package/src/img/index.ts +24 -0
  166. package/src/img/info.ts +79 -0
  167. package/src/img/jimp.d.ts +4 -0
  168. package/src/img/transform.ts +396 -0
  169. package/src/index.ts +6 -0
  170. package/src/logger.ts +93 -0
  171. package/src/node/fs.ts +84 -0
  172. package/src/node/index.ts +1 -0
  173. package/src/polyfills/async-hooks.ts +6 -0
  174. package/src/polyfills/index.ts +4 -0
  175. package/src/types/index.ts +53 -0
  176. package/src/us-keyboard-layout.ts +723 -0
  177. package/src/utils.ts +127 -0
@@ -0,0 +1,698 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ getContainerPath: ()=>getContainerLocatorData,
28
+ getElements: ()=>getManyElementByLocators,
29
+ getFullLocator: ()=>getFullLocator,
30
+ getLocatorUntilFieldid: ()=>getLocatorUntilFieldid,
31
+ getLocators: ()=>getLocators,
32
+ getShadowRootContainerStack: ()=>getShadowRootContainerStack,
33
+ getUniqueElement: ()=>getOneElementByLocators
34
+ });
35
+ const attributeValue = (value)=>{
36
+ if (!value) return '';
37
+ if (value.indexOf("'") < 0) return "'" + value + "'";
38
+ {
39
+ if (value.indexOf('"') < 0) return '"' + value + '"';
40
+ let result = 'concat(';
41
+ let part = '';
42
+ let didReachEndOfValue = false;
43
+ while(!didReachEndOfValue){
44
+ let apos = value.indexOf("'");
45
+ let quot = value.indexOf('"');
46
+ if (apos < 0) {
47
+ result += "'" + value + "'";
48
+ didReachEndOfValue = true;
49
+ break;
50
+ }
51
+ if (quot < 0) {
52
+ result += '"' + value + '"';
53
+ didReachEndOfValue = true;
54
+ break;
55
+ }
56
+ if (quot < apos) {
57
+ part = value.substring(0, apos);
58
+ result += "'" + part + "'";
59
+ value = value.substring(part.length);
60
+ } else {
61
+ part = value.substring(0, quot);
62
+ result += '"' + part + '"';
63
+ value = value.substring(part.length);
64
+ }
65
+ result += ',';
66
+ }
67
+ result += ')';
68
+ return result;
69
+ }
70
+ };
71
+ const verifyXPath = (xpath, dom)=>{
72
+ const root = dom.getRootNode();
73
+ if (isShadowRoot(root)) return null;
74
+ if (xpath) {
75
+ const doms = getElementsByLocator({
76
+ type: 'xpath',
77
+ value: xpath
78
+ });
79
+ if (1 === doms.length && doms[0] === dom) return xpath;
80
+ }
81
+ return null;
82
+ };
83
+ const verifySelector = (selector, dom, type = 'querySelect')=>{
84
+ const root = dom.getRootNode();
85
+ const doms = getElementsByLocator({
86
+ type,
87
+ value: selector
88
+ }, root);
89
+ if (1 === doms.length && doms[0] === dom) return selector;
90
+ return null;
91
+ };
92
+ const isHostElement = (dom)=>{
93
+ var _dom_shadowRoot;
94
+ return (null == (_dom_shadowRoot = dom.shadowRoot) ? void 0 : _dom_shadowRoot.nodeName) === '#document-fragment';
95
+ };
96
+ const isShadowRoot = (node)=>'#document-fragment' === node.nodeName;
97
+ const getRelativeSelector = (dom, useFieldId = true)=>{
98
+ try {
99
+ const id = dom.id;
100
+ const fieldid = dom.getAttribute('fieldid');
101
+ const children = Array.from(dom.parentNode.childNodes).filter(($el)=>1 === $el.nodeType);
102
+ const index = children.findIndex((item)=>item === dom) + 1;
103
+ let extra = '';
104
+ if (useFieldId && fieldid) {
105
+ const sameAttrChildren = children.filter(($el)=>$el.tagName === dom.tagName && $el.getAttribute('fieldid') === fieldid);
106
+ extra = 1 === sameAttrChildren.length ? `[fieldid='${fieldid}']` : `[fieldid='${fieldid}']:nth-child(${index})`;
107
+ } else if (!useFieldId && id) {
108
+ const sameAttrChildren = children.filter(($el)=>$el.tagName === dom.tagName && $el.id === id);
109
+ extra = 1 === sameAttrChildren.length ? `[id='${id}']` : `[id='${id}']:nth-child(${index})`;
110
+ } else {
111
+ const sameTagChildren = children.filter(($el)=>$el.tagName === dom.tagName);
112
+ extra = 1 === sameTagChildren.length ? '' : `:nth-child(${index})`;
113
+ }
114
+ return dom.tagName.toLowerCase() + extra;
115
+ } catch (error) {
116
+ console.error(error);
117
+ return '';
118
+ }
119
+ };
120
+ const getRelativeXpath = (dom, useFieldId = true)=>{
121
+ try {
122
+ if (!dom || 1 !== dom.nodeType) return '';
123
+ if ('OPTION' === dom.tagName) return '';
124
+ const root = dom.getRootNode();
125
+ if (isShadowRoot(root)) return '';
126
+ const id = dom.id;
127
+ const fieldid = dom.getAttribute('fieldid');
128
+ const children = Array.from(dom.parentNode.childNodes).filter(($el)=>1 === $el.nodeType);
129
+ const tagName = dom.tagName.toLowerCase();
130
+ const isDescendantOfSVG = null !== dom.closest('svg');
131
+ let extra = '';
132
+ if (useFieldId && fieldid) {
133
+ const sameAttrChildren = children.filter(($el)=>$el.tagName === dom.tagName && $el.getAttribute('fieldid') === fieldid);
134
+ if (isDescendantOfSVG) {
135
+ if (1 === sameAttrChildren.length) return `/*[name()='${tagName}' and @fieldid='${fieldid}']`;
136
+ const index = sameAttrChildren.findIndex((item)=>item === dom) + 1;
137
+ return `/*[name()='${tagName}' and @fieldid='${fieldid}'][${index}]`;
138
+ }
139
+ if (1 === sameAttrChildren.length) extra = `[@fieldid='${fieldid}']`;
140
+ else {
141
+ const index = sameAttrChildren.findIndex((item)=>item === dom) + 1;
142
+ extra = `[@fieldid='${fieldid}'][${index}]`;
143
+ }
144
+ } else if (!useFieldId && id) {
145
+ const sameAttrChildren = children.filter(($el)=>$el.tagName === dom.tagName && $el.id === id);
146
+ if (isDescendantOfSVG) {
147
+ if (1 === sameAttrChildren.length) return `/*[name()='${tagName}' and @id='${id}']`;
148
+ const index = sameAttrChildren.findIndex((item)=>item === dom) + 1;
149
+ return `/*[name()='${tagName}' and @id='${id}'][${index}]`;
150
+ }
151
+ if (1 === sameAttrChildren.length) extra = `[@id='${id}']`;
152
+ else {
153
+ const index = sameAttrChildren.findIndex((item)=>item === dom) + 1;
154
+ extra = `[@id='${id}'][${index}]`;
155
+ }
156
+ } else {
157
+ const sameAttrChildren = children.filter(($el)=>$el.tagName === dom.tagName);
158
+ if (isDescendantOfSVG) {
159
+ if (1 === sameAttrChildren.length) return `/*[name()='${tagName}']`;
160
+ const index = sameAttrChildren.findIndex((item)=>item === dom) + 1;
161
+ return `/*[name()='${tagName}'][${index}]`;
162
+ }
163
+ if (1 === sameAttrChildren.length) extra = '';
164
+ else {
165
+ const index = sameAttrChildren.findIndex((item)=>item === dom) + 1;
166
+ extra = `[${index}]`;
167
+ }
168
+ }
169
+ return '/' + dom.tagName.toLowerCase() + extra;
170
+ } catch (error) {
171
+ console.error(error);
172
+ return '';
173
+ }
174
+ };
175
+ const getElementsByXPath = (xpath, contextNode = document)=>{
176
+ try {
177
+ if ('#document' !== contextNode.nodeName && '#document' !== contextNode.getRootNode().nodeName) return null;
178
+ const snapshot = document.evaluate(xpath, contextNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
179
+ const list = [];
180
+ for(let i = 0, len = snapshot.snapshotLength; i < len; i++)list.push(snapshot.snapshotItem(i));
181
+ return list;
182
+ } catch (error) {
183
+ console.error(error);
184
+ return [];
185
+ }
186
+ };
187
+ const getElementsByLocator = (locator, docOrHost = document)=>{
188
+ try {
189
+ const { type, value } = locator;
190
+ let eles = [];
191
+ const contextNode = docOrHost.shadowRoot || docOrHost;
192
+ if ('id' === type) eles = contextNode.querySelectorAll(`*[id='${value}']`);
193
+ else if ('className' === type) eles = contextNode.querySelectorAll(`*[class='${value}']`);
194
+ else if ('name' === type) eles = contextNode.querySelectorAll(`*[name='${value}']`);
195
+ else if ('querySelect' === type) eles = contextNode.querySelectorAll(value);
196
+ else if ('xpath' === type) eles = getElementsByXPath(value, contextNode) || [];
197
+ return Array.from(eles);
198
+ } catch (error) {
199
+ console.error(error);
200
+ return [];
201
+ }
202
+ };
203
+ const getBaseSelectors = (dom)=>{
204
+ const locators = [];
205
+ const { id, name, classList } = dom;
206
+ if (id) locators.push({
207
+ type: 'id',
208
+ value: id
209
+ });
210
+ if (name) locators.push({
211
+ type: 'name',
212
+ value: name
213
+ });
214
+ return locators;
215
+ };
216
+ const getLocatorUntilFieldid = (dom, type)=>{
217
+ const getXpathUntilFieldid = (dom)=>{
218
+ try {
219
+ if (!dom || 1 !== dom.nodeType) return '';
220
+ const useFieldId = !!document.querySelector('*[fieldid]');
221
+ const relativeXpath = getRelativeXpath(dom, useFieldId);
222
+ if (useFieldId && relativeXpath.includes('textCol|')) return '';
223
+ if (/\[@/g.test(relativeXpath)) return '/' + relativeXpath;
224
+ return getXpathUntilFieldid(dom.parentNode) + relativeXpath;
225
+ } catch (error) {
226
+ console.error(error);
227
+ return '';
228
+ }
229
+ };
230
+ const getSelectorUntilFieldid = (dom)=>{
231
+ try {
232
+ if (!dom || 1 !== dom.nodeType) return '';
233
+ const useFieldId = !!document.querySelector('*[fieldid]');
234
+ const relativeSelector = getRelativeSelector(dom, useFieldId);
235
+ if (useFieldId && relativeSelector.includes('textCol|')) return '';
236
+ if (relativeSelector.includes('id=') || relativeSelector.includes('fieldid=')) return relativeSelector;
237
+ const parentSelector = getSelectorUntilFieldid(dom.parentNode);
238
+ return parentSelector ? parentSelector + ' > ' + relativeSelector : relativeSelector;
239
+ } catch (error) {
240
+ console.error(error);
241
+ return '';
242
+ }
243
+ };
244
+ if ('xpath' === type) return {
245
+ type: 'xpath',
246
+ value: getXpathUntilFieldid(dom)
247
+ };
248
+ if ('querySelect' === type) return {
249
+ type: 'querySelect',
250
+ value: getSelectorUntilFieldid(dom)
251
+ };
252
+ const value = getXpathUntilFieldid(dom);
253
+ if (value) return {
254
+ type: 'xpath',
255
+ value
256
+ };
257
+ return {
258
+ type: 'querySelect',
259
+ value: getSelectorUntilFieldid(dom)
260
+ };
261
+ };
262
+ const getFullLocator = (dom, type)=>{
263
+ const getFullXpath = (dom)=>{
264
+ try {
265
+ if (!dom || 1 !== dom.nodeType) return '';
266
+ if ('OPTION' === dom.tagName) return '';
267
+ const root = dom.getRootNode();
268
+ if ('#document-fragment' === root.nodeName) return '';
269
+ if ('BODY' === dom.tagName) return '/html/body';
270
+ if ('HTML' === dom.tagName) return '/html';
271
+ const sameTagChildren = Array.from(dom.parentNode.childNodes).filter(($el)=>1 === $el.nodeType && $el.tagName === dom.tagName);
272
+ let extra = '';
273
+ if (1 === sameTagChildren.length) extra = '';
274
+ else {
275
+ const index = sameTagChildren.findIndex((item)=>item === dom) + 1;
276
+ extra = `[${index}]`;
277
+ }
278
+ const lowerTagName = dom.tagName.toLowerCase();
279
+ const isDescendantOfSVG = null !== dom.closest('svg');
280
+ const me = (isDescendantOfSVG ? `*[name()='${lowerTagName}']` : lowerTagName) + extra;
281
+ return getFullXpath(dom.parentNode) + '/' + me;
282
+ } catch (error) {
283
+ console.error(error);
284
+ return '';
285
+ }
286
+ };
287
+ const getFullSelector = (dom)=>{
288
+ try {
289
+ if (!dom || 1 !== dom.nodeType) return '';
290
+ if ('OPTION' === dom.tagName) return '';
291
+ if ('BODY' === dom.tagName) return 'body';
292
+ if ('HTML' === dom.tagName) return 'html';
293
+ const children = Array.from(dom.parentNode.childNodes).filter(($el)=>1 === $el.nodeType);
294
+ const sameTagChildren = children.filter(($el)=>$el.tagName === dom.tagName);
295
+ let extra = '';
296
+ if (1 === sameTagChildren.length) extra = '';
297
+ else {
298
+ const index = children.findIndex((item)=>item === dom) + 1;
299
+ extra = `:nth-child(${index})`;
300
+ }
301
+ const me = dom.tagName.toLowerCase() + extra;
302
+ const parentSelector = getFullSelector(dom.parentNode);
303
+ return parentSelector ? parentSelector + ' > ' + me : me;
304
+ } catch (error) {
305
+ console.error(error);
306
+ return '';
307
+ }
308
+ };
309
+ if ('xpath' === type) return {
310
+ type: 'xpath',
311
+ value: getFullXpath(dom)
312
+ };
313
+ if ('querySelect' === type) return {
314
+ type: 'querySelect',
315
+ value: getFullSelector(dom)
316
+ };
317
+ const value = getFullXpath(dom);
318
+ if (value) return {
319
+ type: 'xpath',
320
+ value
321
+ };
322
+ return {
323
+ type: 'querySelect',
324
+ value: getFullSelector(dom)
325
+ };
326
+ };
327
+ const getPositionLocator = (ele)=>{
328
+ const getPositionXPath = (ele)=>{
329
+ try {
330
+ if (!ele || 1 !== ele.nodeType) return '';
331
+ if ('OPTION' === ele.tagName) return '';
332
+ const root = ele.getRootNode();
333
+ if (isShadowRoot(root)) return '';
334
+ const useFieldId = !!document.querySelector('*[fieldid]');
335
+ let path = '';
336
+ let dom = ele;
337
+ while(dom && 1 === dom.nodeType){
338
+ let currentPath = '';
339
+ currentPath = 'BODY' === dom.tagName ? '/body' : 'HTML' === dom.tagName ? '/html' : getRelativeXpath(dom, useFieldId);
340
+ path = currentPath + path;
341
+ const locator = '/' + path;
342
+ if (useFieldId && locator.includes('textCol|')) return '';
343
+ if (verifyXPath(locator, ele)) return locator;
344
+ dom = dom.parentNode;
345
+ }
346
+ return path;
347
+ } catch (error) {
348
+ console.error(error);
349
+ return '';
350
+ }
351
+ };
352
+ const getPositionSelector = (ele)=>{
353
+ try {
354
+ let path = '';
355
+ let dom = ele;
356
+ if (dom && 'OPTION' === dom.tagName) return '';
357
+ const useFieldId = !!document.querySelector('*[fieldid]');
358
+ while(dom && 1 === dom.nodeType){
359
+ let currentPath;
360
+ currentPath = 'BODY' === dom.tagName ? 'body' : 'HTML' === dom.tagName ? 'html' : getRelativeSelector(dom, useFieldId);
361
+ path = path ? currentPath + ' > ' + path : currentPath;
362
+ if (useFieldId && path.includes('textCol|')) return '';
363
+ if (verifySelector(path, ele)) break;
364
+ dom = dom.parentNode;
365
+ }
366
+ return path;
367
+ } catch (error) {
368
+ console.error(error);
369
+ return '';
370
+ }
371
+ };
372
+ const value = getPositionXPath(ele);
373
+ if (value) return {
374
+ type: 'xpath',
375
+ value
376
+ };
377
+ return {
378
+ type: 'querySelect',
379
+ value: getPositionSelector(ele)
380
+ };
381
+ };
382
+ const getFirstText = (ele)=>{
383
+ var _texts_;
384
+ const texts = Array.from(ele.childNodes).filter((n)=>3 === n.nodeType).filter((node)=>node.textContent && node.textContent.trim() && !/[\{\}\"\'\\\/]/.test(node.textContent) && node.textContent.trim().length < 30);
385
+ return (null == (_texts_ = texts[0]) ? void 0 : _texts_.textContent) || null;
386
+ };
387
+ const getXpathWidthText = (dom)=>{
388
+ if (!dom || 1 !== dom.nodeType) return '';
389
+ const root = dom.getRootNode();
390
+ if (isShadowRoot(root)) return '';
391
+ let locator = '';
392
+ let text = getFirstText(dom);
393
+ if (text) locator = text.length < 30 ? `//${dom.nodeName.toLowerCase()}[text()=${attributeValue(text)}]` : `//${dom.nodeName.toLowerCase()}[contains(text(),${attributeValue(text.slice(0, 30))})]`;
394
+ return verifyXPath(locator, dom);
395
+ };
396
+ const getXpathWidthInnerText = (dom)=>{
397
+ try {
398
+ if (!dom || 1 !== dom.nodeType) return null;
399
+ const root = dom.getRootNode();
400
+ if (isShadowRoot(root)) return null;
401
+ const text = dom.textContent.replace(/\s+/g, ' ');
402
+ if (text && text.length < 30) {
403
+ const escapedText = text.replace(/"/g, '\\"').replace(/'/g, "\\'");
404
+ const tagName = dom.tagName.toLowerCase();
405
+ let parentNode = dom.parentNode;
406
+ let extra = `/${tagName}`;
407
+ while(parentNode){
408
+ let parentNodeName = parentNode.nodeName.toLowerCase();
409
+ if (parentNodeName !== tagName) break;
410
+ extra = `/${parentNodeName}${extra}`;
411
+ parentNode = parentNode.parentNode;
412
+ }
413
+ const locator = `/${extra}[contains(.,'${escapedText}')]`;
414
+ return verifyXPath(locator, dom);
415
+ }
416
+ return null;
417
+ } catch (error) {
418
+ console.error(error);
419
+ return null;
420
+ }
421
+ };
422
+ const getLocatorUntilAllFieldid = (ele)=>{
423
+ const getXpathUntilAllFieldid = (ele)=>{
424
+ try {
425
+ if (!ele || 1 !== ele.nodeType) return '';
426
+ const root = ele.getRootNode();
427
+ if (isShadowRoot(root)) return '';
428
+ const useFieldId = !!document.querySelector('*[fieldid]');
429
+ let path = '';
430
+ let dom = ele;
431
+ while(dom && 1 === dom.nodeType){
432
+ if (useFieldId && path.includes('textCol|') && !dom.getAttribute('childrenfield')) {
433
+ dom = dom.parentNode;
434
+ continue;
435
+ }
436
+ const currentPath = getRelativeXpath(dom, useFieldId);
437
+ if (currentPath) if (/\[@/g.test(path)) {
438
+ if (/\[@/g.test(path) && /\[@/g.test(currentPath) && !path.startsWith('//')) path = '/' + currentPath + '/' + path;
439
+ else if (/\[@/g.test(path) && /\[@/g.test(currentPath)) path = '/' + currentPath + path;
440
+ } else path = currentPath + path;
441
+ const count = (path.match(/\[@/g) || []).length;
442
+ if (count >= 2) break;
443
+ dom = dom.parentNode;
444
+ }
445
+ if (path && !path.startsWith('//')) path = '/' + path;
446
+ return path;
447
+ } catch (error) {
448
+ console.error(error);
449
+ return '';
450
+ }
451
+ };
452
+ const getSelectorUntilAllFieldid = (ele)=>{
453
+ try {
454
+ if (!ele || 1 !== ele.nodeType) return '';
455
+ const root = ele.getRootNode();
456
+ if (isShadowRoot(root)) return '';
457
+ const useFieldId = !!document.querySelector('*[fieldid]');
458
+ let path = '';
459
+ let dom = ele;
460
+ while(dom && 1 === dom.nodeType){
461
+ if (useFieldId && path.includes('textCol|') && !dom.getAttribute('childrenfield')) {
462
+ dom = dom.parentNode;
463
+ continue;
464
+ }
465
+ const currentPath = getRelativeSelector(dom, useFieldId);
466
+ if (currentPath) if (/\[fieldid|\[id/g.test(path)) {
467
+ if (/\[fieldid|\[id/g.test(path) && /\[fieldid|\[id/g.test(currentPath)) path = currentPath + ' ' + path;
468
+ } else path = path ? currentPath + ' > ' + path : currentPath;
469
+ const count = (path.match(/\[fieldid|\[id/g) || []).length;
470
+ if (count >= 2) break;
471
+ dom = dom.parentNode;
472
+ }
473
+ return path;
474
+ } catch (error) {
475
+ console.error(error);
476
+ return '';
477
+ }
478
+ };
479
+ const value = getXpathUntilAllFieldid(ele);
480
+ if (value) return {
481
+ type: 'xpath',
482
+ value
483
+ };
484
+ return {
485
+ type: 'querySelect',
486
+ value: getSelectorUntilAllFieldid(ele)
487
+ };
488
+ };
489
+ const getContainerLocatorUntilAllFieldid = (ele)=>{
490
+ const getContainerXpathUntilAllFieldid = (ele)=>{
491
+ try {
492
+ if (!ele || 1 !== ele.nodeType) return '';
493
+ const root = ele.getRootNode();
494
+ if (isShadowRoot(root)) return '';
495
+ const useFieldId = !!document.querySelector('*[fieldid]');
496
+ let path = '';
497
+ let dom = ele;
498
+ while(dom && 1 === dom.nodeType){
499
+ const currentPath = getRelativeXpath(dom, useFieldId);
500
+ if ('IFRAME' === dom.tagName || 'FRAME' === dom.tagName || dom.shadowRoot || /\[@/g.test(currentPath)) path = '/' + currentPath + path;
501
+ const count = (path.match(/\[@/g) || []).length;
502
+ if (count >= 1) break;
503
+ dom = dom.parentNode;
504
+ }
505
+ if (!path.startsWith('//')) path = '/' + path;
506
+ return path;
507
+ } catch (error) {
508
+ console.error(error);
509
+ return '';
510
+ }
511
+ };
512
+ const getContainerSelectorUntilAllFieldid = (ele)=>{
513
+ try {
514
+ if (!ele || 1 !== ele.nodeType) return '';
515
+ const root = ele.getRootNode();
516
+ if (isShadowRoot(root)) return '';
517
+ const useFieldId = !!document.querySelector('*[fieldid]');
518
+ let path = '';
519
+ let dom = ele;
520
+ while(dom && 1 === dom.nodeType){
521
+ const currentPath = getRelativeSelector(dom, useFieldId);
522
+ if ('IFRAME' === dom.tagName || 'FRAME' === dom.tagName || dom.shadowRoot || /\[fieldid|\[id/g.test(currentPath)) path = path ? currentPath + " " + path : currentPath;
523
+ const count = (path.match(/\[fieldid|\[id/g) || []).length;
524
+ if (count >= 1) break;
525
+ dom = dom.parentNode;
526
+ }
527
+ return path;
528
+ } catch (error) {
529
+ console.error(error);
530
+ return '';
531
+ }
532
+ };
533
+ const value = getContainerXpathUntilAllFieldid(ele);
534
+ if (value) return {
535
+ type: 'xpath',
536
+ value
537
+ };
538
+ return {
539
+ type: 'querySelect',
540
+ value: getContainerSelectorUntilAllFieldid(ele)
541
+ };
542
+ };
543
+ const notExit = (locators, type, value)=>{
544
+ if (!value) return false;
545
+ return !locators.find((item)=>item.type === type && item.value === value);
546
+ };
547
+ const getLocators = (dom)=>{
548
+ const locators = getBaseSelectors(dom);
549
+ const locatorByGetLocatorUntilFieldid = getLocatorUntilFieldid(dom);
550
+ if (notExit(locators, locatorByGetLocatorUntilFieldid.type, locatorByGetLocatorUntilFieldid.value)) locators.push(locatorByGetLocatorUntilFieldid);
551
+ const locatorByGetLocatorUntilAllFieldid = getLocatorUntilAllFieldid(dom);
552
+ if (notExit(locators, locatorByGetLocatorUntilAllFieldid.type, locatorByGetLocatorUntilAllFieldid.value)) locators.push(locatorByGetLocatorUntilAllFieldid);
553
+ const locatorByGetPositionLocator = getPositionLocator(dom);
554
+ if (notExit(locators, locatorByGetPositionLocator.type, locatorByGetPositionLocator.value)) locators.push(locatorByGetPositionLocator);
555
+ const textXPathValue = getXpathWidthText(dom);
556
+ if (notExit(locators, 'xpath', textXPathValue)) locators.push({
557
+ type: 'xpath',
558
+ value: textXPathValue
559
+ });
560
+ const innerTextXpathValue = getXpathWidthInnerText(dom);
561
+ if (notExit(locators, 'xpath', innerTextXpathValue)) locators.push({
562
+ type: 'xpath',
563
+ value: innerTextXpathValue
564
+ });
565
+ const sortedLocators = sortLocators(locators);
566
+ const list = getLocatorsWidthIndex(sortedLocators, dom);
567
+ return list;
568
+ };
569
+ const sortLocators = (locators)=>locators.slice().sort((a, b)=>{
570
+ const valueA = a.value;
571
+ const valueB = b.value;
572
+ const hasFieldIdA = valueA.includes('@fieldid');
573
+ const hasFieldIdB = valueB.includes('@fieldid');
574
+ const hasIdA = valueA.includes('@id') && !hasFieldIdA;
575
+ const hasIdB = valueB.includes('@id') && !hasFieldIdB;
576
+ if (hasFieldIdA !== hasFieldIdB) return hasFieldIdA ? -1 : 1;
577
+ if (hasIdA !== hasIdB) return hasIdA ? -1 : 1;
578
+ if (a.type !== b.type) return 'xpath' === a.type ? -1 : 1;
579
+ if (hasFieldIdA) {
580
+ const countA = (valueA.match(/\[@fieldid/g) || []).length;
581
+ const countB = (valueB.match(/\[@fieldid/g) || []).length;
582
+ return countA - countB;
583
+ }
584
+ if (!hasIdA) return valueA.length - valueB.length;
585
+ {
586
+ const countA = (valueA.match(/\[@id/g) || []).length;
587
+ const countB = (valueB.match(/\[@id/g) || []).length;
588
+ return countA - countB;
589
+ }
590
+ });
591
+ const getContainerLocators = (dom)=>{
592
+ if (!dom || !isHostElement(dom) && 'IFRAME' !== dom.nodeName && 'FRAME' !== dom.nodeName) return [];
593
+ const locators = getBaseSelectors(dom);
594
+ const locatorByGetContainerLocatorUntilAllFieldid = getContainerLocatorUntilAllFieldid(dom);
595
+ if (notExit(locators, locatorByGetContainerLocatorUntilAllFieldid.type, locatorByGetContainerLocatorUntilAllFieldid.value)) locators.push(locatorByGetContainerLocatorUntilAllFieldid);
596
+ const locatorByGetPositionLocator = getPositionLocator(dom);
597
+ if (notExit(locators, locatorByGetPositionLocator.type, locatorByGetPositionLocator.value)) locators.push(locatorByGetPositionLocator);
598
+ const sortedLocators = sortLocators(locators);
599
+ const containerAllPaths = getLocatorsWidthIndex(sortedLocators, dom);
600
+ return containerAllPaths;
601
+ };
602
+ const getContainerLocatorData = (dom)=>{
603
+ var _containerAllPaths_, _containerAllPaths_1, _containerAllPaths_2;
604
+ const containerAllPaths = getContainerLocators(dom);
605
+ const containerType = dom.shadowRoot ? 'shadowRoot' : 'iframe';
606
+ return {
607
+ containerAllPaths,
608
+ containerType,
609
+ containerPathType: (null == (_containerAllPaths_ = containerAllPaths[0]) ? void 0 : _containerAllPaths_.type) || '',
610
+ containerPathValue: (null == (_containerAllPaths_1 = containerAllPaths[0]) ? void 0 : _containerAllPaths_1.value) || '',
611
+ containerPathIndex: (null == (_containerAllPaths_2 = containerAllPaths[0]) ? void 0 : _containerAllPaths_2.index) ?? 1
612
+ };
613
+ };
614
+ const getLocatorsWidthIndex = (locators, dom)=>{
615
+ const rootNode = dom.getRootNode();
616
+ const list = locators.map((item)=>{
617
+ const eles = getElementsByLocator(item, rootNode);
618
+ const eleIndex = eles.findIndex((el)=>el === dom);
619
+ if (-1 === eleIndex || eles.length > 5) return null;
620
+ return {
621
+ ...item,
622
+ index: eleIndex + 1
623
+ };
624
+ }).filter(Boolean);
625
+ if (0 === list.length) {
626
+ const locatorByGetFullLocator = getFullLocator(dom);
627
+ if (locatorByGetFullLocator.value) list.push({
628
+ type: locatorByGetFullLocator.type,
629
+ value: locatorByGetFullLocator.value,
630
+ index: 1
631
+ });
632
+ }
633
+ return list.map((item, index)=>({
634
+ ...item,
635
+ isSelected: 0 === index,
636
+ orderNum: index
637
+ }));
638
+ };
639
+ const getManyElementByLocators = (docOrHost = document, locators, selected = true)=>{
640
+ if (selected) {
641
+ const selectedLocator = locators.find((item)=>item.isSelected) || locators[0];
642
+ if (selectedLocator) return getElementsByLocator(selectedLocator, docOrHost);
643
+ } else {
644
+ const elements = locators.map((item)=>getElementsByLocator(item, docOrHost)).flat();
645
+ return Array.from(new Set(elements));
646
+ }
647
+ return [];
648
+ };
649
+ const getOneElementByLocators = (docOrHost, locators, selected = true)=>{
650
+ if (selected) {
651
+ const selectedLocator = locators.find((item)=>item.isSelected) || locators[0];
652
+ if (selectedLocator) {
653
+ const index = Math.max(0, (selectedLocator.index ?? 1) - 1);
654
+ return getElementsByLocator(selectedLocator, docOrHost)[index] || null;
655
+ }
656
+ } else {
657
+ let ele = null;
658
+ for(let i = 0; i < locators.length; i += 1){
659
+ const index = Math.max(0, (locators[i].index ?? 1) - 1);
660
+ ele = getElementsByLocator(locators[i], docOrHost)[index] || null;
661
+ if (ele) break;
662
+ }
663
+ return ele;
664
+ }
665
+ return null;
666
+ };
667
+ const getShadowRootContainerStack = (dom)=>{
668
+ const containers = [];
669
+ let ele = dom;
670
+ while(ele){
671
+ const rootNode = ele.getRootNode();
672
+ ele = rootNode.host;
673
+ if (ele) {
674
+ const container = getContainerLocatorData(ele);
675
+ containers.unshift(container);
676
+ } else break;
677
+ }
678
+ return containers;
679
+ };
680
+ exports.getContainerPath = __webpack_exports__.getContainerPath;
681
+ exports.getElements = __webpack_exports__.getElements;
682
+ exports.getFullLocator = __webpack_exports__.getFullLocator;
683
+ exports.getLocatorUntilFieldid = __webpack_exports__.getLocatorUntilFieldid;
684
+ exports.getLocators = __webpack_exports__.getLocators;
685
+ exports.getShadowRootContainerStack = __webpack_exports__.getShadowRootContainerStack;
686
+ exports.getUniqueElement = __webpack_exports__.getUniqueElement;
687
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
688
+ "getContainerPath",
689
+ "getElements",
690
+ "getFullLocator",
691
+ "getLocatorUntilFieldid",
692
+ "getLocators",
693
+ "getShadowRootContainerStack",
694
+ "getUniqueElement"
695
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
696
+ Object.defineProperty(exports, '__esModule', {
697
+ value: true
698
+ });