/*! * css-vars-ponyfill * v1.8.0 * https://github.com/jhildenbiddle/css-vars-ponyfill * (c) 2018 John Hildenbiddle * MIT license */ function getUrls(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t={mimeType:r.mimeType||null,onBeforeSend:r.onBeforeSend||Function.prototype,onSuccess:r.onSuccess||Function.prototype,onError:r.onError||Function.prototype,onComplete:r.onComplete||Function.prototype},n=Array.isArray(e)?e:[e],o=Array.apply(null,Array(n.length)).map(function(e){return null});function s(e,r){t.onError(e,n[r],r)}function a(e,r){var s=t.onSuccess(e,n[r],r);e=!1===s?"":s||e,o[r]=e,-1===o.indexOf(null)&&t.onComplete(o)}n.forEach(function(e,r){var n=document.createElement("a");n.setAttribute("href",e),n.href=n.href;var o=n.host!==location.host,i=n.protocol===location.protocol;if(o&&"undefined"!=typeof XDomainRequest)if(i){var c=new XDomainRequest;c.open("GET",e),c.timeout=0,c.onprogress=Function.prototype,c.ontimeout=Function.prototype,c.onload=function(){a(c.responseText,r)},c.onerror=function(e){s(c,r)},setTimeout(function(){c.send()},0)}else console.log("Internet Explorer 9 Cross-Origin (CORS) requests must use the same protocol"),s(null,r);else{var u=new XMLHttpRequest;u.open("GET",e),t.mimeType&&u.overrideMimeType&&u.overrideMimeType(t.mimeType),t.onBeforeSend(u,e,r),u.onreadystatechange=function(){4===u.readyState&&(200===u.status?a(u.responseText,r):s(u,r))},u.send()}})}function getCssData(e){var r={cssComments:/\/\*[\s\S]+?\*\//g,cssImports:/(?:@import\s*)(?:url\(\s*)?(?:['"])([^'"]*)(?:['"])(?:\s*\))?(?:[^;]*;)/g},t={include:e.include||'style,link[rel="stylesheet"]',exclude:e.exclude||null,filter:e.filter||null,onBeforeSend:e.onBeforeSend||Function.prototype,onSuccess:e.onSuccess||Function.prototype,onError:e.onError||Function.prototype,onComplete:e.onComplete||Function.prototype},n=Array.apply(null,document.querySelectorAll(t.include)).filter(function(e){return!matchesSelector(e,t.exclude)}),o=Array.apply(null,Array(n.length)).map(function(e){return null});function s(){if(-1===o.indexOf(null)){var e=o.join("");t.onComplete(e,o,n)}}function a(e,r,n,a){var c=t.onSuccess(e,n,a);(function e(r,n,o,s){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[];var c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:[];var u=i(r,o,c);u.rules.length?getUrls(u.absoluteUrls,{onBeforeSend:function(e,r,o){t.onBeforeSend(e,n,r)},onSuccess:function(e,r,o){var s=t.onSuccess(e,n,r),a=i(e=!1===s?"":s||e,r,c);return a.rules.forEach(function(r,t){e=e.replace(r,a.absoluteRules[t])}),e},onError:function(t,i,l){a.push({xhr:t,url:i}),c.push(u.rules[l]),e(r,n,o,s,a,c)},onComplete:function(t){t.forEach(function(e,t){r=r.replace(u.rules[t],e)}),e(r,n,o,s,a,c)}}):s(r,a)})(e=!1===c?"":c||e,n,a,function(e,a){null===o[r]&&(a.forEach(function(e){return t.onError(e.xhr,n,e.url)}),!t.filter||t.filter.test(e)?o[r]=e:o[r]="",s())})}function i(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o={};return o.rules=(e.replace(r.cssComments,"").match(r.cssImports)||[]).filter(function(e){return-1===n.indexOf(e)}),o.urls=o.rules.map(function(e){return e.replace(r.cssImports,"$1")}),o.absoluteUrls=o.urls.map(function(e){return getFullUrl(e,t)}),o.absoluteRules=o.rules.map(function(e,r){var n=o.urls[r],s=getFullUrl(o.absoluteUrls[r],t);return e.replace(n,s)}),o}n.length?n.forEach(function(e,r){var n=e.getAttribute("href"),i=e.getAttribute("rel"),c="LINK"===e.nodeName&&n&&i&&"stylesheet"===i.toLowerCase(),u="STYLE"===e.nodeName;c?getUrls(n,{mimeType:"text/css",onBeforeSend:function(r,n,o){t.onBeforeSend(r,e,n)},onSuccess:function(t,o,s){var i=getFullUrl(n,location.href);a(t,r,e,i)},onError:function(n,a,i){o[r]="",t.onError(n,e,a),s()}}):u?a(e.textContent,r,e,location.href):(o[r]="",s())}):t.onComplete("",[])}function getFullUrl(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:location.href,t=document.implementation.createHTMLDocument(""),n=t.createElement("base"),o=t.createElement("a");return t.head.appendChild(n),t.body.appendChild(o),n.href=r,o.href=e,o.href}function matchesSelector(e,r){return(e.matches||e.matchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector).call(e,r)}function mergeDeep(){for(var e=function(e){return e instanceof Object&&e.constructor===Object},r=arguments.length,t=Array(r),n=0;n=0&&u>0){for(n=[],s=t.length;l>=0&&!i;)l==c?(n.push(l),c=t.indexOf(e,l+1)):1==n.length?i=[n.pop(),u]:((o=n.pop())=0?c:u;n.length&&(i=[s,a])}return i}function cssParse(e){function r(e){throw new Error("CSS parse error: "+e)}function t(r){var t=r.exec(e);if(t)return e=e.slice(t[0].length),t}function n(){t(/^\s*/)}function o(){return t(/^{\s*/)}function s(){return t(/^}/)}function a(){if(n(),"/"===e[0]&&"*"===e[1]){for(var t=2;e[t]&&("*"!==e[t]||"/"!==e[t+1]);)t++;if(!e[t])return r("end of comment is missing");var o=e.slice(2,t);return e=e.slice(t+2),{type:"comment",comment:o}}}function i(){for(var e=[],r=void 0;r=a();)e.push(r);return e}function c(){for(n();"}"===e[0];)r("extra closing bracket");var o=t(/^(("(?:\\"|[^"])*"|'(?:\\'|[^'])*'|[^{])+)/);if(o)return o[0].trim().replace(/\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*\/+/g,"").replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g,function(e){return e.replace(/,/g,"‌")}).split(/\s*(?![^(]*\)),\s*/).map(function(e){return e.replace(/\u200C/g,",")})}function u(){t(/^([;\s]*)+/);var e=/\/\*[^*]*\*+([^\/*][^*]*\*+)*\//g,n=t(/^(\*?[-#\/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);if(n){if(n=n[0].trim(),!t(/^:\s*/))return r("property missing ':'");var o=t(/^((?:\/\*.*?\*\/|'(?:\\'|.)*?'|"(?:\\"|.)*?"|\((\s*'(?:\\'|.)*?'|"(?:\\"|.)*?"|[^)]*?)\s*\)|[^};])+)/),s={type:"declaration",property:n.replace(e,""),value:o?o[0].replace(e,"").trim():""};return t(/^[;\s]*/),s}}function l(){if(!o())return r("missing '{'");for(var e=void 0,t=i();e=u();)t.push(e),t=t.concat(i());return s()?t:r("missing '}'")}function f(){n();for(var e=[],r=void 0;r=t(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/);)e.push(r[1]),t(/^,\s*/);if(e.length)return{type:"keyframe",values:e,declarations:l()}}function p(){if(n(),"@"===e[0])return function(){var e=t(/^@([-\w]+)?keyframes\s*/);if(e){var n=e[1];if(!(e=t(/^([-\w]+)\s*/)))return r("@keyframes missing name");var a=e[1];if(!o())return r("@keyframes missing '{'");for(var c=void 0,u=i();c=f();)u.push(c),u=u.concat(i());return s()?{type:"keyframes",name:a,vendor:n,keyframes:u}:r("@keyframes missing '}'")}}()||function(){var e=t(/^@supports *([^{]+)/);if(e)return{type:"supports",supports:e[1].trim(),rules:d()}}()||function(){if(t(/^@host\s*/))return{type:"host",rules:d()}}()||function(){var e=t(/^@media *([^{]+)/);if(e)return{type:"media",media:e[1].trim(),rules:d()}}()||function(){var e=t(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);if(e)return{type:"custom-media",name:e[1].trim(),media:e[2].trim()}}()||function(){if(t(/^@page */))return{type:"page",selectors:c()||[],declarations:l()}}()||function(){var e=t(/^@([-\w]+)?document *([^{]+)/);if(e)return{type:"document",document:e[2].trim(),vendor:e[1]?e[1].trim():null,rules:d()}}()||function(){if(t(/^@font-face\s*/))return{type:"font-face",declarations:l()}}()||function(){var e=t(/^@(import|charset|namespace)\s*([^;]+);/);if(e)return{type:e[1],name:e[2].trim()}}()}function d(t){if(!t&&!o())return r("missing '{'");for(var n,a=void 0,u=i();e.length&&(t||"}"!==e[0])&&(a=p()||(void 0,(n=c()||[]).length||r("selector missing"),{type:"rule",selectors:n,declarations:l()}));)u.push(a),u=u.concat(i());return t||s()?u:r("missing '}'")}return{type:"stylesheet",stylesheet:{rules:d(!0),errors:[]}}}function stringifyCss(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=arguments[2],n={charset:function(e){return"@charset "+e.name+";"},comment:function(e){return 0===e.comment.indexOf("__CSSVARSPONYFILL")?"/*"+e.comment+"*/":""},"custom-media":function(e){return"@custom-media "+e.name+" "+e.media+";"},declaration:function(e){return e.property+":"+e.value+";"},document:function(e){return"@"+(e.vendor||"")+"document "+e.document+"{"+o(e.rules)+"}"},"font-face":function(e){return"@font-face{"+o(e.declarations)+"}"},host:function(e){return"@host{"+o(e.rules)+"}"},import:function(e){return"@import "+e.name+";"},keyframe:function(e){return e.values.join(",")+"{"+o(e.declarations)+"}"},keyframes:function(e){return"@"+(e.vendor||"")+"keyframes "+e.name+"{"+o(e.keyframes)+"}"},media:function(e){return"@media "+e.media+"{"+o(e.rules)+"}"},namespace:function(e){return"@namespace "+e.name+";"},page:function(e){return"@page "+(e.selectors.length?e.selectors.join(", "):"")+"{"+o(e.declarations)+"}"},rule:function(e){var r=e.declarations;if(r.length)return e.selectors.join(",")+"{"+o(r)+"}"},supports:function(e){return"@supports "+e.supports+"{"+o(e.rules)+"}"}};function o(e){for(var o="",s=0;s1&&void 0!==arguments[1]?arguments[1]:{},t={},n=mergeDeep({fixNestedCalc:!0,onlyVars:!0,persist:!1,preserve:!1,variables:{},onWarning:function(){}},r),o=n.persist?persistStore:n.variables,s=cssParse(e);if(n.onlyVars&&(s.stylesheet.rules=filterVars(s.stylesheet.rules)),s.stylesheet.rules.forEach(function(e){var r=[];if("rule"===e.type&&1===e.selectors.length&&":root"===e.selectors[0]&&(e.declarations.forEach(function(e,n){var o=e.property,s=e.value;o&&0===o.indexOf(VAR_PROP_IDENTIFIER)&&(t[o]=s,r.push(n))}),!n.preserve))for(var o=r.length-1;o>=0;o--)e.declarations.splice(r[o],1)}),Object.keys(n.variables).forEach(function(e){var r="--"+e.replace(/^-+/,""),t=n.variables[e];e!==r&&(n.variables[r]=t,delete n.variables[e]),n.persist&&(persistStore[r]=t)}),Object.keys(o).length){var a={declarations:[],selectors:[":root"],type:"rule"};Object.keys(o).forEach(function(e){t[e]=o[e],a.declarations.push({type:"declaration",property:e,value:o[e]}),n.persist&&(persistStore[e]=o[e])}),n.preserve&&s.stylesheet.rules.push(a)}return walkCss(s.stylesheet,function(e,r){for(var o=void 0,s=void 0,a=void 0,i=0;i-1;return r||t});return"font-face"!==e.type&&(e.declarations=r),Boolean(r.length)}return e.keyframes?Boolean(e.keyframes.filter(function(e){return Boolean(e.declarations.filter(function(e){var r=e.property&&0===e.property.indexOf(VAR_PROP_IDENTIFIER),t=e.value&&e.value.indexOf(VAR_FUNC_IDENTIFIER+"(")>-1;return r||t}).length)}).length):!e.rules||(e.rules=filterVars(e.rules).filter(function(e){return e.declarations&&e.declarations.length}),Boolean(e.rules.length))})}function fixNestedCalc(e){var r=/(-[a-z]+-)?calc\(/;e.forEach(function(e){e.declarations&&e.declarations.forEach(function(e){for(var t=e.value,n="";r.test(t);){var o=balancedMatch("calc(",")",t||"");for(t=t.slice(o.end);r.test(o.body);){var s=balancedMatch(r,")",o.body);o.body=s.pre+"("+s.body+")"+s.post}n+=o.pre+"calc("+o.body,n+=r.test(t)?"":")"+o.post}e.value=n||e.value})})}function resolveValue(e,r,t){var n=balancedMatch("(",")",e),o=e.indexOf("var("),s=balancedMatch("(",")",e.substring(o)).body;n||t.onWarning('CSS transform warning: missing closing ")" in the value "'+e+'"'),""===s&&t.onWarning("CSS transform warning: var() must contain a non-whitespace string");var a=VAR_FUNC_IDENTIFIER+"("+s+")",i=s.replace(/([\w-]+)(?:\s*,\s*)?(.*)?/,function(e,n,o){var s=r[n],a=void 0!==s&&""!==s,i=void 0!==o&&""!==o;return a||i||t.onWarning('CSS transform warning: variable "'+n+'" is undefined'),!a&&i?o:s});return-1!==(e=e.split(a).join(i)).indexOf(VAR_FUNC_IDENTIFIER+"(")&&(e=resolveValue(e,r,t)),e}var name="css-vars-ponyfill",defaults={include:"style,link[rel=stylesheet]",exclude:"",fixNestedCalc:!0,onlyLegacy:!0,onlyVars:!1,preserve:!1,silent:!1,updateDOM:!0,updateURLs:!0,variables:{},watch:!1,onBeforeSend:function(){},onSuccess:function(){},onWarning:function(){},onError:function(){},onComplete:function(){}},hasNativeSupport=window&&window.CSS&&window.CSS.supports&&window.CSS.supports("(--a: 0)"),regex={cssComments:/\/\*[\s\S]+?\*\//g,cssKeyframes:/@(?:-\w*-)?keyframes/,cssUrls:/url\((?!['"]?(?:data|http|\/\/):)['"]?([^'")]*)['"]?\)/g,cssVars:/(?:(?::root\s*{\s*[^;]*;*\s*)|(?:var\(\s*))(--[^:)]+)(?:\s*[:)])/},cssVarsObserver=null;function cssVars(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=mergeDeep(defaults,e);function t(e,t,n,o){r.silent||console.error(e+"\n",t),r.onError(e,t,n,o)}function n(e){r.silent||console.warn(e),r.onWarning(e)}if("loading"!==document.readyState)if(hasNativeSupport&&r.onlyLegacy)hasNativeSupport&&r.updateDOM&&Object.keys(r.variables).forEach(function(e){var t="--"+e.replace(/^-+/,""),n=r.variables[e];document.documentElement.style.setProperty(t,n)});else{var o=name;r.watch&&addMutationObserver(r,o),getCssData({include:r.include,exclude:"#"+o+(r.exclude?","+r.exclude:""),filter:r.onlyVars?regex.cssVars:null,onBeforeSend:r.onBeforeSend,onSuccess:function(e,t,n){var o=r.onSuccess(e,t,n);(e=!1===o?"":o||e,r.updateURLs)&&(e.replace(regex.cssComments,"").match(regex.cssUrls)||[]).forEach(function(r){var t=r.replace(regex.cssUrls,"$1"),o=getFullUrl$1(t,n);e=e.replace(r,r.replace(t,o))});return e},onError:function(e,r,n){var o=e.responseURL||getFullUrl$1(n,location.href),s=e.statusText?"("+e.statusText+")":"Unspecified Error"+(0===e.status?" (possibly CORS related)":"");t("CSS XHR Error: "+o+" "+e.status+" "+s,r,e,o)},onComplete:function(e,s,a){var i=/\/\*__CSSVARSPONYFILL-(\d+)__\*\//g,c=null;e=s.map(function(e,r){return regex.cssVars.test(e)?e:"/*__CSSVARSPONYFILL-"+r+"__*/"}).join("");try{e=transformVars(e,{fixNestedCalc:r.fixNestedCalc,onlyVars:r.onlyVars,persist:r.updateDOM,preserve:r.preserve,variables:r.variables,onWarning:n});for(var u=regex.cssKeyframes.test(e),l=i.exec(e);null!==l;){var f=l[0],p=l[1];e=e.replace(f,s[p]),l=i.exec(e)}if(r.updateDOM&&a&&a.length){var d=a[a.length-1];(c=document.querySelector("#"+o)||document.createElement("style")).setAttribute("id",o),c.textContent!==e&&(c.textContent=e),d.nextSibling!==c&&d.parentNode.insertBefore(c,d.nextSibling),u&&fixKeyframes()}}catch(e){var m=!1;s.forEach(function(e,n){try{e=transformVars(e,r)}catch(e){var o=a[n-0];m=!0,t(e.message,o)}}),m||t(e.message||e)}r.onComplete(e,c)}})}else document.addEventListener("DOMContentLoaded",function r(t){cssVars(e),document.removeEventListener("DOMContentLoaded",r)})}function addMutationObserver(e,r){if(window.MutationObserver&&!cssVarsObserver){var t=function(e){return"LINK"===e.tagName&&-1!==(e.getAttribute("rel")||"").indexOf("stylesheet")},n=function(e){return"STYLE"===e.tagName&&(!r||e.id!==r)},o=null;(cssVarsObserver=new MutationObserver(function(r){var s=!1;r.forEach(function(r){if("attributes"===r.type)s=t(r.target)||n(r.target);else if("childList"===r.type){var a=Array.apply(null,r.addedNodes),i=Array.apply(null,r.removedNodes);s=[].concat(a,i).some(function(e){var r=t(e)&&!e.disabled,o=n(e)&&!e.disabled&®ex.cssVars.test(e.textContent);return r||o})}s&&(clearTimeout(o),o=setTimeout(function(){cssVars(e)},1))})})).observe(document.documentElement,{attributes:!0,attributeFilter:["disabled","href"],childList:!0,subtree:!0})}}function fixKeyframes(){for(var e=document.body.getElementsByTagName("*"),r=[],t=0,n=e.length;t1&&void 0!==arguments[1]?arguments[1]:location.href,t=document.implementation.createHTMLDocument(""),n=t.createElement("base"),o=t.createElement("a");return t.head.appendChild(n),t.body.appendChild(o),n.href=r,o.href=e,o.href}export default cssVars; //# sourceMappingURL=css-vars-ponyfill.esm.min.js.map