conflict-detection.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  1. /*!
  2. * Font Awesome Free 5.15.1 by @fontawesome - https://fontawesome.com
  3. * License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
  4. */
  5. (function (global, factory) {
  6. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  7. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  8. (factory((global['fontawesome-free-conflict-detection'] = {})));
  9. }(this, (function (exports) { 'use strict';
  10. function _typeof(obj) {
  11. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  12. _typeof = function (obj) {
  13. return typeof obj;
  14. };
  15. } else {
  16. _typeof = function (obj) {
  17. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  18. };
  19. }
  20. return _typeof(obj);
  21. }
  22. function _defineProperty(obj, key, value) {
  23. if (key in obj) {
  24. Object.defineProperty(obj, key, {
  25. value: value,
  26. enumerable: true,
  27. configurable: true,
  28. writable: true
  29. });
  30. } else {
  31. obj[key] = value;
  32. }
  33. return obj;
  34. }
  35. function _objectSpread(target) {
  36. for (var i = 1; i < arguments.length; i++) {
  37. var source = arguments[i] != null ? arguments[i] : {};
  38. var ownKeys = Object.keys(source);
  39. if (typeof Object.getOwnPropertySymbols === 'function') {
  40. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  41. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  42. }));
  43. }
  44. ownKeys.forEach(function (key) {
  45. _defineProperty(target, key, source[key]);
  46. });
  47. }
  48. return target;
  49. }
  50. var _WINDOW = {};
  51. var _DOCUMENT = {};
  52. try {
  53. if (typeof window !== 'undefined') _WINDOW = window;
  54. if (typeof document !== 'undefined') _DOCUMENT = document;
  55. } catch (e) {}
  56. var _ref = _WINDOW.navigator || {},
  57. _ref$userAgent = _ref.userAgent,
  58. userAgent = _ref$userAgent === void 0 ? '' : _ref$userAgent;
  59. var WINDOW = _WINDOW;
  60. var DOCUMENT = _DOCUMENT;
  61. var IS_BROWSER = !!WINDOW.document;
  62. var IS_DOM = !!DOCUMENT.documentElement && !!DOCUMENT.head && typeof DOCUMENT.addEventListener === 'function' && typeof DOCUMENT.createElement === 'function';
  63. var IS_IE = ~userAgent.indexOf('MSIE') || ~userAgent.indexOf('Trident/');
  64. var functions = [];
  65. var listener = function listener() {
  66. DOCUMENT.removeEventListener('DOMContentLoaded', listener);
  67. loaded = 1;
  68. functions.map(function (fn) {
  69. return fn();
  70. });
  71. };
  72. var loaded = false;
  73. if (IS_DOM) {
  74. loaded = (DOCUMENT.documentElement.doScroll ? /^loaded|^c/ : /^loaded|^i|^c/).test(DOCUMENT.readyState);
  75. if (!loaded) DOCUMENT.addEventListener('DOMContentLoaded', listener);
  76. }
  77. function domready (fn) {
  78. if (!IS_DOM) return;
  79. loaded ? setTimeout(fn, 0) : functions.push(fn);
  80. }
  81. function report (_ref) {
  82. var nodesTested = _ref.nodesTested,
  83. nodesFound = _ref.nodesFound;
  84. var timedOutTests = {};
  85. for (var key in nodesFound) {
  86. if (!(nodesTested.conflict[key] || nodesTested.noConflict[key])) {
  87. timedOutTests[key] = nodesFound[key];
  88. }
  89. }
  90. var conflictsCount = Object.keys(nodesTested.conflict).length;
  91. if (conflictsCount > 0) {
  92. console.info("%cConflict".concat(conflictsCount > 1 ? 's' : '', " found:"), 'color: darkred; font-size: large');
  93. var data = {};
  94. for (var _key in nodesTested.conflict) {
  95. var item = nodesTested.conflict[_key];
  96. data[_key] = {
  97. 'tagName': item.tagName,
  98. 'src/href': item.src || item.href || 'n/a',
  99. 'innerText excerpt': item.innerText && item.innerText !== '' ? item.innerText.slice(0, 200) + '...' : '(empty)'
  100. };
  101. }
  102. console.table(data);
  103. }
  104. var noConflictsCount = Object.keys(nodesTested.noConflict).length;
  105. if (noConflictsCount > 0) {
  106. console.info("%cNo conflict".concat(noConflictsCount > 1 ? 's' : '', " found with ").concat(noConflictsCount == 1 ? 'this' : 'these', ":"), 'color: green; font-size: large');
  107. var _data = {};
  108. for (var _key2 in nodesTested.noConflict) {
  109. var _item = nodesTested.noConflict[_key2];
  110. _data[_key2] = {
  111. 'tagName': _item.tagName,
  112. 'src/href': _item.src || _item.href || 'n/a',
  113. 'innerText excerpt': _item.innerText && _item.innerText !== '' ? _item.innerText.slice(0, 200) + '...' : '(empty)'
  114. };
  115. }
  116. console.table(_data);
  117. }
  118. var timeOutCount = Object.keys(timedOutTests).length;
  119. if (timeOutCount > 0) {
  120. console.info("%cLeftovers--we timed out before collecting test results for ".concat(timeOutCount == 1 ? 'this' : 'these', ":"), 'color: blue; font-size: large');
  121. var _data2 = {};
  122. for (var _key3 in timedOutTests) {
  123. var _item2 = timedOutTests[_key3];
  124. _data2[_key3] = {
  125. 'tagName': _item2.tagName,
  126. 'src/href': _item2.src || _item2.href || 'n/a',
  127. 'innerText excerpt': _item2.innerText && _item2.innerText !== '' ? _item2.innerText.slice(0, 200) + '...' : '(empty)'
  128. };
  129. }
  130. console.table(_data2);
  131. }
  132. }
  133. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  134. function createCommonjsModule(fn, module) {
  135. return module = { exports: {} }, fn(module, module.exports), module.exports;
  136. }
  137. var md5 = createCommonjsModule(function (module) {
  138. (function ($) {
  139. /**
  140. * Add integers, wrapping at 2^32.
  141. * This uses 16-bit operations internally to work around bugs in interpreters.
  142. *
  143. * @param {number} x First integer
  144. * @param {number} y Second integer
  145. * @returns {number} Sum
  146. */
  147. function safeAdd(x, y) {
  148. var lsw = (x & 0xffff) + (y & 0xffff);
  149. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  150. return msw << 16 | lsw & 0xffff;
  151. }
  152. /**
  153. * Bitwise rotate a 32-bit number to the left.
  154. *
  155. * @param {number} num 32-bit number
  156. * @param {number} cnt Rotation count
  157. * @returns {number} Rotated number
  158. */
  159. function bitRotateLeft(num, cnt) {
  160. return num << cnt | num >>> 32 - cnt;
  161. }
  162. /**
  163. * Basic operation the algorithm uses.
  164. *
  165. * @param {number} q q
  166. * @param {number} a a
  167. * @param {number} b b
  168. * @param {number} x x
  169. * @param {number} s s
  170. * @param {number} t t
  171. * @returns {number} Result
  172. */
  173. function md5cmn(q, a, b, x, s, t) {
  174. return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
  175. }
  176. /**
  177. * Basic operation the algorithm uses.
  178. *
  179. * @param {number} a a
  180. * @param {number} b b
  181. * @param {number} c c
  182. * @param {number} d d
  183. * @param {number} x x
  184. * @param {number} s s
  185. * @param {number} t t
  186. * @returns {number} Result
  187. */
  188. function md5ff(a, b, c, d, x, s, t) {
  189. return md5cmn(b & c | ~b & d, a, b, x, s, t);
  190. }
  191. /**
  192. * Basic operation the algorithm uses.
  193. *
  194. * @param {number} a a
  195. * @param {number} b b
  196. * @param {number} c c
  197. * @param {number} d d
  198. * @param {number} x x
  199. * @param {number} s s
  200. * @param {number} t t
  201. * @returns {number} Result
  202. */
  203. function md5gg(a, b, c, d, x, s, t) {
  204. return md5cmn(b & d | c & ~d, a, b, x, s, t);
  205. }
  206. /**
  207. * Basic operation the algorithm uses.
  208. *
  209. * @param {number} a a
  210. * @param {number} b b
  211. * @param {number} c c
  212. * @param {number} d d
  213. * @param {number} x x
  214. * @param {number} s s
  215. * @param {number} t t
  216. * @returns {number} Result
  217. */
  218. function md5hh(a, b, c, d, x, s, t) {
  219. return md5cmn(b ^ c ^ d, a, b, x, s, t);
  220. }
  221. /**
  222. * Basic operation the algorithm uses.
  223. *
  224. * @param {number} a a
  225. * @param {number} b b
  226. * @param {number} c c
  227. * @param {number} d d
  228. * @param {number} x x
  229. * @param {number} s s
  230. * @param {number} t t
  231. * @returns {number} Result
  232. */
  233. function md5ii(a, b, c, d, x, s, t) {
  234. return md5cmn(c ^ (b | ~d), a, b, x, s, t);
  235. }
  236. /**
  237. * Calculate the MD5 of an array of little-endian words, and a bit length.
  238. *
  239. * @param {Array} x Array of little-endian words
  240. * @param {number} len Bit length
  241. * @returns {Array<number>} MD5 Array
  242. */
  243. function binlMD5(x, len) {
  244. /* append padding */
  245. x[len >> 5] |= 0x80 << len % 32;
  246. x[(len + 64 >>> 9 << 4) + 14] = len;
  247. var i;
  248. var olda;
  249. var oldb;
  250. var oldc;
  251. var oldd;
  252. var a = 1732584193;
  253. var b = -271733879;
  254. var c = -1732584194;
  255. var d = 271733878;
  256. for (i = 0; i < x.length; i += 16) {
  257. olda = a;
  258. oldb = b;
  259. oldc = c;
  260. oldd = d;
  261. a = md5ff(a, b, c, d, x[i], 7, -680876936);
  262. d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
  263. c = md5ff(c, d, a, b, x[i + 2], 17, 606105819);
  264. b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
  265. a = md5ff(a, b, c, d, x[i + 4], 7, -176418897);
  266. d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
  267. c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
  268. b = md5ff(b, c, d, a, x[i + 7], 22, -45705983);
  269. a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
  270. d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
  271. c = md5ff(c, d, a, b, x[i + 10], 17, -42063);
  272. b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
  273. a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
  274. d = md5ff(d, a, b, c, x[i + 13], 12, -40341101);
  275. c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
  276. b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
  277. a = md5gg(a, b, c, d, x[i + 1], 5, -165796510);
  278. d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
  279. c = md5gg(c, d, a, b, x[i + 11], 14, 643717713);
  280. b = md5gg(b, c, d, a, x[i], 20, -373897302);
  281. a = md5gg(a, b, c, d, x[i + 5], 5, -701558691);
  282. d = md5gg(d, a, b, c, x[i + 10], 9, 38016083);
  283. c = md5gg(c, d, a, b, x[i + 15], 14, -660478335);
  284. b = md5gg(b, c, d, a, x[i + 4], 20, -405537848);
  285. a = md5gg(a, b, c, d, x[i + 9], 5, 568446438);
  286. d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
  287. c = md5gg(c, d, a, b, x[i + 3], 14, -187363961);
  288. b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
  289. a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
  290. d = md5gg(d, a, b, c, x[i + 2], 9, -51403784);
  291. c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
  292. b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
  293. a = md5hh(a, b, c, d, x[i + 5], 4, -378558);
  294. d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
  295. c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
  296. b = md5hh(b, c, d, a, x[i + 14], 23, -35309556);
  297. a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
  298. d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
  299. c = md5hh(c, d, a, b, x[i + 7], 16, -155497632);
  300. b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
  301. a = md5hh(a, b, c, d, x[i + 13], 4, 681279174);
  302. d = md5hh(d, a, b, c, x[i], 11, -358537222);
  303. c = md5hh(c, d, a, b, x[i + 3], 16, -722521979);
  304. b = md5hh(b, c, d, a, x[i + 6], 23, 76029189);
  305. a = md5hh(a, b, c, d, x[i + 9], 4, -640364487);
  306. d = md5hh(d, a, b, c, x[i + 12], 11, -421815835);
  307. c = md5hh(c, d, a, b, x[i + 15], 16, 530742520);
  308. b = md5hh(b, c, d, a, x[i + 2], 23, -995338651);
  309. a = md5ii(a, b, c, d, x[i], 6, -198630844);
  310. d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
  311. c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
  312. b = md5ii(b, c, d, a, x[i + 5], 21, -57434055);
  313. a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
  314. d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
  315. c = md5ii(c, d, a, b, x[i + 10], 15, -1051523);
  316. b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
  317. a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
  318. d = md5ii(d, a, b, c, x[i + 15], 10, -30611744);
  319. c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
  320. b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
  321. a = md5ii(a, b, c, d, x[i + 4], 6, -145523070);
  322. d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
  323. c = md5ii(c, d, a, b, x[i + 2], 15, 718787259);
  324. b = md5ii(b, c, d, a, x[i + 9], 21, -343485551);
  325. a = safeAdd(a, olda);
  326. b = safeAdd(b, oldb);
  327. c = safeAdd(c, oldc);
  328. d = safeAdd(d, oldd);
  329. }
  330. return [a, b, c, d];
  331. }
  332. /**
  333. * Convert an array of little-endian words to a string
  334. *
  335. * @param {Array<number>} input MD5 Array
  336. * @returns {string} MD5 string
  337. */
  338. function binl2rstr(input) {
  339. var i;
  340. var output = '';
  341. var length32 = input.length * 32;
  342. for (i = 0; i < length32; i += 8) {
  343. output += String.fromCharCode(input[i >> 5] >>> i % 32 & 0xff);
  344. }
  345. return output;
  346. }
  347. /**
  348. * Convert a raw string to an array of little-endian words
  349. * Characters >255 have their high-byte silently ignored.
  350. *
  351. * @param {string} input Raw input string
  352. * @returns {Array<number>} Array of little-endian words
  353. */
  354. function rstr2binl(input) {
  355. var i;
  356. var output = [];
  357. output[(input.length >> 2) - 1] = undefined;
  358. for (i = 0; i < output.length; i += 1) {
  359. output[i] = 0;
  360. }
  361. var length8 = input.length * 8;
  362. for (i = 0; i < length8; i += 8) {
  363. output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << i % 32;
  364. }
  365. return output;
  366. }
  367. /**
  368. * Calculate the MD5 of a raw string
  369. *
  370. * @param {string} s Input string
  371. * @returns {string} Raw MD5 string
  372. */
  373. function rstrMD5(s) {
  374. return binl2rstr(binlMD5(rstr2binl(s), s.length * 8));
  375. }
  376. /**
  377. * Calculates the HMAC-MD5 of a key and some data (raw strings)
  378. *
  379. * @param {string} key HMAC key
  380. * @param {string} data Raw input string
  381. * @returns {string} Raw MD5 string
  382. */
  383. function rstrHMACMD5(key, data) {
  384. var i;
  385. var bkey = rstr2binl(key);
  386. var ipad = [];
  387. var opad = [];
  388. var hash;
  389. ipad[15] = opad[15] = undefined;
  390. if (bkey.length > 16) {
  391. bkey = binlMD5(bkey, key.length * 8);
  392. }
  393. for (i = 0; i < 16; i += 1) {
  394. ipad[i] = bkey[i] ^ 0x36363636;
  395. opad[i] = bkey[i] ^ 0x5c5c5c5c;
  396. }
  397. hash = binlMD5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
  398. return binl2rstr(binlMD5(opad.concat(hash), 512 + 128));
  399. }
  400. /**
  401. * Convert a raw string to a hex string
  402. *
  403. * @param {string} input Raw input string
  404. * @returns {string} Hex encoded string
  405. */
  406. function rstr2hex(input) {
  407. var hexTab = '0123456789abcdef';
  408. var output = '';
  409. var x;
  410. var i;
  411. for (i = 0; i < input.length; i += 1) {
  412. x = input.charCodeAt(i);
  413. output += hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f);
  414. }
  415. return output;
  416. }
  417. /**
  418. * Encode a string as UTF-8
  419. *
  420. * @param {string} input Input string
  421. * @returns {string} UTF8 string
  422. */
  423. function str2rstrUTF8(input) {
  424. return unescape(encodeURIComponent(input));
  425. }
  426. /**
  427. * Encodes input string as raw MD5 string
  428. *
  429. * @param {string} s Input string
  430. * @returns {string} Raw MD5 string
  431. */
  432. function rawMD5(s) {
  433. return rstrMD5(str2rstrUTF8(s));
  434. }
  435. /**
  436. * Encodes input string as Hex encoded string
  437. *
  438. * @param {string} s Input string
  439. * @returns {string} Hex encoded string
  440. */
  441. function hexMD5(s) {
  442. return rstr2hex(rawMD5(s));
  443. }
  444. /**
  445. * Calculates the raw HMAC-MD5 for the given key and data
  446. *
  447. * @param {string} k HMAC key
  448. * @param {string} d Input string
  449. * @returns {string} Raw MD5 string
  450. */
  451. function rawHMACMD5(k, d) {
  452. return rstrHMACMD5(str2rstrUTF8(k), str2rstrUTF8(d));
  453. }
  454. /**
  455. * Calculates the Hex encoded HMAC-MD5 for the given key and data
  456. *
  457. * @param {string} k HMAC key
  458. * @param {string} d Input string
  459. * @returns {string} Raw MD5 string
  460. */
  461. function hexHMACMD5(k, d) {
  462. return rstr2hex(rawHMACMD5(k, d));
  463. }
  464. /**
  465. * Calculates MD5 value for a given string.
  466. * If a key is provided, calculates the HMAC-MD5 value.
  467. * Returns a Hex encoded string unless the raw argument is given.
  468. *
  469. * @param {string} string Input string
  470. * @param {string} [key] HMAC key
  471. * @param {boolean} raw Raw oytput switch
  472. * @returns {string} MD5 output
  473. */
  474. function md5(string, key, raw) {
  475. if (!key) {
  476. if (!raw) {
  477. return hexMD5(string);
  478. }
  479. return rawMD5(string);
  480. }
  481. if (!raw) {
  482. return hexHMACMD5(key, string);
  483. }
  484. return rawHMACMD5(key, string);
  485. }
  486. if (module.exports) {
  487. module.exports = md5;
  488. } else {
  489. $.md5 = md5;
  490. }
  491. })(commonjsGlobal);
  492. });
  493. function md5ForNode(node) {
  494. if (null === node || 'object' !== _typeof(node)) return undefined;
  495. if (node.src) {
  496. return md5(node.src);
  497. } else if (node.href) {
  498. return md5(node.href);
  499. } else if (node.innerText && '' !== node.innerText) {
  500. // eslint-disable-line yoda
  501. return md5(node.innerText);
  502. } else {
  503. return undefined;
  504. }
  505. }
  506. var diagScriptId = 'fa-kits-diag';
  507. var nodeUnderTestId = 'fa-kits-node-under-test';
  508. var md5Attr = 'data-md5';
  509. var detectionIgnoreAttr = 'data-fa-detection-ignore';
  510. var timeoutAttr = 'data-fa-detection-timeout';
  511. var resultsCollectionMaxWaitAttr = 'data-fa-detection-results-collection-max-wait';
  512. var silenceErrors = function silenceErrors(e) {
  513. e.preventDefault();
  514. e.stopPropagation();
  515. };
  516. function pollUntil(_ref) {
  517. var _ref$fn = _ref.fn,
  518. fn = _ref$fn === void 0 ? function () {
  519. return true;
  520. } : _ref$fn,
  521. _ref$initialDuration = _ref.initialDuration,
  522. initialDuration = _ref$initialDuration === void 0 ? 1 : _ref$initialDuration,
  523. _ref$maxDuration = _ref.maxDuration,
  524. maxDuration = _ref$maxDuration === void 0 ? WINDOW.FontAwesomeDetection.timeout : _ref$maxDuration,
  525. _ref$showProgress = _ref.showProgress,
  526. showProgress = _ref$showProgress === void 0 ? false : _ref$showProgress,
  527. progressIndicator = _ref.progressIndicator;
  528. return new Promise(function (resolve, reject) {
  529. // eslint-disable-line compat/compat
  530. function poll(duration, cumulativeDuration) {
  531. setTimeout(function () {
  532. var result = fn();
  533. if (showProgress) {
  534. console.info(progressIndicator);
  535. }
  536. if (!!result) {
  537. // eslint-disable-line no-extra-boolean-cast
  538. resolve(result);
  539. } else {
  540. var nextDuration = 250;
  541. var nextCumulativeDuration = nextDuration + cumulativeDuration;
  542. if (nextCumulativeDuration <= maxDuration) {
  543. poll(nextDuration, nextCumulativeDuration);
  544. } else {
  545. reject('timeout'); // eslint-disable-line prefer-promise-reject-errors
  546. }
  547. }
  548. }, duration);
  549. }
  550. poll(initialDuration, 0);
  551. });
  552. }
  553. function detectWebfontConflicts() {
  554. var linkTags = Array.from(DOCUMENT.getElementsByTagName('link')).filter(function (t) {
  555. return !t.hasAttribute(detectionIgnoreAttr);
  556. });
  557. var styleTags = Array.from(DOCUMENT.getElementsByTagName('style')).filter(function (t) {
  558. if (t.hasAttribute(detectionIgnoreAttr)) {
  559. return false;
  560. } // If the browser has loaded the FA5 CSS, let's not test that <style> element.
  561. // Its enough that we'll be testing for traces of the corresponding JS being loaded, and testing
  562. // this <style> would only produce a false negative anyway.
  563. if (WINDOW.FontAwesomeConfig && t.innerText.match(new RegExp("svg:not\\(:root\\)\\.".concat(WINDOW.FontAwesomeConfig.replacementClass)))) {
  564. return false;
  565. }
  566. return true;
  567. });
  568. function runDiag(scriptOrLinkTag, md5) {
  569. var diagFrame = DOCUMENT.createElement('iframe'); // Using "visibility: hidden; position: absolute" instead of "display: none;" because
  570. // Firefox will not return the expected results for getComputedStyle if our iframe has display: none.
  571. diagFrame.setAttribute('style', 'visibility: hidden; position: absolute; height: 0; width: 0;');
  572. var testIconId = 'fa-test-icon-' + md5;
  573. var iTag = DOCUMENT.createElement('i');
  574. iTag.setAttribute('class', 'fa fa-coffee');
  575. iTag.setAttribute('id', testIconId);
  576. var diagScript = DOCUMENT.createElement('script');
  577. diagScript.setAttribute('id', diagScriptId); // WARNING: this function will be toString()'d and assigned to innerText of the diag script
  578. // element that we'll be putting into a diagnostic iframe.
  579. // That means that this code won't compile until after the outer script has run and injected
  580. // this code into the iframe. There are some compile time errors that might occur there.
  581. // For example, using single line (double-slash) comments like this one inside that function
  582. // will probably cause it to choke. Chrome will show an error like this:
  583. // Uncaught SyntaxError: Unexpected end of input
  584. var diagScriptFun = function diagScriptFun(nodeUnderTestId, testIconId, md5, parentOrigin) {
  585. parent.FontAwesomeDetection.__pollUntil({
  586. fn: function fn() {
  587. var iEl = document.getElementById(testIconId);
  588. var computedStyle = window.getComputedStyle(iEl);
  589. var fontFamily = computedStyle.getPropertyValue('font-family');
  590. if (!!fontFamily.match(/FontAwesome/) || !!fontFamily.match(/Font Awesome 5/)) {
  591. return true;
  592. } else {
  593. return false;
  594. }
  595. }
  596. }).then(function () {
  597. var node = document.getElementById(nodeUnderTestId);
  598. parent.postMessage({
  599. type: 'fontawesome-conflict',
  600. technology: 'webfont',
  601. href: node.href,
  602. innerText: node.innerText,
  603. tagName: node.tagName,
  604. md5: md5
  605. }, parentOrigin);
  606. }).catch(function (e) {
  607. var node = document.getElementById(nodeUnderTestId);
  608. if (e === 'timeout') {
  609. parent.postMessage({
  610. type: 'no-conflict',
  611. technology: 'webfont',
  612. href: node.src,
  613. innerText: node.innerText,
  614. tagName: node.tagName,
  615. md5: md5
  616. }, parentOrigin);
  617. } else {
  618. console.error(e);
  619. }
  620. });
  621. };
  622. var parentOrigin = WINDOW.location.origin === 'file://' ? '*' : WINDOW.location.origin;
  623. diagScript.innerText = "(".concat(diagScriptFun.toString(), ")('").concat(nodeUnderTestId, "', '").concat(testIconId || 'foo', "', '").concat(md5, "', '").concat(parentOrigin, "');");
  624. diagFrame.onload = function () {
  625. diagFrame.contentWindow.addEventListener('error', silenceErrors, true);
  626. diagFrame.contentDocument.head.appendChild(diagScript);
  627. diagFrame.contentDocument.head.appendChild(scriptOrLinkTag);
  628. diagFrame.contentDocument.body.appendChild(iTag);
  629. };
  630. domready(function () {
  631. return DOCUMENT.body.appendChild(diagFrame);
  632. });
  633. }
  634. var cssByMD5 = {};
  635. for (var i = 0; i < linkTags.length; i++) {
  636. var linkUnderTest = DOCUMENT.createElement('link');
  637. linkUnderTest.setAttribute('id', nodeUnderTestId);
  638. linkUnderTest.setAttribute('href', linkTags[i].href);
  639. linkUnderTest.setAttribute('rel', linkTags[i].rel);
  640. var md5ForLink = md5ForNode(linkTags[i]);
  641. linkUnderTest.setAttribute(md5Attr, md5ForLink);
  642. cssByMD5[md5ForLink] = linkTags[i];
  643. runDiag(linkUnderTest, md5ForLink);
  644. }
  645. for (var _i = 0; _i < styleTags.length; _i++) {
  646. var styleUnderTest = DOCUMENT.createElement('style');
  647. styleUnderTest.setAttribute('id', nodeUnderTestId);
  648. var md5ForStyle = md5ForNode(styleTags[_i]);
  649. styleUnderTest.setAttribute(md5Attr, md5ForStyle);
  650. styleUnderTest.innerText = styleTags[_i].innerText;
  651. cssByMD5[md5ForStyle] = styleTags[_i];
  652. runDiag(styleUnderTest, md5ForStyle);
  653. }
  654. return cssByMD5;
  655. }
  656. function detectSvgConflicts(currentScript) {
  657. var scripts = Array.from(DOCUMENT.scripts).filter(function (t) {
  658. return !t.hasAttribute(detectionIgnoreAttr) && t !== currentScript;
  659. });
  660. var scriptsByMD5 = {};
  661. var _loop = function _loop(scriptIdx) {
  662. var diagFrame = DOCUMENT.createElement('iframe');
  663. diagFrame.setAttribute('style', 'display:none;');
  664. var scriptUnderTest = DOCUMENT.createElement('script');
  665. scriptUnderTest.setAttribute('id', nodeUnderTestId);
  666. var md5ForScript = md5ForNode(scripts[scriptIdx]);
  667. scriptUnderTest.setAttribute(md5Attr, md5ForScript);
  668. scriptsByMD5[md5ForScript] = scripts[scriptIdx];
  669. if (scripts[scriptIdx].src !== '') {
  670. scriptUnderTest.src = scripts[scriptIdx].src;
  671. }
  672. if (scripts[scriptIdx].innerText !== '') {
  673. scriptUnderTest.innerText = scripts[scriptIdx].innerText;
  674. }
  675. scriptUnderTest.async = true;
  676. var diagScript = DOCUMENT.createElement('script');
  677. diagScript.setAttribute('id', diagScriptId);
  678. var parentOrigin = WINDOW.location.origin === 'file://' ? '*' : WINDOW.location.origin;
  679. var diagScriptFun = function diagScriptFun(nodeUnderTestId, md5, parentOrigin) {
  680. parent.FontAwesomeDetection.__pollUntil({
  681. fn: function fn() {
  682. return !!window.FontAwesomeConfig || !!window.FontAwesomeKitConfig;
  683. }
  684. }).then(function () {
  685. var scriptNode = document.getElementById(nodeUnderTestId);
  686. parent.postMessage({
  687. type: 'fontawesome-conflict',
  688. technology: 'js',
  689. src: scriptNode.src,
  690. innerText: scriptNode.innerText,
  691. tagName: scriptNode.tagName,
  692. md5: md5
  693. }, parentOrigin);
  694. }).catch(function (e) {
  695. var scriptNode = document.getElementById(nodeUnderTestId);
  696. if (e === 'timeout') {
  697. parent.postMessage({
  698. type: 'no-conflict',
  699. src: scriptNode.src,
  700. innerText: scriptNode.innerText,
  701. tagName: scriptNode.tagName,
  702. md5: md5
  703. }, parentOrigin);
  704. } else {
  705. console.error(e);
  706. }
  707. });
  708. };
  709. diagScript.innerText = "(".concat(diagScriptFun.toString(), ")('").concat(nodeUnderTestId, "', '").concat(md5ForScript, "', '").concat(parentOrigin, "');");
  710. diagFrame.onload = function () {
  711. diagFrame.contentWindow.addEventListener('error', silenceErrors, true);
  712. diagFrame.contentDocument.head.appendChild(diagScript);
  713. diagFrame.contentDocument.head.appendChild(scriptUnderTest);
  714. };
  715. domready(function () {
  716. return DOCUMENT.body.appendChild(diagFrame);
  717. });
  718. };
  719. for (var scriptIdx = 0; scriptIdx < scripts.length; scriptIdx++) {
  720. _loop(scriptIdx);
  721. }
  722. return scriptsByMD5;
  723. }
  724. function setDoneResults(_ref2) {
  725. var nodesTested = _ref2.nodesTested,
  726. nodesFound = _ref2.nodesFound;
  727. WINDOW.FontAwesomeDetection = WINDOW.FontAwesomeDetection || {};
  728. WINDOW.FontAwesomeDetection.nodesTested = nodesTested;
  729. WINDOW.FontAwesomeDetection.nodesFound = nodesFound;
  730. WINDOW.FontAwesomeDetection.detectionDone = true;
  731. }
  732. function conflictDetection() {
  733. var report$$1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
  734. var nodesTested = {
  735. conflict: {},
  736. noConflict: {}
  737. };
  738. WINDOW.onmessage = function (e) {
  739. if (WINDOW.location.origin === 'file://' || e.origin === WINDOW.location.origin) {
  740. if (e && e.data) {
  741. if (e.data.type === 'fontawesome-conflict') {
  742. nodesTested.conflict[e.data.md5] = e.data;
  743. } else if (e.data.type === 'no-conflict') {
  744. nodesTested.noConflict[e.data.md5] = e.data;
  745. }
  746. }
  747. }
  748. };
  749. var scriptsToTest = detectSvgConflicts(DOCUMENT.currentScript);
  750. var cssToTest = detectWebfontConflicts();
  751. var nodesFound = _objectSpread({}, scriptsToTest, cssToTest);
  752. var testCount = Object.keys(scriptsToTest).length + Object.keys(cssToTest).length; // The resultsCollectionMaxWait allows for the time between when the tests running under
  753. // child iframes call postMessage with their results, and when the parent window
  754. // receives and handles those events with window.onmessage.
  755. // Making it configurable allows us to test the scenario where this timeout is exceeded.
  756. // Naming it something very different from "timeout" is to help avoid the potential ambiguity between
  757. // these two timeout-related settings.
  758. var masterTimeout = WINDOW.FontAwesomeDetection.timeout + WINDOW.FontAwesomeDetection.resultsCollectionMaxWait;
  759. console.group('Font Awesome Detector');
  760. if (testCount === 0) {
  761. console.info('%cAll Good!', 'color: green; font-size: large');
  762. console.info('We didn\'t find anything that needs testing for conflicts. Ergo, no conflicts.');
  763. } else {
  764. console.info("Testing ".concat(testCount, " possible conflicts."));
  765. console.info("We'll wait about ".concat(Math.round(WINDOW.FontAwesomeDetection.timeout / 10) / 100, " seconds while testing these and\n") + "then up to another ".concat(Math.round(WINDOW.FontAwesomeDetection.resultsCollectionMaxWait / 10) / 100, " to allow the browser time\n") + "to accumulate the results. But we'll probably be outta here way before then.\n\n");
  766. console.info("You can adjust those durations by assigning values to these attributes on the <script> element that loads this detection:");
  767. console.info("\t%c".concat(timeoutAttr, "%c: milliseconds to wait for each test before deciding whether it's a conflict."), 'font-weight: bold;', 'font-size: normal;');
  768. console.info("\t%c".concat(resultsCollectionMaxWaitAttr, "%c: milliseconds to wait for the browser to accumulate test results before giving up."), 'font-weight: bold;', 'font-size: normal;');
  769. pollUntil({
  770. // Give this overall timer a little extra cushion
  771. maxDuration: masterTimeout,
  772. showProgress: true,
  773. progressIndicator: 'waiting...',
  774. fn: function fn() {
  775. return Object.keys(nodesTested.conflict).length + Object.keys(nodesTested.noConflict).length >= testCount;
  776. }
  777. }).then(function () {
  778. console.info('DONE!');
  779. setDoneResults({
  780. nodesTested: nodesTested,
  781. nodesFound: nodesFound
  782. });
  783. report$$1({
  784. nodesTested: nodesTested,
  785. nodesFound: nodesFound
  786. });
  787. console.groupEnd();
  788. }).catch(function (e) {
  789. if (e === 'timeout') {
  790. console.info('TIME OUT! We waited until we got tired. Here\'s what we found:');
  791. setDoneResults({
  792. nodesTested: nodesTested,
  793. nodesFound: nodesFound
  794. });
  795. report$$1({
  796. nodesTested: nodesTested,
  797. nodesFound: nodesFound
  798. });
  799. } else {
  800. console.info('Whoops! We hit an error:', e);
  801. console.info('Here\'s what we\'d found up until that error:');
  802. setDoneResults({
  803. nodesTested: nodesTested,
  804. nodesFound: nodesFound
  805. });
  806. report$$1({
  807. nodesTested: nodesTested,
  808. nodesFound: nodesFound
  809. });
  810. }
  811. console.groupEnd();
  812. });
  813. }
  814. } // Allow clients to access, and in some cases, override some properties
  815. var initialConfig = WINDOW.FontAwesomeDetection || {}; // These can be overridden
  816. var _default = {
  817. report: report,
  818. timeout: +(DOCUMENT.currentScript.getAttribute(timeoutAttr) || "2000"),
  819. resultsCollectionMaxWait: +(DOCUMENT.currentScript.getAttribute(resultsCollectionMaxWaitAttr) || "5000")
  820. };
  821. var _config = _objectSpread({}, _default, initialConfig, {
  822. // These cannot be overridden
  823. __pollUntil: pollUntil,
  824. md5ForNode: md5ForNode,
  825. detectionDone: false,
  826. nodesTested: null,
  827. nodesFound: null
  828. });
  829. WINDOW.FontAwesomeDetection = _config;
  830. var PRODUCTION = function () {
  831. try {
  832. return process.env.NODE_ENV === 'production';
  833. } catch (e) {
  834. return false;
  835. }
  836. }();
  837. function bunker(fn) {
  838. try {
  839. fn();
  840. } catch (e) {
  841. if (!PRODUCTION) {
  842. throw e;
  843. }
  844. }
  845. }
  846. bunker(function () {
  847. if (IS_BROWSER && IS_DOM) {
  848. conflictDetection(window.FontAwesomeDetection.report);
  849. }
  850. });
  851. exports.conflictDetection = conflictDetection;
  852. Object.defineProperty(exports, '__esModule', { value: true });
  853. })));