UNPKG

7.65 kBJavaScriptView Raw
1var t=function(){this.start=0,this.end=0,this.previous=null,this.parent=null,this.rules=null,this.parsedCssText="",this.cssText="",this.atRule=!1,this.type=0,this.keyframesName="",this.selector="",this.parsedSelector=""};var e={STYLE_RULE:1,KEYFRAMES_RULE:7,MEDIA_RULE:4,MIXIN_RULE:1e3},r="{",n="}",s={comments:/\/\*[^*]*\*+([^\/*][^*]*\*+)*\//gim,port:/@import[^;]*;/gim,customProp:/(?:^[^;\-\s}]+)?--[^;{}]*?:[^{};]*?(?:[;\n]|$)/gim,mixinProp:/(?:^[^;\-\s}]+)?--[^;{}]*?:[^{};]*?{[^}]*?}(?:[;\n]|$)?/gim,mixinApply:/@apply\s*\(?[^);]*\)?\s*(?:[;\n]|$)?/gim,varApply:/[^;:]*?:[^;]*?var\([^;]*\)(?:[;\n]|$)?/gim,keyframesRule:/^@[^\s]*keyframes/,multipleSpaces:/\s+/g},i="--",o="@media",a="@";function c(t,e,r){t.lastIndex=0;var n=e.substring(r).match(t);if(n){var s=r+n.index;return{start:s,end:s+n[0].length}}return null}var l=/\bvar\(/,u=/\B--[\w-]+\s*:/,p=/\/\*[^*]*\*+([^\/*][^*]*\*+)*\//gim,f=/^[\t ]+\n/gm;function h(t,e,r){var n=function(t,e){var r=c(l,t,e);if(!r)return null;var n=function(t){for(var e=0,n=r.start;n<t.length;n++){var s=t[n];if("("===s)e++;else if(")"===s&&--e<=0)return n+1}return n}(t),s=t.substring(r.end,n-1).split(","),i=s[0],o=s.slice(1);return{start:r.start,end:n,propName:i.trim(),fallback:o.length>0?o.join(",").trim():void 0}}(t,r);if(!n)return e.push(t.substring(r,t.length)),t.length;var s=n.propName,i=null!=n.fallback?g(n.fallback):void 0;return e.push(t.substring(r,n.start),function(t){return function(e,r,n){return t[s]?t[s]:n?v(n,t):""}(0,0,i)}),n.end}function v(t,e){for(var r="",n=0;n<t.length;n++){var s=t[n];r+="string"==typeof s?s:s(e)}return r}function m(t,e){for(var r=!1,n=!1,s=e;s<t.length;s++){var i=t[s];if(r)n&&'"'===i&&(r=!1),n||"'"!==i||(r=!1);else if('"'===i)r=!0,n=!0;else if("'"===i)r=!0,n=!1;else{if(";"===i)return s+1;if("}"===i)return s}}return s}function g(t){var e=0;t=function(t){for(var e="",r=0;;){var n=c(u,t,r),s=n?n.start:t.length;if(e+=t.substring(r,s),!n)break;r=m(t,s)}return e}(t=t.replace(p,"")).replace(f,"");for(var r=[];e<t.length;)e=h(t,r,e);return r}function d(t){var e={};t.forEach(function(t){t.declarations.forEach(function(t){e[t.prop]=t.value})});for(var r={},n=Object.entries(e),s=function(){var t=!1;if(n.forEach(function(e){var n=e[0],s=v(e[1],r);s!==r[n]&&(r[n]=s,t=!0)}),!t)return"break"},i=0;i<10&&"break"!==s();i++);return r}function y(t,r){if(void 0===r&&(r=0),!t.rules)return[];var n=[];return t.rules.filter(function(t){return t.type===e.STYLE_RULE}).forEach(function(t){var e=function(t){for(var e,r=[];e=E.exec(t.trim());){var n=b(e[2]),s=n.value,i=n.important;r.push({prop:e[1].trim(),value:g(s),important:i})}return r}(t.cssText);e.length>0&&t.parsedSelector.split(",").forEach(function(t){t=t.trim(),n.push({selector:t,declarations:e,specificity:1,nu:r})}),r++}),n}var S="!important",E=/(?:^|[;\s{]\s*)(--[\w-]*?)\s*:\s*(?:((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};{])+)|\{([^}]*)\}(?:(?=[;\s}])|$))/gm;function b(t){var e=(t=t.replace(/\s+/gim," ").trim()).endsWith(S);return e&&(t=t.substr(0,t.length-S.length).trim()),{value:t,important:e}}function M(t){var e=[];return t.forEach(function(t){e.push.apply(e,t.selectors)}),e}function L(c){var l,u=function t(r,n){var c=n.substring(r.start,r.end-1);if(r.parsedCssText=r.cssText=c.trim(),r.parent){c=(c=(c=(c=n.substring(r.previous?r.previous.end:r.parent.start,r.start-1)).replace(/\\([0-9a-f]{1,6})\s/gi,function(){for(var t=arguments[1],e=6-t.length;e--;)t="0"+t;return"\\"+t})).replace(s.multipleSpaces," ")).substring(c.lastIndexOf(";")+1);var l=r.parsedSelector=r.selector=c.trim();r.atRule=0===l.indexOf(a),r.atRule?0===l.indexOf(o)?r.type=e.MEDIA_RULE:l.match(s.keyframesRule)&&(r.type=e.KEYFRAMES_RULE,r.keyframesName=r.selector.split(s.multipleSpaces).pop()):r.type=0===l.indexOf(i)?e.MIXIN_RULE:e.STYLE_RULE}var u=r.rules;if(u)for(var p=0,f=u.length,h=void 0;p<f&&(h=u[p]);p++)t(h,n);return r}(function(e){var s=new t;s.start=0,s.end=e.length;for(var i=s,o=0,a=e.length;o<a;o++)if(e[o]===r){i.rules||(i.rules=[]);var c=i,l=c.rules[c.rules.length-1]||null;(i=new t).start=o+1,i.parent=c,i.previous=l,c.rules.push(i)}else e[o]===n&&(i.end=o+1,i=i.parent||s);return s}(l=(l=c).replace(s.comments,"").replace(s.port,"")),l),p=g(c);return{original:c,template:p,selectors:y(u),isDynamic:p.length>1}}function x(t,e){var r=L(e.innerHTML);r.styleEl=e,t.push(r)}function R(t,e,r){var n;return n="."+r,t.replace(new RegExp("\\."+e,"g"),n)}function T(t,e,r){var n=r.href;return fetch(n).then(function(t){return t.text()}).then(function(s){if(((o=s).indexOf("var(")>-1||w.test(o))&&r.parentNode){(function(t){return I.lastIndex=0,I.test(t)})(s)&&(s=function(t){var e=n.replace(/[^\/]*$/,"");return t.replace(I,function(t,r){return t.replace(r,e+r)})}(s));var i=t.createElement("style");i.innerHTML=s,x(e,i),r.parentNode.insertBefore(i,r),r.remove()}var o}).catch(function(t){console.error(t)})}var w=/[\s;{]--[-a-zA-Z0-9]+\s*:/m,I=/url[\s]*\([\s]*['"]?(?![http|\/])([^\'\"\)]*)[\s]*['"]?\)[\s]*/gim,k=function(){function t(t,e){this.win=t,this.doc=e,this.count=0,this.hostStyleMap=new WeakMap,this.hostScopeMap=new WeakMap,this.globalScopes=[],this.scopesMap=new Map}return t.prototype.initShim=function(){var t=this;return new Promise(function(e){t.win.requestAnimationFrame(function(){var r,n;(r=t.doc,n=t.globalScopes,function(t,e){for(var r=[],n=t.querySelectorAll('link[rel="stylesheet"][href]'),s=0;s<n.length;s++)r.push(T(t,e,n[s]));return Promise.all(r)}(r,n).then(function(){!function(t,e){for(var r=t.querySelectorAll("style"),n=0;n<r.length;n++)x(e,r[n])}(r,n)})).then(function(){return e()})})})},t.prototype.addLink=function(t){var e=this;return T(this.doc,this.globalScopes,t).then(function(){e.updateGlobal()})},t.prototype.addGlobalStyle=function(t){x(this.globalScopes,t),this.updateGlobal()},t.prototype.createHostStyle=function(t,e,r){if(this.hostScopeMap.has(t))throw new Error("host style already created");var n=this.registerHostTemplate(r,e),s=!(!n.isDynamic||!n.cssScopeId),i=s||!n.styleEl,o=this.doc.createElement("style");return i?s?(o["s-sc"]=e=n.cssScopeId+"-"+this.count,o.innerHTML="/*needs update*/",this.hostStyleMap.set(t,o),this.hostScopeMap.set(t,function(t,e){var r=t.template.map(function(r){return"string"==typeof r?R(r,t.cssScopeId,e):r}),n=t.selectors.map(function(r){return Object.assign({},r,{selector:R(r.selector,t.cssScopeId,e)})});return Object.assign({},t,{template:r,selectors:n,cssScopeId:e})}(n,e)),this.count++):(n.styleEl=o,n.isDynamic||(o.innerHTML=v(n.template,{})),this.globalScopes.push(n),this.updateGlobal(),this.hostScopeMap.set(t,n)):o.innerHTML=r,o},t.prototype.removeHost=function(t){var e=this.hostStyleMap.get(t);e&&e.remove(),this.hostStyleMap.delete(t),this.hostScopeMap.delete(t)},t.prototype.updateHost=function(t){var e=this.hostScopeMap.get(t);if(e&&e.isDynamic&&e.cssScopeId){var r=this.hostStyleMap.get(t);if(r){var n=d(function(t,e,r){var n;return(n=M(r.concat(function(t,e){for(var r=[];e;){var n=t.get(e);n&&r.push(n),e=e.parentElement}return r}(e,t))).filter(function(e){return function(e,r){return t.matches(r)}(0,e.selector)})).sort(function(t,e){return t.specificity===e.specificity?t.nu-e.nu:t.specificity-e.specificity}),n}(t,this.hostScopeMap,this.globalScopes));r.innerHTML=v(e.template,n)}}},t.prototype.updateGlobal=function(){var t,e;e=d(M(t=this.globalScopes)),t.forEach(function(t){t.isDynamic&&(t.styleEl.innerHTML=v(t.template,e))})},t.prototype.registerHostTemplate=function(t,e){var r=this.scopesMap.get(e);return r||((r=L(t)).cssScopeId=e,this.scopesMap.set(e,r)),r},t}(),_=window;_.__stencil_cssshim||_.CSS&&_.CSS.supports&&_.CSS.supports("color","var(--c)")||(_.__stencil_cssshim=new k(_,document));
\No newline at end of file