util.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getNode = getNode;
  6. exports.isEleEllipsis = isEleEllipsis;
  7. exports.isValidText = void 0;
  8. exports.toList = toList;
  9. function toList(val) {
  10. if (val === false) {
  11. return [false, false];
  12. }
  13. return Array.isArray(val) ? val : [val];
  14. }
  15. function getNode(dom, defaultNode, needDom) {
  16. if (dom === true || dom === undefined) {
  17. return defaultNode;
  18. }
  19. return dom || needDom && defaultNode;
  20. }
  21. /**
  22. * Check for element is native ellipsis
  23. * ref:
  24. * - https://github.com/ant-design/ant-design/issues/50143
  25. * - https://github.com/ant-design/ant-design/issues/50414
  26. */
  27. function isEleEllipsis(ele) {
  28. // Create a new div to get the size
  29. const childDiv = document.createElement('em');
  30. ele.appendChild(childDiv);
  31. // For test case
  32. if (process.env.NODE_ENV !== 'production') {
  33. childDiv.className = 'ant-typography-css-ellipsis-content-measure';
  34. }
  35. const rect = ele.getBoundingClientRect();
  36. const childRect = childDiv.getBoundingClientRect();
  37. // Reset
  38. ele.removeChild(childDiv);
  39. // Range checker
  40. return (
  41. // Horizontal out of range
  42. rect.left > childRect.left || childRect.right > rect.right ||
  43. // Vertical out of range
  44. rect.top > childRect.top || childRect.bottom > rect.bottom
  45. );
  46. }
  47. const isValidText = val => ['string', 'number'].includes(typeof val);
  48. exports.isValidText = isValidText;