web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.0 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.findByText = exports.findAllByText = exports.getAllByText = exports.getByText = exports.queryAllByText = exports.queryByText = void 0;
  6. var _queryHelpers = require("../query-helpers");
  7. var _helpers = require("../helpers");
  8. var _config = require("../config");
  9. var _allUtils = require("./all-utils");
  10. function queryAllByText(container, text, {
  11. selector = '*',
  12. exact = true,
  13. collapseWhitespace,
  14. trim,
  15. ignore = _config.DEFAULT_IGNORE_TAGS,
  16. normalizer
  17. } = {}) {
  18. (0, _helpers.checkContainerType)(container);
  19. const matcher = exact ? _allUtils.matches : _allUtils.fuzzyMatches;
  20. const matchNormalizer = (0, _allUtils.makeNormalizer)({
  21. collapseWhitespace,
  22. trim,
  23. normalizer
  24. });
  25. let baseArray = [];
  26. if (typeof container.matches === 'function' && container.matches(selector)) {
  27. baseArray = [container];
  28. }
  29. return [...baseArray, ...Array.from(container.querySelectorAll(selector))].filter(node => !ignore || !node.matches(ignore)).filter(node => matcher((0, _allUtils.getNodeText)(node), node, text, matchNormalizer));
  30. }
  31. const getMultipleError = (c, text) => `Found multiple elements with the text: ${text}`;
  32. const getMissingError = (c, text) => `Unable to find an element with the text: ${text}. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.`;
  33. const queryAllByTextWithSuggestions = (0, _queryHelpers.wrapAllByQueryWithSuggestion)(queryAllByText, queryAllByText.name, 'queryAll');
  34. exports.queryAllByText = queryAllByTextWithSuggestions;
  35. const [queryByText, getAllByText, getByText, findAllByText, findByText] = (0, _allUtils.buildQueries)(queryAllByText, getMultipleError, getMissingError);
  36. exports.findByText = findByText;
  37. exports.findAllByText = findAllByText;
  38. exports.getByText = getByText;
  39. exports.getAllByText = getAllByText;
  40. exports.queryByText = queryByText;