@whitesev/domutils 1.8.4 → 1.8.6

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.amd.js CHANGED
@@ -517,7 +517,7 @@ define((function () { 'use strict';
517
517
  },
518
518
  };
519
519
 
520
- const version = "1.8.3";
520
+ const version = "1.8.6";
521
521
 
522
522
  class ElementSelector {
523
523
  windowApi;
@@ -531,7 +531,18 @@ define((function () { 'use strict';
531
531
  const context = this;
532
532
  parent = parent || context.windowApi.document;
533
533
  selector = selector.trim();
534
- if (selector.match(/[^\s]{1}:empty$/gi)) {
534
+ if (selector.startsWith("xpath:")) {
535
+ selector = selector.replace(/^xpath:/i, "");
536
+ const xpathResult = context.windowApi.document.evaluate(selector, parent, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
537
+ const result = [];
538
+ let iterateNext = xpathResult.iterateNext();
539
+ while (iterateNext) {
540
+ result.push(iterateNext);
541
+ iterateNext = xpathResult.iterateNext();
542
+ }
543
+ return result;
544
+ }
545
+ else if (selector.match(/[^\s]{1}:empty$/gi)) {
535
546
  // empty 语法
536
547
  selector = selector.replace(/:empty$/gi, "");
537
548
  return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
@@ -1057,7 +1068,7 @@ define((function () { 'use strict';
1057
1068
  // 超时时间
1058
1069
  let timeout = 0;
1059
1070
  if (typeof args[0] !== "string" && !Array.isArray(args[0]) && typeof args[0] !== "function") {
1060
- throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
1071
+ throw new TypeError("DOMUtils.waitNode 第一个参数必须是string|string[]|Function");
1061
1072
  }
1062
1073
  if (args.length === 1) ;
1063
1074
  else if (args.length === 2) {
@@ -1071,7 +1082,7 @@ define((function () { 'use strict';
1071
1082
  parent = secondParam;
1072
1083
  }
1073
1084
  else {
1074
- throw new TypeError("Utils.waitNode 第二个参数必须是number|Node");
1085
+ throw new TypeError("DOMUtils.waitNode 第二个参数必须是number|Node");
1075
1086
  }
1076
1087
  }
1077
1088
  else if (args.length === 3) {
@@ -1086,15 +1097,15 @@ define((function () { 'use strict';
1086
1097
  timeout = thirdParam;
1087
1098
  }
1088
1099
  else {
1089
- throw new TypeError("Utils.waitNode 第三个参数必须是number");
1100
+ throw new TypeError("DOMUtils.waitNode 第三个参数必须是number");
1090
1101
  }
1091
1102
  }
1092
1103
  else {
1093
- throw new TypeError("Utils.waitNode 第二个参数必须是Node");
1104
+ throw new TypeError("DOMUtils.waitNode 第二个参数必须是Node");
1094
1105
  }
1095
1106
  }
1096
1107
  else {
1097
- throw new TypeError("Utils.waitNode 参数个数错误");
1108
+ throw new TypeError("DOMUtils.waitNode 参数个数错误");
1098
1109
  }
1099
1110
  function getNode() {
1100
1111
  if (Array.isArray(selector)) {
@@ -1143,7 +1154,7 @@ define((function () { 'use strict';
1143
1154
  // 超时时间
1144
1155
  let timeout = 0;
1145
1156
  if (typeof args[0] !== "object" && !Array.isArray(args[0])) {
1146
- throw new TypeError("Utils.waitAnyNode 第一个参数必须是string[]");
1157
+ throw new TypeError("DOMUtils.waitAnyNode 第一个参数必须是string[]");
1147
1158
  }
1148
1159
  if (args.length === 1) ;
1149
1160
  else if (args.length === 2) {
@@ -1157,7 +1168,7 @@ define((function () { 'use strict';
1157
1168
  parent = secondParam;
1158
1169
  }
1159
1170
  else {
1160
- throw new TypeError("Utils.waitAnyNode 第二个参数必须是number|Node");
1171
+ throw new TypeError("DOMUtils.waitAnyNode 第二个参数必须是number|Node");
1161
1172
  }
1162
1173
  }
1163
1174
  else if (args.length === 3) {
@@ -1172,15 +1183,15 @@ define((function () { 'use strict';
1172
1183
  timeout = thirdParam;
1173
1184
  }
1174
1185
  else {
1175
- throw new TypeError("Utils.waitAnyNode 第三个参数必须是number");
1186
+ throw new TypeError("DOMUtils.waitAnyNode 第三个参数必须是number");
1176
1187
  }
1177
1188
  }
1178
1189
  else {
1179
- throw new TypeError("Utils.waitAnyNode 第二个参数必须是Node");
1190
+ throw new TypeError("DOMUtils.waitAnyNode 第二个参数必须是Node");
1180
1191
  }
1181
1192
  }
1182
1193
  else {
1183
- throw new TypeError("Utils.waitAnyNode 参数个数错误");
1194
+ throw new TypeError("DOMUtils.waitAnyNode 参数个数错误");
1184
1195
  }
1185
1196
  const promiseList = selectorList.map((selector) => {
1186
1197
  return UtilsContext.waitNode(selector, parent, timeout);
@@ -1198,7 +1209,7 @@ define((function () { 'use strict';
1198
1209
  // 超时时间
1199
1210
  let timeout = 0;
1200
1211
  if (typeof args[0] !== "string" && !Array.isArray(args[0])) {
1201
- throw new TypeError("Utils.waitNodeList 第一个参数必须是string|string[]");
1212
+ throw new TypeError("DOMUtils.waitNodeList 第一个参数必须是string|string[]");
1202
1213
  }
1203
1214
  if (args.length === 1) ;
1204
1215
  else if (args.length === 2) {
@@ -1212,7 +1223,7 @@ define((function () { 'use strict';
1212
1223
  parent = secondParam;
1213
1224
  }
1214
1225
  else {
1215
- throw new TypeError("Utils.waitNodeList 第二个参数必须是number|Node");
1226
+ throw new TypeError("DOMUtils.waitNodeList 第二个参数必须是number|Node");
1216
1227
  }
1217
1228
  }
1218
1229
  else if (args.length === 3) {
@@ -1227,15 +1238,15 @@ define((function () { 'use strict';
1227
1238
  timeout = thirdParam;
1228
1239
  }
1229
1240
  else {
1230
- throw new TypeError("Utils.waitNodeList 第三个参数必须是number");
1241
+ throw new TypeError("DOMUtils.waitNodeList 第三个参数必须是number");
1231
1242
  }
1232
1243
  }
1233
1244
  else {
1234
- throw new TypeError("Utils.waitNodeList 第二个参数必须是Node");
1245
+ throw new TypeError("DOMUtils.waitNodeList 第二个参数必须是Node");
1235
1246
  }
1236
1247
  }
1237
1248
  else {
1238
- throw new TypeError("Utils.waitNodeList 参数个数错误");
1249
+ throw new TypeError("DOMUtils.waitNodeList 参数个数错误");
1239
1250
  }
1240
1251
  function getNodeList() {
1241
1252
  if (Array.isArray(selector)) {
@@ -1284,7 +1295,7 @@ define((function () { 'use strict';
1284
1295
  // 超时时间
1285
1296
  let timeout = 0;
1286
1297
  if (!Array.isArray(args[0])) {
1287
- throw new TypeError("Utils.waitAnyNodeList 第一个参数必须是string[]");
1298
+ throw new TypeError("DOMUtils.waitAnyNodeList 第一个参数必须是string[]");
1288
1299
  }
1289
1300
  if (args.length === 1) ;
1290
1301
  else if (args.length === 2) {
@@ -1298,7 +1309,7 @@ define((function () { 'use strict';
1298
1309
  parent = secondParam;
1299
1310
  }
1300
1311
  else {
1301
- throw new TypeError("Utils.waitAnyNodeList 第二个参数必须是number|Node");
1312
+ throw new TypeError("DOMUtils.waitAnyNodeList 第二个参数必须是number|Node");
1302
1313
  }
1303
1314
  }
1304
1315
  else if (args.length === 3) {
@@ -1313,15 +1324,15 @@ define((function () { 'use strict';
1313
1324
  timeout = thirdParam;
1314
1325
  }
1315
1326
  else {
1316
- throw new TypeError("Utils.waitAnyNodeList 第三个参数必须是number");
1327
+ throw new TypeError("DOMUtils.waitAnyNodeList 第三个参数必须是number");
1317
1328
  }
1318
1329
  }
1319
1330
  else {
1320
- throw new TypeError("Utils.waitAnyNodeList 第二个参数必须是Node");
1331
+ throw new TypeError("DOMUtils.waitAnyNodeList 第二个参数必须是Node");
1321
1332
  }
1322
1333
  }
1323
1334
  else {
1324
- throw new TypeError("Utils.waitAnyNodeList 参数个数错误");
1335
+ throw new TypeError("DOMUtils.waitAnyNodeList 参数个数错误");
1325
1336
  }
1326
1337
  const promiseList = selectorList.map((selector) => {
1327
1338
  return UtilsContext.waitNodeList(selector, parent, timeout);
@@ -4003,7 +4014,7 @@ define((function () { 'use strict';
4003
4014
  checkUserClickInNode($el) {
4004
4015
  const that = this;
4005
4016
  if (!CommonUtils.isDOM($el)) {
4006
- throw new Error("Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型");
4017
+ throw new Error("DOMUtils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型");
4007
4018
  }
4008
4019
  const clickEvent = that.windowApi.window.event;
4009
4020
  const touchEvent = that.windowApi.window.event;