UNPKG

ant-design-vue

Version:

An enterprise-class UI design language and Vue-based implementation

103 lines (81 loc) 4.13 kB
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } import ResizeObserver from 'resize-observer-polyfill'; import contains from '../vc-util/Dom/contains'; export function buffer(fn, ms) { var timer; function clear() { if (timer) { clearTimeout(timer); timer = null; } } function bufferFn() { clear(); timer = setTimeout(fn, ms); } bufferFn.clear = clear; return bufferFn; } export function isSamePoint(prev, next) { if (prev === next) return true; if (!prev || !next) return false; if ('pageX' in next && 'pageY' in next) { return prev.pageX === next.pageX && prev.pageY === next.pageY; } if ('clientX' in next && 'clientY' in next) { return prev.clientX === next.clientX && prev.clientY === next.clientY; } return false; } export function isWindow(obj) { return obj && _typeof(obj) === 'object' && obj.window === obj; } export function isSimilarValue(val1, val2) { var int1 = Math.floor(val1); var int2 = Math.floor(val2); return Math.abs(int1 - int2) <= 1; } export function restoreFocus(activeElement, container) { // Focus back if is in the container if (activeElement !== document.activeElement && contains(container, activeElement)) { activeElement.focus(); } } export function monitorResize(element, callback) { var prevWidth = null; var prevHeight = null; function onResize(_ref) { var _ref2 = _slicedToArray(_ref, 1), target = _ref2[0].target; if (!document.documentElement.contains(target)) return; var _target$getBoundingCl = target.getBoundingClientRect(), width = _target$getBoundingCl.width, height = _target$getBoundingCl.height; var fixedWidth = Math.floor(width); var fixedHeight = Math.floor(height); if (prevWidth !== fixedWidth || prevHeight !== fixedHeight) { // https://webkit.org/blog/9997/resizeobserver-in-webkit/ Promise.resolve().then(function () { callback({ width: fixedWidth, height: fixedHeight }); }); } prevWidth = fixedWidth; prevHeight = fixedHeight; } var resizeObserver = new ResizeObserver(onResize); if (element) { resizeObserver.observe(element); } return function () { resizeObserver.disconnect(); }; }