c53ef7d394db8cf2365c7397b26b26ea5264115d3325fd197c000218da19b633574ced50beb92f673f5857cc5e04f20669b3f30f3ea10182380ca80dbd0e62 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  4. exports.requestAnimationFrame = requestAnimationFrame;
  5. exports.cancelAnimationFrame = cancelAnimationFrame;
  6. exports.isTouchSupported = isTouchSupported;
  7. exports.isWebComponentSupportedNatively = isWebComponentSupportedNatively;
  8. exports.hasCaptionProblem = hasCaptionProblem;
  9. exports.getComparisonFunction = getComparisonFunction;
  10. // https://gist.github.com/paulirish/1579671
  11. var lastTime = 0;
  12. var vendors = ['ms', 'moz', 'webkit', 'o'];
  13. var _requestAnimationFrame = window.requestAnimationFrame;
  14. var _cancelAnimationFrame = window.cancelAnimationFrame;
  15. for (var x = 0; x < vendors.length && !_requestAnimationFrame; ++x) {
  16. _requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
  17. _cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
  18. }
  19. if (!_requestAnimationFrame) {
  20. _requestAnimationFrame = function _requestAnimationFrame(callback) {
  21. var currTime = new Date().getTime();
  22. var timeToCall = Math.max(0, 16 - (currTime - lastTime));
  23. var id = window.setTimeout(function () {
  24. callback(currTime + timeToCall);
  25. }, timeToCall);
  26. lastTime = currTime + timeToCall;
  27. return id;
  28. };
  29. }
  30. if (!_cancelAnimationFrame) {
  31. _cancelAnimationFrame = function _cancelAnimationFrame(id) {
  32. clearTimeout(id);
  33. };
  34. }
  35. /**
  36. * Polyfill for requestAnimationFrame
  37. *
  38. * @param {Function} callback
  39. * @returns {Number}
  40. */
  41. function requestAnimationFrame(callback) {
  42. return _requestAnimationFrame.call(window, callback);
  43. }
  44. /**
  45. * Polyfill for cancelAnimationFrame
  46. *
  47. * @param {Number} id
  48. */
  49. function cancelAnimationFrame(id) {
  50. _cancelAnimationFrame.call(window, id);
  51. }
  52. function isTouchSupported() {
  53. return 'ontouchstart' in window;
  54. }
  55. /**
  56. * Checks if browser is support web components natively
  57. *
  58. * @returns {Boolean}
  59. */
  60. function isWebComponentSupportedNatively() {
  61. var test = document.createElement('div');
  62. return !!(test.createShadowRoot && test.createShadowRoot.toString().match(/\[native code\]/));
  63. }
  64. var _hasCaptionProblem;
  65. function detectCaptionProblem() {
  66. var TABLE = document.createElement('TABLE');
  67. TABLE.style.borderSpacing = 0;
  68. TABLE.style.borderWidth = 0;
  69. TABLE.style.padding = 0;
  70. var TBODY = document.createElement('TBODY');
  71. TABLE.appendChild(TBODY);
  72. TBODY.appendChild(document.createElement('TR'));
  73. TBODY.firstChild.appendChild(document.createElement('TD'));
  74. TBODY.firstChild.firstChild.innerHTML = '<tr><td>t<br>t</td></tr>';
  75. var CAPTION = document.createElement('CAPTION');
  76. CAPTION.innerHTML = 'c<br>c<br>c<br>c';
  77. CAPTION.style.padding = 0;
  78. CAPTION.style.margin = 0;
  79. TABLE.insertBefore(CAPTION, TBODY);
  80. document.body.appendChild(TABLE);
  81. _hasCaptionProblem = TABLE.offsetHeight < 2 * TABLE.lastChild.offsetHeight; // boolean
  82. document.body.removeChild(TABLE);
  83. }
  84. function hasCaptionProblem() {
  85. if (_hasCaptionProblem === void 0) {
  86. detectCaptionProblem();
  87. }
  88. return _hasCaptionProblem;
  89. }
  90. var comparisonFunction = void 0;
  91. /**
  92. * Get string comparison function for sorting purposes. It supports multilingual string comparison base on Internationalization API.
  93. *
  94. * @param {String} [language]
  95. * @param {Object} [options]
  96. * @returns {*}
  97. */
  98. function getComparisonFunction(language) {
  99. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  100. if (comparisonFunction) {
  101. return comparisonFunction;
  102. }
  103. if ((typeof Intl === 'undefined' ? 'undefined' : _typeof(Intl)) === 'object') {
  104. comparisonFunction = new Intl.Collator(language, options).compare;
  105. } else if (typeof String.prototype.localeCompare === 'function') {
  106. comparisonFunction = function comparisonFunction(a, b) {
  107. return ('' + a).localeCompare(b);
  108. };
  109. } else {
  110. comparisonFunction = function comparisonFunction(a, b) {
  111. if (a === b) {
  112. return 0;
  113. }
  114. return a > b ? -1 : 1;
  115. };
  116. }
  117. return comparisonFunction;
  118. }