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