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.

60 lines
1.9 KiB

  1. "use strict";
  2. var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.screen = void 0;
  7. var _lzString = require("lz-string");
  8. var queries = _interopRequireWildcard(require("./queries"));
  9. var _getQueriesForElement = require("./get-queries-for-element");
  10. var _prettyDom = require("./pretty-dom");
  11. var _helpers = require("./helpers");
  12. function unindent(string) {
  13. // remove white spaces first, to save a few bytes.
  14. // testing-playground will reformat on load any ways.
  15. return string.replace(/[ \t]*[\n][ \t]*/g, '\n');
  16. }
  17. function encode(value) {
  18. return (0, _lzString.compressToEncodedURIComponent)(unindent(value));
  19. }
  20. function getPlaygroundUrl(markup) {
  21. return `https://testing-playground.com/#markup=${encode(markup)}`;
  22. }
  23. const debug = (element, maxLength, options) => Array.isArray(element) ? element.forEach(el => (0, _prettyDom.logDOM)(el, maxLength, options)) : (0, _prettyDom.logDOM)(element, maxLength, options);
  24. const logTestingPlaygroundURL = (element = (0, _helpers.getDocument)().body) => {
  25. if (!element || !('innerHTML' in element)) {
  26. console.log(`The element you're providing isn't a valid DOM element.`);
  27. return;
  28. }
  29. if (!element.innerHTML) {
  30. console.log(`The provided element doesn't have any children.`);
  31. return;
  32. }
  33. console.log(`Open this URL in your browser\n\n${getPlaygroundUrl(element.innerHTML)}`);
  34. };
  35. const initialValue = {
  36. debug,
  37. logTestingPlaygroundURL
  38. };
  39. const screen = typeof document !== 'undefined' && document.body ? (0, _getQueriesForElement.getQueriesForElement)(document.body, queries, initialValue) : Object.keys(queries).reduce((helpers, key) => {
  40. helpers[key] = () => {
  41. throw new TypeError('For queries bound to document.body a global document has to be available... Learn more: https://testing-library.com/s/screen-global-error');
  42. };
  43. return helpers;
  44. }, initialValue);
  45. exports.screen = screen;