1/*! 2 * css-vars-ponyfill 3 * v2.3.2 4 * https://jhildenbiddle.github.io/css-vars-ponyfill/ 5 * (c) 2018-2020 John Hildenbiddle <http://hildenbiddle.com> 6 * MIT license 7 */ 8(function(global, factory) { 9 typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = global || self, 10 global.cssVars = factory()); 11})(this, (function() { 12 "use strict"; 13 function _extends() { 14 _extends = Object.assign || function(target) { 15 for (var i = 1; i < arguments.length; i++) { 16 var source = arguments[i]; 17 for (var key in source) { 18 if (Object.prototype.hasOwnProperty.call(source, key)) { 19 target[key] = source[key]; 20 } 21 } 22 } 23 return target; 24 }; 25 return _extends.apply(this, arguments); 26 } 27 function _toConsumableArray(arr) { 28 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); 29 } 30 function _arrayWithoutHoles(arr) { 31 if (Array.isArray(arr)) return _arrayLikeToArray(arr); 32 } 33 function _iterableToArray(iter) { 34 if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); 35 } 36 function _unsupportedIterableToArray(o, minLen) { 37 if (!o) return; 38 if (typeof o === "string") return _arrayLikeToArray(o, minLen); 39 var n = Object.prototype.toString.call(o).slice(8, -1); 40 if (n === "Object" && o.constructor) n = o.constructor.name; 41 if (n === "Map" || n === "Set") return Array.from(o); 42 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); 43 } 44 function _arrayLikeToArray(arr, len) { 45 if (len == null || len > arr.length) len = arr.length; 46 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; 47 return arr2; 48 } 49 function _nonIterableSpread() { 50 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); 51 } 52 /*! 53 * get-css-data 54 * v1.8.0 55 * https://github.com/jhildenbiddle/get-css-data 56 * (c) 2018-2020 John Hildenbiddle <http://hildenbiddle.com> 57 * MIT license 58 */ function getUrls(urls) { 59 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 60 var settings = { 61 mimeType: options.mimeType || null, 62 onBeforeSend: options.onBeforeSend || Function.prototype, 63 onSuccess: options.onSuccess || Function.prototype, 64 onError: options.onError || Function.prototype, 65 onComplete: options.onComplete || Function.prototype 66 }; 67 var urlArray = Array.isArray(urls) ? urls : [ urls ]; 68 var urlQueue = Array.apply(null, Array(urlArray.length)).map((function(x) { 69 return null; 70 })); 71 function isValidCss() { 72 var cssText = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; 73 var isHTML = cssText.trim().charAt(0) === "<"; 74 return !isHTML; 75 } 76 function onError(xhr, urlIndex) { 77 settings.onError(xhr, urlArray[urlIndex], urlIndex); 78 } 79 function onSuccess(responseText, urlIndex) { 80 var returnVal = settings.onSuccess(responseText, urlArray[urlIndex], urlIndex); 81 responseText = returnVal === false ? "" : returnVal || responseText; 82 urlQueue[urlIndex] = responseText; 83 if (urlQueue.indexOf(null) === -1) { 84 settings.onComplete(urlQueue); 85 } 86 } 87 var parser = document.createElement("a"); 88 urlArray.forEach((function(url, i) { 89 parser.setAttribute("href", url); 90 parser.href = String(parser.href); 91 var isIElte9 = Boolean(document.all && !window.atob); 92 var isIElte9CORS = isIElte9 && parser.host.split(":")[0] !== location.host.split(":")[0]; 93 if (isIElte9CORS) { 94 var isSameProtocol = parser.protocol === location.protocol; 95 if (isSameProtocol) { 96 var xdr = new XDomainRequest;
97 xdr.open("GET", url); 98 xdr.timeout = 0; 99 xdr.onprogress = Function.prototype; 100 xdr.ontimeout = Function.prototype; 101 xdr.onload = function() { 102 if (isValidCss(xdr.responseText)) { 103 onSuccess(xdr.responseText, i); 104 } else { 105 onError(xdr, i); 106 } 107 }; 108 xdr.onerror = function(err) { 109 onError(xdr, i); 110 }; 111 setTimeout((function() { 112 xdr.send(); 113 }), 0); 114 } else { 115 console.warn("Internet Explorer 9 Cross-Origin (CORS) requests must use the same protocol (".concat(url, ")")); 116 onError(null, i); 117 } 118 } else { 119 var xhr = new XMLHttpRequest; 120 xhr.open("GET", url); 121 if (settings.mimeType && xhr.overrideMimeType) { 122 xhr.overrideMimeType(settings.mimeType); 123 } 124 settings.onBeforeSend(xhr, url, i); 125 xhr.onreadystatechange = function() { 126 if (xhr.readyState === 4) { 127 if (xhr.status === 200 && isValidCss(xhr.responseText)) { 128 onSuccess(xhr.responseText, i); 129 } else { 130 onError(xhr, i); 131 } 132 } 133 }; 134 xhr.send(); 135 } 136 })); 137 } 138 /** 139 * Gets CSS data from <style> and <link> nodes (including @imports), then 140 * returns data in order processed by DOM. Allows specifying nodes to 141 * include/exclude and filtering CSS data using RegEx. 142 * 143 * @preserve 144 * @param {object} [options] The options object 145 * @param {object} [options.rootElement=document] Root element to traverse for 146 * <link> and <style> nodes. 147 * @param {string} [options.include] CSS selector matching <link> and <style> 148 * nodes to include 149 * @param {string} [options.exclude] CSS selector matching <link> and <style> 150 * nodes to exclude 151 * @param {object} [options.filter] Regular expression used to filter node CSS 152 * data. Each block of CSS data is tested against the filter, 153 * and only matching data is included. 154 * @param {boolean} [options.skipDisabled=true] Determines if disabled 155 * stylesheets will be skipped while collecting CSS data. 156 * @param {boolean} [options.useCSSOM=false] Determines if CSS data will be 157 * collected from a stylesheet's runtime values instead of its 158 * text content. This is required to get accurate CSS data 159 * when a stylesheet has been modified using the deleteRule() 160 * or insertRule() methods because these modifications will 161 * not be reflected in the stylesheet's text content. 162 * @param {function} [options.onBeforeSend] Callback before XHR is sent. Passes 163 * 1) the XHR object, 2) source node reference, and 3) the 164 * source URL as arguments. 165 * @param {function} [options.onSuccess] Callback on each CSS node read. Passes 166 * 1) CSS text, 2) source node reference, and 3) the source 167 * URL as arguments. 168 * @param {function} [options.onError] Callback on each error. Passes 1) the XHR 169 * object for inspection, 2) soure node reference, and 3) the 170 * source URL that failed (either a <link> href or an @import) 171 * as arguments 172 * @param {function} [options.onComplete] Callback after all nodes have been 173 * processed. Passes 1) concatenated CSS text, 2) an array of 174 * CSS text in DOM order, and 3) an array of nodes in DOM 175 * order as arguments. 176 * 177 * @example 178 * 179 * getCssData({ 180 * rootElement : document, 181 * include : 'style,link[rel="stylesheet"]', 182 * exclude : '[href="skip.css"]', 183 * filter : /red/, 184 * skipDisabled: true, 185 * useCSSOM : false, 186 * onBeforeSend(xhr, node, url) { 187 * // ... 188 * } 189 * onSuccess(cssText, node, url) { 190 * // ... 191 * } 192 * onError(xhr, node, url) { 193 * // ... 194 * }, 195 * onComplete(cssText, cssArray, nodeArray) { 196 * // ... 197 * } 198 * }); 199 */ function getCssData(options) { 200 var regex = { 201 cssComments: /\/\*[\s\S]+?\*\//g,
vendor: 4,221 bytes, lines 202-277
202 cssImports: /(?:@import\s*)(?:url\(\s*)?(?:['"])([^'"]*)(?:['"])(?:\s*\))?(?:[^;]*;)/g 203 }; 204 var settings = { 205 rootElement: options.rootElement || document, 206 include: options.include || 'style,link[rel="stylesheet"]', 207 exclude: options.exclude || null, 208 filter: options.filter || null, 209 skipDisabled: options.skipDisabled !== false, 210 useCSSOM: options.useCSSOM || false, 211 onBeforeSend: options.onBeforeSend || Function.prototype, 212 onSuccess: options.onSuccess || Function.prototype, 213 onError: options.onError || Function.prototype, 214 onComplete: options.onComplete || Function.prototype 215 }; 216 var sourceNodes = Array.apply(null, settings.rootElement.querySelectorAll(settings.include)).filter((function(node) { 217 return !matchesSelector(node, settings.exclude); 218 })); 219 var cssArray = Array.apply(null, Array(sourceNodes.length)).map((function(x) { 220 return null; 221 })); 222 function handleComplete() { 223 var isComplete = cssArray.indexOf(null) === -1; 224 if (isComplete) { 225 var cssText = cssArray.join(""); 226 settings.onComplete(cssText, cssArray, sourceNodes); 227 } 228 } 229 function handleSuccess(cssText, cssIndex, node, sourceUrl) { 230 var returnVal = settings.onSuccess(cssText, node, sourceUrl); 231 cssText = returnVal !== undefined && Boolean(returnVal) === false ? "" : returnVal || cssText; 232 resolveImports(cssText, node, sourceUrl, (function(resolvedCssText, errorData) { 233 if (cssArray[cssIndex] === null) { 234 errorData.forEach((function(data) { 235 return settings.onError(data.xhr, node, data.url); 236 })); 237 if (!settings.filter || settings.filter.test(resolvedCssText)) { 238 cssArray[cssIndex] = resolvedCssText; 239 } else { 240 cssArray[cssIndex] = ""; 241 } 242 handleComplete(); 243 } 244 })); 245 } 246 function parseImportData(cssText, baseUrl) { 247 var ignoreRules = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; 248 var importData = {}; 249 importData.rules = (cssText.replace(regex.cssComments, "").match(regex.cssImports) || []).filter((function(rule) { 250 return ignoreRules.indexOf(rule) === -1; 251 })); 252 importData.urls = importData.rules.map((function(rule) { 253 return rule.replace(regex.cssImports, "$1"); 254 })); 255 importData.absoluteUrls = importData.urls.map((function(url) { 256 return getFullUrl(url, baseUrl); 257 })); 258 importData.absoluteRules = importData.rules.map((function(rule, i) { 259 var oldUrl = importData.urls[i]; 260 var newUrl = getFullUrl(importData.absoluteUrls[i], baseUrl); 261 return rule.replace(oldUrl, newUrl); 262 })); 263 return importData; 264 } 265 function resolveImports(cssText, node, baseUrl, callbackFn) { 266 var __errorData = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : []; 267 var __errorRules = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : []; 268 var importData = parseImportData(cssText, baseUrl, __errorRules); 269 if (importData.rules.length) { 270 getUrls(importData.absoluteUrls, { 271 onBeforeSend: function onBeforeSend(xhr, url, urlIndex) { 272 settings.onBeforeSend(xhr, node, url); 273 }, 274 onSuccess: function onSuccess(cssText, url, urlIndex) { 275 var returnVal = settings.onSuccess(cssText, node, url); 276 cssText = returnVal === false ? "" : returnVal || cssText; 277 var responseImportData = parseImportData(cssText, url, __errorRules);
vendor: 8,564 bytes, lines 278-492
278 responseImportData.rules.forEach((function(rule, i) { 279 cssText = cssText.replace(rule, responseImportData.absoluteRules[i]); 280 })); 281 return cssText; 282 }, 283 onError: function onError(xhr, url, urlIndex) { 284 __errorData.push({ 285 xhr: xhr, 286 url: url 287 }); 288 __errorRules.push(importData.rules[urlIndex]); 289 resolveImports(cssText, node, baseUrl, callbackFn, __errorData, __errorRules); 290 }, 291 onComplete: function onComplete(responseArray) { 292 responseArray.forEach((function(importText, i) { 293 cssText = cssText.replace(importData.rules[i], importText); 294 })); 295 resolveImports(cssText, node, baseUrl, callbackFn, __errorData, __errorRules); 296 } 297 }); 298 } else { 299 callbackFn(cssText, __errorData); 300 } 301 } 302 if (sourceNodes.length) { 303 sourceNodes.forEach((function(node, i) { 304 var linkHref = node.getAttribute("href"); 305 var linkRel = node.getAttribute("rel"); 306 var isLink = node.nodeName === "LINK" && linkHref && linkRel && linkRel.toLowerCase().indexOf("stylesheet") !== -1; 307 var isSkip = settings.skipDisabled === false ? false : node.disabled; 308 var isStyle = node.nodeName === "STYLE"; 309 if (isLink && !isSkip) { 310 getUrls(linkHref, { 311 mimeType: "text/css", 312 onBeforeSend: function onBeforeSend(xhr, url, urlIndex) { 313 settings.onBeforeSend(xhr, node, url); 314 }, 315 onSuccess: function onSuccess(cssText, url, urlIndex) { 316 var sourceUrl = getFullUrl(linkHref); 317 handleSuccess(cssText, i, node, sourceUrl); 318 }, 319 onError: function onError(xhr, url, urlIndex) { 320 cssArray[i] = ""; 321 settings.onError(xhr, node, url); 322 handleComplete(); 323 } 324 }); 325 } else if (isStyle && !isSkip) { 326 var cssText = node.textContent; 327 if (settings.useCSSOM) { 328 cssText = Array.apply(null, node.sheet.cssRules).map((function(rule) { 329 return rule.cssText; 330 })).join(""); 331 } 332 handleSuccess(cssText, i, node, location.href); 333 } else { 334 cssArray[i] = ""; 335 handleComplete(); 336 } 337 })); 338 } else { 339 settings.onComplete("", []); 340 } 341 } 342 function getFullUrl(url, base) { 343 var d = document.implementation.createHTMLDocument(""); 344 var b = d.createElement("base"); 345 var a = d.createElement("a"); 346 d.head.appendChild(b); 347 d.body.appendChild(a); 348 b.href = base || document.baseURI || (document.querySelector("base") || {}).href || location.href; 349 a.href = url; 350 return a.href; 351 } 352 function matchesSelector(elm, selector) { 353 var matches = elm.matches || elm.matchesSelector || elm.webkitMatchesSelector || elm.mozMatchesSelector || elm.msMatchesSelector || elm.oMatchesSelector; 354 return matches.call(elm, selector); 355 } 356 var balancedMatch = balanced; 357 function balanced(a, b, str) { 358 if (a instanceof RegExp) a = maybeMatch(a, str); 359 if (b instanceof RegExp) b = maybeMatch(b, str); 360 var r = range(a, b, str); 361 return r && { 362 start: r[0], 363 end: r[1], 364 pre: str.slice(0, r[0]), 365 body: str.slice(r[0] + a.length, r[1]), 366 post: str.slice(r[1] + b.length) 367 }; 368 } 369 function maybeMatch(reg, str) { 370 var m = str.match(reg); 371 return m ? m[0] : null; 372 } 373 balanced.range = range; 374 function range(a, b, str) { 375 var begs, beg, left, right, result; 376 var ai = str.indexOf(a); 377 var bi = str.indexOf(b, ai + 1); 378 var i = ai; 379 if (ai >= 0 && bi > 0) { 380 begs = []; 381 left = str.length; 382 while (i >= 0 && !result) { 383 if (i == ai) { 384 begs.push(i); 385 ai = str.indexOf(a, i + 1); 386 } else if (begs.length == 1) { 387 result = [ begs.pop(), bi ]; 388 } else { 389 beg = begs.pop(); 390 if (beg < left) { 391 left = beg; 392 right = bi; 393 } 394 bi = str.indexOf(b, i + 1); 395 } 396 i = ai < bi && ai >= 0 ? ai : bi; 397 } 398 if (begs.length) { 399 result = [ left, right ]; 400 } 401 } 402 return result; 403 } 404 function parseCss(css) { 405 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 406 var defaults = { 407 preserveStatic: true, 408 removeComments: false 409 }; 410 var settings = _extends({}, defaults, options); 411 var errors = []; 412 function error(msg) { 413 throw new Error("CSS parse error: ".concat(msg)); 414 } 415 function match(re) { 416 var m = re.exec(css); 417 if (m) { 418 css = css.slice(m[0].length); 419 return m; 420 } 421 } 422 function open() { 423 return match(/^{\s*/); 424 } 425 function close() { 426 return match(/^}/); 427 } 428 function whitespace() { 429 match(/^\s*/); 430 } 431 function comment() { 432 whitespace(); 433 if (css[0] !== "/" || css[1] !== "*") { 434 return; 435 } 436 var i = 2; 437 while (css[i] && (css[i] !== "*" || css[i + 1] !== "/")) { 438 i++; 439 } 440 if (!css[i]) { 441 return error("end of comment is missing"); 442 } 443 var str = css.slice(2, i); 444 css = css.slice(i + 2); 445 return { 446 type: "comment", 447 comment: str 448 }; 449 } 450 function comments() { 451 var cmnts = []; 452 var c; 453 while (c = comment()) { 454 cmnts.push(c); 455 } 456 return settings.removeComments ? [] : cmnts; 457 } 458 function selector() { 459 whitespace(); 460 while (css[0] === "}") { 461 error("extra closing bracket"); 462 } 463 var m = match(/^(("(?:\\"|[^"])*"|'(?:\\'|[^'])*'|[^{])+)/); 464 if (m) { 465 return m[0].trim().replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, "").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, (function(m) { 466 return m.replace(/,/g, "‌"); 467 })).split(/\s*(?![^(]*\)),\s*/).map((function(s) { 468 return s.replace(/\u200C/g, ","); 469 })); 470 } 471 } 472 function declaration() { 473 if (css[0] === "@") { 474 return at_rule(); 475 } 476 match(/^([;\s]*)+/); 477 var comment_regexp = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g; 478 var prop = match(/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/); 479 if (!prop) { 480 return; 481 } 482 prop = prop[0].trim(); 483 if (!match(/^:\s*/)) { 484 return error("property missing ':'"); 485 } 486 var val = match(/^((?:\/\*.*?\*\/|'(?:\\'|.)*?'|"(?:\\"|.)*?"|\((\s*'(?:\\'|.)*?'|"(?:\\"|.)*?"|[^)]*?)\s*\)|[^};])+)/); 487 var ret = { 488 type: "declaration", 489 property: prop.replace(comment_regexp, ""), 490 value: val ? val[0].replace(comment_regexp, "").trim() : "" 491 }; 492 match(/^[;
vendor: 23,141 bytes, lines 492-1045
492\s]*/); 493 return ret; 494 } 495 function declarations() { 496 if (!open()) { 497 return error("missing '{'"); 498 } 499 var d; 500 var decls = comments(); 501 while (d = declaration()) { 502 decls.push(d); 503 decls = decls.concat(comments()); 504 } 505 if (!close()) { 506 return error("missing '}'"); 507 } 508 return decls; 509 } 510 function keyframe() { 511 whitespace(); 512 var vals = []; 513 var m; 514 while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) { 515 vals.push(m[1]); 516 match(/^,\s*/); 517 } 518 if (vals.length) { 519 return { 520 type: "keyframe", 521 values: vals, 522 declarations: declarations() 523 }; 524 } 525 } 526 function at_keyframes() { 527 var m = match(/^@([-\w]+)?keyframes\s*/); 528 if (!m) { 529 return; 530 } 531 var vendor = m[1]; 532 m = match(/^([-\w]+)\s*/); 533 if (!m) { 534 return error("@keyframes missing name"); 535 } 536 var name = m[1]; 537 if (!open()) { 538 return error("@keyframes missing '{'"); 539 } 540 var frame; 541 var frames = comments(); 542 while (frame = keyframe()) { 543 frames.push(frame); 544 frames = frames.concat(comments()); 545 } 546 if (!close()) { 547 return error("@keyframes missing '}'"); 548 } 549 return { 550 type: "keyframes", 551 name: name, 552 vendor: vendor, 553 keyframes: frames 554 }; 555 } 556 function at_page() { 557 var m = match(/^@page */); 558 if (m) { 559 var sel = selector() || []; 560 return { 561 type: "page", 562 selectors: sel, 563 declarations: declarations() 564 }; 565 } 566 } 567 function at_page_margin_box() { 568 var m = match(/@(top|bottom|left|right)-(left|center|right|top|middle|bottom)-?(corner)?\s*/); 569 if (m) { 570 var name = "".concat(m[1], "-").concat(m[2]) + (m[3] ? "-".concat(m[3]) : ""); 571 return { 572 type: "page-margin-box", 573 name: name, 574 declarations: declarations() 575 }; 576 } 577 } 578 function at_fontface() { 579 var m = match(/^@font-face\s*/); 580 if (m) { 581 return { 582 type: "font-face", 583 declarations: declarations() 584 }; 585 } 586 } 587 function at_supports() { 588 var m = match(/^@supports *([^{]+)/); 589 if (m) { 590 return { 591 type: "supports", 592 supports: m[1].trim(), 593 rules: rules() 594 }; 595 } 596 } 597 function at_host() { 598 var m = match(/^@host\s*/); 599 if (m) { 600 return { 601 type: "host", 602 rules: rules() 603 }; 604 } 605 } 606 function at_media() { 607 var m = match(/^@media([^{]+)*/); 608 if (m) { 609 return { 610 type: "media", 611 media: (m[1] || "").trim(), 612 rules: rules() 613 }; 614 } 615 } 616 function at_custom_m() { 617 var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/); 618 if (m) { 619 return { 620 type: "custom-media", 621 name: m[1].trim(), 622 media: m[2].trim() 623 }; 624 } 625 } 626 function at_document() { 627 var m = match(/^@([-\w]+)?document *([^{]+)/); 628 if (m) { 629 return { 630 type: "document", 631 document: m[2].trim(), 632 vendor: m[1] ? m[1].trim() : null, 633 rules: rules() 634 }; 635 } 636 } 637 function at_x() { 638 var m = match(/^@(import|charset|namespace)\s*([^;]+);/); 639 if (m) { 640 return { 641 type: m[1], 642 name: m[2].trim() 643 }; 644 } 645 } 646 function at_rule() { 647 whitespace(); 648 if (css[0] === "@") { 649 var ret = at_x() || at_fontface() || at_media() || at_keyframes() || at_supports() || at_document() || at_custom_m() || at_host() || at_page() || at_page_margin_box(); 650 if (ret && !settings.preserveStatic) { 651 var hasVarFunc = false; 652 if (ret.declarations) { 653 hasVarFunc = ret.declarations.some((function(decl) { 654 return /var\(/.test(decl.value); 655 })); 656 } else { 657 var arr = ret.keyframes || ret.rules || []; 658 hasVarFunc = arr.some((function(obj) { 659 return (obj.declarations || []).some((function(decl) { 660 return /var\(/.test(decl.value); 661 })); 662 })); 663 } 664 return hasVarFunc ? ret : {}; 665 } 666 return ret; 667 } 668 } 669 function rule() { 670 if (!settings.preserveStatic) { 671 var balancedMatch$1 = balancedMatch("{", "}", css); 672 if (balancedMatch$1) { 673 var hasVarDecl = /:(?:root|host)(?![.:#(])/.test(balancedMatch$1.pre) && /--\S*\s*:/.test(balancedMatch$1.body); 674 var hasVarFunc = /var\(/.test(balancedMatch$1.body); 675 if (!hasVarDecl && !hasVarFunc) { 676 css = css.slice(balancedMatch$1.end + 1); 677 return {}; 678 } 679 } 680 } 681 var sel = selector() || []; 682 var decls = settings.preserveStatic ? declarations() : declarations().filter((function(decl) { 683 var hasVarDecl = sel.some((function(s) { 684 return /:(?:root|host)(?![.:#(])/.test(s); 685 })) && /^--\S/.test(decl.property); 686 var hasVarFunc = /var\(/.test(decl.value); 687 return hasVarDecl || hasVarFunc; 688 })); 689 if (!sel.length) { 690 error("selector missing"); 691 } 692 return { 693 type: "rule", 694 selectors: sel, 695 declarations: decls 696 }; 697 } 698 function rules(core) { 699 if (!core && !open()) { 700 return error("missing '{'"); 701 } 702 var node; 703 var rules = comments(); 704 while (css.length && (core || css[0] !== "}") && (node = at_rule() || rule())) { 705 if (node.type) { 706 rules.push(node); 707 } 708 rules = rules.concat(comments()); 709 } 710 if (!core && !close()) { 711 return error("missing '}'"); 712 } 713 return rules; 714 } 715 return { 716 type: "stylesheet", 717 stylesheet: { 718 rules: rules(true), 719 errors: errors 720 } 721 }; 722 } 723 function parseVars(cssData) { 724 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 725 var defaults = { 726 parseHost: false, 727 store: {}, 728 onWarning: function onWarning() {} 729 }; 730 var settings = _extends({}, defaults, options); 731 var reVarDeclSelectors = new RegExp(":".concat(settings.parseHost ? "host" : "root", "$")); 732 if (typeof cssData === "string") { 733 cssData = parseCss(cssData, settings); 734 } 735 cssData.stylesheet.rules.forEach((function(rule) { 736 if (rule.type !== "rule" || !rule.selectors.some((function(s) { 737 return reVarDeclSelectors.test(s); 738 }))) { 739 return; 740 } 741 rule.declarations.forEach((function(decl, i) { 742 var prop = decl.property; 743 var value = decl.value; 744 if (prop && prop.indexOf("--") === 0) { 745 settings.store[prop] = value; 746 } 747 })); 748 })); 749 return settings.store; 750 } 751 function stringifyCss(tree) { 752 var delim = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ""; 753 var cb = arguments.length > 2 ? arguments[2] : undefined; 754 var renderMethods = { 755 charset: function charset(node) { 756 return "@charset " + node.name + ";"; 757 }, 758 comment: function comment(node) { 759 return node.comment.indexOf("__CSSVARSPONYFILL") === 0 ? "/*" + node.comment + "*/" : ""; 760 }, 761 "custom-media": function customMedia(node) { 762 return "@custom-media " + node.name + " " + node.media + ";"; 763 }, 764 declaration: function declaration(node) { 765 return node.property + ":" + node.value + ";"; 766 }, 767 document: function document(node) { 768 return "@" + (node.vendor || "") + "document " + node.document + "{" + visit(node.rules) + "}"; 769 }, 770 "font-face": function fontFace(node) { 771 return "@font-face" + "{" + visit(node.declarations) + "}"; 772 }, 773 host: function host(node) { 774 return "@host" + "{" + visit(node.rules) + "}"; 775 }, 776 import: function _import(node) { 777 return "@import " + node.name + ";"; 778 }, 779 keyframe: function keyframe(node) { 780 return node.values.join(",") + "{" + visit(node.declarations) + "}"; 781 }, 782 keyframes: function keyframes(node) { 783 return "@" + (node.vendor || "") + "keyframes " + node.name + "{" + visit(node.keyframes) + "}"; 784 }, 785 media: function media(node) { 786 return "@media " + node.media + "{" + visit(node.rules) + "}"; 787 }, 788 namespace: function namespace(node) { 789 return "@namespace " + node.name + ";"; 790 }, 791 page: function page(node) { 792 return "@page " + (node.selectors.length ? node.selectors.join(", ") : "") + "{" + visit(node.declarations) + "}"; 793 }, 794 "page-margin-box": function pageMarginBox(node) { 795 return "@" + node.name + "{" + visit(node.declarations) + "}"; 796 }, 797 rule: function rule(node) { 798 var decls = node.declarations; 799 if (decls.length) { 800 return node.selectors.join(",") + "{" + visit(decls) + "}"; 801 } 802 }, 803 supports: function supports(node) { 804 return "@supports " + node.supports + "{" + visit(node.rules) + "}"; 805 } 806 }; 807 function visit(nodes) { 808 var buf = ""; 809 for (var i = 0; i < nodes.length; i++) { 810 var n = nodes[i]; 811 if (cb) { 812 cb(n); 813 } 814 var txt = renderMethods[n.type](n); 815 if (txt) { 816 buf += txt; 817 if (txt.length && n.selectors) { 818 buf += delim; 819 } 820 } 821 } 822 return buf; 823 } 824 return visit(tree.stylesheet.rules); 825 } 826 function walkCss(node, fn) { 827 node.rules.forEach((function(rule) { 828 if (rule.rules) { 829 walkCss(rule, fn); 830 return; 831 } 832 if (rule.keyframes) { 833 rule.keyframes.forEach((function(keyframe) { 834 if (keyframe.type === "keyframe") { 835 fn(keyframe.declarations, rule); 836 } 837 })); 838 return; 839 } 840 if (!rule.declarations) { 841 return; 842 } 843 fn(rule.declarations, node); 844 })); 845 } 846 var VAR_PROP_IDENTIFIER = "--"; 847 var VAR_FUNC_IDENTIFIER = "var"; 848 function transformCss(cssData) { 849 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 850 var defaults = { 851 preserveStatic: true, 852 preserveVars: false, 853 variables: {}, 854 onWarning: function onWarning() {} 855 }; 856 var settings = _extends({}, defaults, options); 857 if (typeof cssData === "string") { 858 cssData = parseCss(cssData, settings); 859 } 860 walkCss(cssData.stylesheet, (function(declarations, node) { 861 for (var i = 0; i < declarations.length; i++) { 862 var decl = declarations[i]; 863 var type = decl.type; 864 var prop = decl.property; 865 var value = decl.value; 866 if (type !== "declaration") { 867 continue; 868 } 869 if (!settings.preserveVars && prop && prop.indexOf(VAR_PROP_IDENTIFIER) === 0) { 870 declarations.splice(i, 1); 871 i--; 872 continue; 873 } 874 if (value.indexOf(VAR_FUNC_IDENTIFIER + "(") !== -1) { 875 var resolvedValue = resolveValue(value, settings); 876 if (resolvedValue !== decl.value) { 877 resolvedValue = fixNestedCalc(resolvedValue); 878 if (!settings.preserveVars) { 879 decl.value = resolvedValue; 880 } else { 881 declarations.splice(i, 0, { 882 type: type, 883 property: prop, 884 value: resolvedValue 885 }); 886 i++; 887 } 888 } 889 } 890 } 891 })); 892 return stringifyCss(cssData); 893 } 894 function fixNestedCalc(value) { 895 var reCalcVal = /calc\(([^)]+)\)/g; 896 (value.match(reCalcVal) || []).forEach((function(match) { 897 var newVal = "calc".concat(match.split("calc").join("")); 898 value = value.replace(match, newVal); 899 })); 900 return value; 901 } 902 function resolveValue(value) { 903 var settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 904 var __recursiveFallback = arguments.length > 2 ? arguments[2] : undefined; 905 if (value.indexOf("var(") === -1) { 906 return value; 907 } 908 var valueData = balancedMatch("(", ")", value); 909 function resolveFunc(value) { 910 var name = value.split(",")[0].replace(/[\s\n\t]/g, ""); 911 var fallback = (value.match(/(?:\s*,\s*){1}(.*)?/) || [])[1]; 912 var match = Object.prototype.hasOwnProperty.call(settings.variables, name) ? String(settings.variables[name]) : undefined; 913 var replacement = match || (fallback ? String(fallback) : undefined); 914 var unresolvedFallback = __recursiveFallback || value; 915 if (!match) { 916 settings.onWarning('variable "'.concat(name, '" is undefined')); 917 } 918 if (replacement && replacement !== "undefined" && replacement.length > 0) { 919 return resolveValue(replacement, settings, unresolvedFallback); 920 } else { 921 return "var(".concat(unresolvedFallback, ")"); 922 } 923 } 924 if (!valueData) { 925 if (value.indexOf("var(") !== -1) { 926 settings.onWarning('missing closing ")" in the value "'.concat(value, '"')); 927 } 928 return value; 929 } else if (valueData.pre.slice(-3) === "var") { 930 var isEmptyVarFunc = valueData.body.trim().length === 0; 931 if (isEmptyVarFunc) { 932 settings.onWarning("var() must contain a non-whitespace string"); 933 return value; 934 } else { 935 return valueData.pre.slice(0, -3) + resolveFunc(valueData.body) + resolveValue(valueData.post, settings); 936 } 937 } else { 938 return valueData.pre + "(".concat(resolveValue(valueData.body, settings), ")") + resolveValue(valueData.post, settings); 939 } 940 } 941 var isBrowser = typeof window !== "undefined"; 942 var isNativeSupport = isBrowser && window.CSS && window.CSS.supports && window.CSS.supports("(--a: 0)"); 943 var counters = { 944 group: 0, 945 job: 0 946 }; 947 var defaults = { 948 rootElement: isBrowser ? document : null, 949 shadowDOM: false, 950 include: "style,link[rel=stylesheet]", 951 exclude: "", 952 variables: {}, 953 onlyLegacy: true, 954 preserveStatic: true, 955 preserveVars: false, 956 silent: false, 957 updateDOM: true, 958 updateURLs: true, 959 watch: null, 960 onBeforeSend: function onBeforeSend() {}, 961 onError: function onError() {}, 962 onWarning: function onWarning() {}, 963 onSuccess: function onSuccess() {}, 964 onComplete: function onComplete() {}, 965 onFinally: function onFinally() {} 966 }; 967 var regex = { 968 cssComments: /\/\*[\s\S]+?\*\//g, 969 cssKeyframes: /@(?:-\w*-)?keyframes/, 970 cssMediaQueries: /@media[^{]+\{([\s\S]+?})\s*}/g, 971 cssUrls: /url\((?!['"]?(?:data|http|\/\/):)['"]?([^'")]*)['"]?\)/g, 972 cssVarDeclRules: /(?::(?:root|host)(?![.:#(])[\s,]*[^{]*{\s*[^}]*})/g, 973 cssVarDecls: /(?:[\s;]*)(-{2}\w[\w-]*)(?:\s*:\s*)([^;]*);/g, 974 cssVarFunc: /var\(\s*--[\w-]/, 975 cssVars: /(?:(?::(?:root|host)(?![.:#(])[\s,]*[^{]*{\s*[^;]*;*\s*)|(?:var\(\s*))(--[^:)]+)(?:\s*[:)])/ 976 }; 977 var variableStore = { 978 dom: {}, 979 job: {}, 980 user: {} 981 }; 982 var cssVarsIsRunning = false; 983 var cssVarsObserver = null; 984 var cssVarsSrcNodeCount = 0; 985 var debounceTimer = null; 986 var isShadowDOMReady = false; 987 /** 988 * Fetches, parses, and transforms CSS custom properties from specified 989 * <style> and <link> elements into static values, then appends a new <style> 990 * element with static values to the DOM to provide CSS custom property 991 * compatibility for legacy browsers. Also provides a single interface for 992 * live updates of runtime values in both modern and legacy browsers. 993 * 994 * @preserve 995 * @param {object} [options] Options object 996 * @param {object} [options.rootElement=document] Root element to traverse for 997 * <link> and <style> nodes 998 * @param {boolean} [options.shadowDOM=false] Determines if shadow DOM <link> 999 * and <style> nodes will be processed. 1000 * @param {string} [options.include="style,link[rel=stylesheet]"] CSS selector 1001 * matching <link re="stylesheet"> and <style> nodes to 1002 * process 1003 * @param {string} [options.exclude] CSS selector matching <link 1004 * rel="stylehseet"> and <style> nodes to exclude from those 1005 * matches by options.include 1006 * @param {object} [options.variables] A map of custom property name/value 1007 * pairs. Property names can omit or include the leading 1008 * double-hyphen (—), and values specified will override 1009 * previous values 1010 * @param {boolean} [options.onlyLegacy=true] Determines if the ponyfill will 1011 * only generate legacy-compatible CSS in browsers that lack 1012 * native support (i.e., legacy browsers) 1013 * @param {boolean} [options.preserveStatic=true] Determines if CSS 1014 * declarations that do not reference a custom property will 1015 * be preserved in the transformed CSS 1016 * @param {boolean} [options.preserveVars=false] Determines if CSS custom 1017 * property declarations will be preserved in the transformed 1018 * CSS 1019 * @param {boolean} [options.silent=false] Determines if warning and error 1020 * messages will be displayed on the console 1021 * @param {boolean} [options.updateDOM=true] Determines if the ponyfill will 1022 * update the DOM after processing CSS custom properties 1023 * @param {boolean} [options.updateURLs=true] Determines if relative url() 1024 * paths will be converted to absolute urls in external CSS 1025 * @param {boolean} [options.watch=false] Determines if a MutationObserver will 1026 * be created that will execute the ponyfill when a <link> or 1027 * <style> DOM mutation is observed 1028 * @param {function} [options.onBeforeSend] Callback before XHR is sent. Passes 1029 * 1) the XHR object, 2) source node reference, and 3) the 1030 * source URL as arguments 1031 * @param {function} [options.onError] Callback after a CSS parsing error has 1032 * occurred or an XHR request has failed. Passes 1) an error 1033 * message, and 2) source node reference, 3) xhr, and 4 url as 1034 * arguments. 1035 * @param {function} [options.onWarning] Callback after each CSS parsing warning 1036 * has occurred. Passes 1) a warning message as an argument. 1037 * @param {function} [options.onSuccess] Callback after CSS data has been 1038 * collected from each node and before CSS custom properties 1039 * have been transformed. Allows modifying the CSS data before 1040 * it is transformed by returning any string value (or false 1041 * to skip). Passes 1) CSS text, 2) source node reference, and 1042 * 3) the source URL as arguments. 1043 * @param {function} [options.onComplete] Callback after all CSS has been 1044 * processed, legacy-compatible CSS has been generated, and 1045 * (optionally) the DOM has been updated. Passes 1) a CSS
1046 * string with CSS variable values resolved, 2) an array of 1047 * output <style> node references that have been appended to 1048 * the DOM, 3) an object containing all custom properies names 1049 * and values, and 4) the ponyfill execution time in 1050 * milliseconds. 1051 * @param {function} [options.onFinally] Callback in modern and legacy browsers 1052 * after the ponyfill has finished all tasks. Passes 1) a 1053 * boolean indicating if the last ponyfill call resulted in a 1054 * style change, 2) a boolean indicating if the current 1055 * browser provides native support for CSS custom properties, 1056 * and 3) the ponyfill execution time in milliseconds. 1057 * @example 1058 * 1059 * cssVars({ 1060 * rootElement : document, 1061 * shadowDOM : false, 1062 * include : 'style,link[rel="stylesheet"]', 1063 * exclude : '', 1064 * variables : {}, 1065 * onlyLegacy : true, 1066 * preserveStatic: true, 1067 * preserveVars : false, 1068 * silent : false, 1069 * updateDOM : true, 1070 * updateURLs : true, 1071 * watch : false, 1072 * onBeforeSend(xhr, node, url) {}, 1073 * onError(message, node, xhr, url) {}, 1074 * onWarning(message) {}, 1075 * onSuccess(cssText, node, url) {}, 1076 * onComplete(cssText, styleNode, cssVariables, benchmark) {}, 1077 * onFinally(hasChanged, hasNativeSupport, benchmark) 1078 * }); 1079 */ function cssVars() { 1080 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 1081 var msgPrefix = "cssVars(): "; 1082 var settings = _extends({}, defaults, options); 1083 function handleError(message, sourceNode, xhr, url) { 1084 if (!settings.silent && window.console) { 1085 console.error("".concat(msgPrefix).concat(message, "\n"), sourceNode); 1086 } 1087 settings.onError(message, sourceNode, xhr, url); 1088 } 1089 function handleWarning(message) { 1090 if (!settings.silent && window.console) { 1091 console.warn("".concat(msgPrefix).concat(message)); 1092 } 1093 settings.onWarning(message); 1094 } 1095 function handleFinally(hasChanged) { 1096 settings.onFinally(Boolean(hasChanged), isNativeSupport, getTimeStamp() - settings.__benchmark); 1097 } 1098 if (!isBrowser) { 1099 return; 1100 } 1101 if (settings.watch) { 1102 settings.watch = defaults.watch; 1103 addMutationObserver(settings); 1104 cssVars(settings); 1105 return; 1106 } else if (settings.watch === false && cssVarsObserver) { 1107 cssVarsObserver.disconnect(); 1108 cssVarsObserver = null; 1109 } 1110 if (!settings.__benchmark) { 1111 if (cssVarsIsRunning === settings.rootElement) { 1112 cssVarsDebounced(options); 1113 return; 1114 } 1115 settings.__benchmark = getTimeStamp(); 1116 settings.exclude = [ cssVarsObserver ? '[data-cssvars]:not([data-cssvars=""])' : '[data-cssvars="out"]', settings.exclude ].filter((function(selector) { 1117 return selector; 1118 })).join(","); 1119 settings.variables = fixVarNames(settings.variables); 1120 if (!cssVarsObserver) { 1121 var outNodes = Array.apply(null, settings.rootElement.querySelectorAll('[data-cssvars="out"]')); 1122 outNodes.forEach((function(outNode) { 1123 var dataGroup = outNode.getAttribute("data-cssvars-group"); 1124 var srcNode = dataGroup ? settings.rootElement.querySelector('[data-cssvars="src"][data-cssvars-group="'.concat(dataGroup, '"]')) : null; 1125 if (!srcNode) { 1126 outNode.parentNode.removeChild(outNode); 1127 } 1128 })); 1129 if (cssVarsSrcNodeCount) { 1130 var srcNodes = settings.rootElement.querySelectorAll('[data-cssvars]:not([data-cssvars="out"])'); 1131 if (srcNodes.length < cssVarsSrcNodeCount) { 1132 cssVarsSrcNodeCount = srcNodes.length; 1133 variableStore.dom = {}; 1134 } 1135 } 1136 } 1137 } 1138 if (document.readyState !== "loading") { 1139 if (isNativeSupport && settings.onlyLegacy) { 1140 var hasVarChange = false; 1141 if (settings.updateDOM) { 1142 var targetElm = settings.rootElement.host || (sett
vendor: 7,831 bytes, lines 1142-1260
1142ings.rootElement === document ? document.documentElement : settings.rootElement); 1143 Object.keys(settings.variables).forEach((function(key) { 1144 var varValue = settings.variables[key]; 1145 hasVarChange = hasVarChange || varValue !== getComputedStyle(targetElm).getPropertyValue(key); 1146 targetElm.style.setProperty(key, varValue); 1147 })); 1148 } 1149 handleFinally(hasVarChange); 1150 } else if (!isShadowDOMReady && (settings.shadowDOM || settings.rootElement.shadowRoot || settings.rootElement.host)) { 1151 getCssData({ 1152 rootElement: defaults.rootElement, 1153 include: defaults.include, 1154 exclude: settings.exclude, 1155 skipDisabled: false, 1156 onSuccess: function onSuccess(cssText, node, url) { 1157 cssText = cssText.replace(regex.cssComments, "").replace(regex.cssMediaQueries, ""); 1158 cssText = (cssText.match(regex.cssVarDeclRules) || []).join(""); 1159 return cssText || false; 1160 }, 1161 onComplete: function onComplete(cssText, cssArray, nodeArray) { 1162 parseVars(cssText, { 1163 store: variableStore.dom, 1164 onWarning: handleWarning 1165 }); 1166 isShadowDOMReady = true; 1167 cssVars(settings); 1168 } 1169 }); 1170 } else { 1171 cssVarsIsRunning = settings.rootElement; 1172 getCssData({ 1173 rootElement: settings.rootElement, 1174 include: settings.include, 1175 exclude: settings.exclude, 1176 skipDisabled: false, 1177 onBeforeSend: settings.onBeforeSend, 1178 onError: function onError(xhr, node, url) { 1179 var responseUrl = xhr.responseURL || getFullUrl$1(url, location.href); 1180 var statusText = xhr.statusText ? "(".concat(xhr.statusText, ")") : "Unspecified Error" + (xhr.status === 0 ? " (possibly CORS related)" : ""); 1181 var errorMsg = "CSS XHR Error: ".concat(responseUrl, " ").concat(xhr.status, " ").concat(statusText); 1182 handleError(errorMsg, node, xhr, responseUrl); 1183 }, 1184 onSuccess: function onSuccess(cssText, node, url) { 1185 var isLink = node.tagName === "LINK"; 1186 var isStyleImport = node.tagName === "STYLE" && cssText !== node.textContent; 1187 var returnVal = settings.onSuccess(cssText, node, url); 1188 cssText = returnVal !== undefined && Boolean(returnVal) === false ? "" : returnVal || cssText; 1189 if (settings.updateURLs && (isLink || isStyleImport)) { 1190 cssText = fixRelativeCssUrls(cssText, url); 1191 } 1192 return cssText; 1193 }, 1194 onComplete: function onComplete(cssText, cssArray) { 1195 var nodeArray = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; 1196 var currentVars = _extends({}, variableStore.dom, variableStore.user); 1197 var hasVarChange = false; 1198 variableStore.job = {}; 1199 nodeArray.forEach((function(node, i) { 1200 var nodeCSS = cssArray[i]; 1201 if (regex.cssVars.test(nodeCSS)) { 1202 try { 1203 var cssTree = parseCss(nodeCSS, { 1204 preserveStatic: settings.preserveStatic, 1205 removeComments: true 1206 }); 1207 parseVars(cssTree, { 1208 parseHost: Boolean(settings.rootElement.host), 1209 store: variableStore.dom, 1210 onWarning: handleWarning 1211 }); 1212 node.__cssVars = { 1213 tree: cssTree 1214 }; 1215 } catch (err) { 1216 handleError(err.message, node); 1217 } 1218 } 1219 })); 1220 _extends(variableStore.job, variableStore.dom); 1221 if (settings.updateDOM) { 1222 _extends(variableStore.user, settings.variables); 1223 _extends(variableStore.job, variableStore.user); 1224 } else { 1225 _extends(variableStore.job, variableStore.user, settings.variables); 1226 _extends(currentVars, settings.variables); 1227 } 1228 hasVarChange = counters.job > 0 && Boolean(Object.keys(variableStore.job).length > Object.keys(currentVars).length || Boolean(Object.keys(currentVars).length && Object.keys(variableStore.job).some((function(key) { 1229 return variableStore.job[key] !== currentVars[key]; 1230 })))); 1231 if (hasVarChange) { 1232 resetCssNodes(settings.rootElement); 1233 cssVars(settings); 1234 } else { 1235 var outCssArray = []; 1236 var outNodeArray = []; 1237 var hasKeyframesWithVars = false; 1238 if (settings.updateDOM) { 1239 counters.job++; 1240 } 1241 nodeArray.forEach((function(node, i) { 1242 var isSkip = !node.__cssVars; 1243 if (node.__cssVars) { 1244 try { 1245 transformCss(node.__cssVars.tree, _extends({}, settings, { 1246 variables: variableStore.job, 1247 onWarning: handleWarning 1248 })); 1249 var outCss = stringifyCss(node.__cssVars.tree); 1250 if (settings.updateDOM) { 1251 var nodeCSS = cssArray[i]; 1252 var hasCSSVarFunc = regex.cssVarFunc.test(nodeCSS); 1253 if (!node.getAttribute("data-cssvars")) { 1254 node.setAttribute("data-cssvars", "src"); 1255 } 1256 if (outCss.length && hasCSSVarFunc) { 1257 var dataGroup = node.getAttribute("data-cssvars-group") || ++counters.group; 1258 var outCssNoSpaces = outCss.replace(/\s/g, ""); 1259 var outNode = settings.rootElement.querySelector('[data-cssvars="out"][data-cssvars-group="'.concat(dataGroup, '"]')) || document.createElement("style"); 1260 hasKeyframesWithVars = hasKeyframesWithVars || regex.cssKeyframes.test(outCss);
1261 if (settings.preserveStatic) { 1262 node.sheet.disabled = true; 1263 } 1264 if (!outNode.hasAttribute("data-cssvars")) { 1265 outNode.setAttribute("data-cssvars", "out"); 1266 } 1267 if (outCssNoSpaces === node.textContent.replace(/\s/g, "")) { 1268 isSkip = true; 1269 if (outNode && outNode.parentNode) { 1270 node.removeAttribute("data-cssvars-group"); 1271 outNode.parentNode.removeChild(outNode); 1272 } 1273 } else if (outCssNoSpaces !== outNode.textContent.replace(/\s/g, "")) { 1274 [ node, outNode ].forEach((function(n) { 1275 n.setAttribute("data-cssvars-job", counters.job); 1276 n.setAttribute("data-cssvars-group", dataGroup); 1277 })); 1278 outNode.textContent = outCss; 1279 outCssArray.push(outCss); 1280 outNodeArray.push(outNode); 1281 if (!outNode.parentNode) { 1282 node.parentNode.insertBefore(outNode, node.nextSibling); 1283 } 1284 } 1285 } 1286 } else { 1287 if (node.textContent.replace(/\s/g, "") !== outCss) { 1288 outCssArray.push(outCss); 1289 } 1290 } 1291 } catch (err) { 1292 handleError(err.message, node); 1293 } 1294 } 1295 if (isSkip) { 1296 node.setAttribute("data-cssvars", "skip"); 1297 } 1298 if (!node.hasAttribute("data-cssvars-job")) { 1299 node.setAttribute("data-cssvars-job", counters.job); 1300 } 1301 })); 1302 cssVarsSrcNodeCount = settings.rootElement.querySelectorAll('[data-cssvars]:not([data-cssvars="out"])').length; 1303 if (settings.shadowDOM) { 1304 var elms = [ settings.rootElement ].concat(_toConsumableArray(settings.rootElement.querySelectorAll("*"))); 1305 for (var i = 0, elm; elm = elms[i]; ++i) { 1306 if (elm.shadowRoot && elm.shadowRoot.querySelector("style")) { 1307 var shadowSettings = _extends({}, settings, { 1308 rootElement: elm.shadowRoot 1309 }); 1310 cssVars(shadowSettings); 1311 } 1312 } 1313 } 1314 if (settings.updateDOM && hasKeyframesWithVars) { 1315 fixKeyframes(settings.rootElement); 1316 } 1317 cssVarsIsRunning = false; 1318 settings.onComplete(outCssArray.join(""), outNodeArray, JSON.parse(JSON.stringify(variableStore.job)), getTimeStamp() - settings.__benchmark); 1319 handleFinally(outNodeArray.length); 1320 } 1321 } 1322 }); 1323 } 1324 } else { 1325 document.addEventListener("DOMContentLoaded", (function init(evt) { 1326 cssVars(options); 1327 document.removeEventListener("DOMContentLoaded", init); 1328 })); 1329 } 1330 } 1331 cssVars.reset = function() { 1332 counters.job = 0; 1333 counters.group = 0; 1334 cssVarsIsRunning = false; 1335 if (cssVarsObserver) { 1336 cssVarsObserver.disconnect(); 1337 cssVarsObserver = null; 1338 } 1339 cssVarsSrcNodeCount = 0; 1340 debounceTimer = null; 1341 isShadowDOMReady = false; 1342 for (var prop in variableStore) { 1343 variableStore[prop] = {}; 1344 } 1345 }; 1346 function addMutationObserver(settings) { 1347 function isDisabled(node) { 1348 var isDisabledAttr = node.hasAttribute("disabled"); 1349 var isDisabledSheet = (node.sheet || {}).disabled; 1350 return isDisabledAttr || isDisabledSheet; 1351 } 1352 function isLink(node) { 1353 var isStylesheet = node.tagName === "LINK" && (node.getAttribute("rel") || "").indexOf("stylesheet") !== -1; 1354 return isStylesheet && !isDisabled(node); 1355 } 1356 function isStyle(node) { 1357 return node.tagName === "STYLE" && !isDisabled(node); 1358 }
1359 function isValidAddMutation(mutationNodes) { 1360 return Array.apply(null, mutationNodes).some((function(node) { 1361 var isElm = node.nodeType === 1; 1362 var hasAttr = isElm && node.hasAttribute("data-cssvars"); 1363 var isStyleWithVars = isStyle(node) && regex.cssVars.test(node.textContent); 1364 var isValid = !hasAttr && (isLink(node) || isStyleWithVars); 1365 return isValid; 1366 })); 1367 } 1368 function isValidRemoveMutation(mutationNodes) { 1369 return Array.apply(null, mutationNodes).some((function(node) { 1370 var isElm = node.nodeType === 1; 1371 var isOutNode = isElm && node.getAttribute("data-cssvars") === "out"; 1372 var isSrcNode = isElm && node.getAttribute("data-cssvars") === "src"; 1373 var isValid = isSrcNode; 1374 if (isSrcNode || isOutNode) { 1375 var dataGroup = node.getAttribute("data-cssvars-group"); 1376 var orphanNode = settings.rootElement.querySelector('[data-cssvars-group="'.concat(dataGroup, '"]')); 1377 if (isSrcNode) { 1378 resetCssNodes(settings.rootElement); 1379 variableStore.dom = {}; 1380 } 1381 if (orphanNode) { 1382 orphanNode.parentNode.removeChild(orphanNode); 1383 } 1384 } 1385 return isValid; 1386 })); 1387 } 1388 if (!window.MutationObserver) { 1389 return; 1390 } 1391 if (cssVarsObserver) { 1392 cssVarsObserver.disconnect(); 1393 cssVarsObserver = null; 1394 } 1395 cssVarsObserver = new MutationObserver((function(mutations) { 1396 var hasValidMutation = mutations.some((function(mutation) { 1397 var isValid = false; 1398 if (mutation.type === "attributes") { 1399 isValid = isLink(mutation.target); 1400 } else if (mutation.type === "childList") { 1401 isValid = isValidAddMutation(mutation.addedNodes) || isValidRemoveMutation(mutation.removedNodes); 1402 } 1403 return isValid; 1404 })); 1405 if (hasValidMutation) { 1406 cssVars(settings); 1407 } 1408 })); 1409 cssVarsObserver.observe(document.documentElement, { 1410 attributes: true, 1411 attributeFilter: [ "disabled", "href" ], 1412 childList: true, 1413 subtree: true 1414 }); 1415 } 1416 function cssVarsDebounced(settings) { 1417 var delay = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100; 1418 clearTimeout(debounceTimer); 1419 debounceTimer = setTimeout((function() { 1420 settings.__benchmark = null; 1421 cssVars(settings); 1422 }), delay); 1423 } 1424 function fixKeyframes(rootElement) { 1425 var animationNameProp = [ "animation-name", "-moz-animation-name", "-webkit-animation-name" ].filter((function(prop) { 1426 return getComputedStyle(document.body)[prop]; 1427 }))[0]; 1428 if (animationNameProp) { 1429 var allNodes = rootElement.getElementsByTagName("*"); 1430 var keyframeNodes = []; 1431 var nameMarker = "__CSSVARSPONYFILL-KEYFRAMES__"; 1432 for (var i = 0, len = allNodes.length; i < len; i++) { 1433 var node = allNodes[i]; 1434 var animationName = getComputedStyle(node)[animationNameProp]; 1435 if (animationName !== "none") { 1436 node.style[animationNameProp] += nameMarker; 1437 keyframeNodes.push(node); 1438 } 1439 } 1440 void document.body.offsetHeight; 1441 for (var _i = 0, _len = keyframeNodes.length; _i < _len; _i++) { 1442 var nodeStyle = keyframeNodes[_i].style; 1443 nodeStyle[animationNameProp] = nodeStyle[animationNameProp].replace(nameMarker, ""); 1444 } 1445 } 1446 } 1447 function fixRelativeCssUrls(cssText, baseUrl) { 1448 var cssUrls = cssText.replace(regex.cssComments, "").match(regex.cssUrls) || [];
vendor: 1,651 bytes, lines 1449-1487
1449 cssUrls.forEach((function(cssUrl) { 1450 var oldUrl = cssUrl.replace(regex.cssUrls, "$1"); 1451 var newUrl = getFullUrl$1(oldUrl, baseUrl); 1452 cssText = cssText.replace(cssUrl, cssUrl.replace(oldUrl, newUrl)); 1453 })); 1454 return cssText; 1455 } 1456 function fixVarNames() { 1457 var varObj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 1458 var reLeadingHyphens = /^-{2}/; 1459 return Object.keys(varObj).reduce((function(obj, value) { 1460 var key = reLeadingHyphens.test(value) ? value : "--".concat(value.replace(/^-+/, "")); 1461 obj[key] = varObj[value]; 1462 return obj; 1463 }), {}); 1464 } 1465 function getFullUrl$1(url) { 1466 var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : location.href; 1467 var d = document.implementation.createHTMLDocument(""); 1468 var b = d.createElement("base"); 1469 var a = d.createElement("a"); 1470 d.head.appendChild(b); 1471 d.body.appendChild(a); 1472 b.href = base; 1473 a.href = url; 1474 return a.href; 1475 } 1476 function getTimeStamp() { 1477 return isBrowser && (window.performance || {}).now ? window.performance.now() : (new Date).getTime(); 1478 } 1479 function resetCssNodes(rootElement) { 1480 var resetNodes = Array.apply(null, rootElement.querySelectorAll('[data-cssvars="skip"],[data-cssvars="src"]')); 1481 resetNodes.forEach((function(node) { 1482 return node.setAttribute("data-cssvars", ""); 1483 })); 1484 } 1485 return cssVars; 1486})); 1487//# sourceMappingURL=css-vars-ponyfill.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.