UNPKG

ionicons

Version:

Premium icons for Ionic.

1 lines 5.21 kB
function t(t,s,o){return(new e).shimCssText(t,s,s+"-h",s+"-s",o)}class e{constructor(){this.strictStyling=!0}shimCssText(t,e,s="",o="",r=!1){const n=t.match(f)||[];t=t.replace(x,"");const c=[];if(r){const e=t=>{const e=`/*!@___${c.length}___*/`;return c.push({placeholder:e,comment:`/*!@${t.selector}*/`}),t.selector=e+t.selector,t};t=H(t,t=>"@"!==t.selector[0]?e(t):t.selector.startsWith("@media")||t.selector.startsWith("@supports")||t.selector.startsWith("@page")||t.selector.startsWith("@document")?(t.content=H(t.content,e),t):t)}const l=this._scopeCssText(t,e,s,o,r);return t=[l,...n].join("\n"),r&&c.forEach(({placeholder:e,comment:s})=>{t=t.replace(e,s)}),t}_scopeCssText(t,e,s,o,r){return t=this._insertPolyfillHostInCssText(t),t=this._convertColonHost(t),t=this._convertColonHostContext(t),t=this._convertColonSlotted(t,o),t=this._convertShadowDOMSelectors(t),e&&(t=this._scopeSelectors(t,e,s,o,r)),(t=(t=t.replace(/-shadowcsshost-no-combinator/g,`.${s}`)).replace(/>\s*\*\s+([^{, ]+)/gm," $1 ")).trim()}_convertColonHost(t){return this._convertColonRule(t,l,this._colonHostPartReplacer)}_convertColonSlotted(t,e){return t.replace(p,function(...t){if(t[2]){const s=t[2].trim();return"."+e+" > "+s+t[3]}return h+t[3]})}_convertColonHostContext(t){return this._convertColonRule(t,i,this._colonHostContextPartReplacer)}_convertColonRule(t,e,s){return t.replace(e,function(...t){if(t[2]){const e=t[2].split(","),o=[];for(let r=0;r<e.length;r++){const n=e[r].trim();if(!n)break;o.push(s(h,n,t[3]))}return o.join(",")}return h+t[3]})}_colonHostContextPartReplacer(t,e,s){return e.indexOf(o)>-1?this._colonHostPartReplacer(t,e,s):t+e+s+", "+e+" "+t+s}_colonHostPartReplacer(t,e,s){return t+e.replace(o,"")+s}_convertShadowDOMSelectors(t){return u.reduce((t,e)=>t.replace(e," "),t)}_scopeSelectors(t,e,s,o,r){return H(t,t=>{let n=t.selector,c=t.content;return"@"!==t.selector[0]?n=this._scopeSelector(t.selector,e,s,o,this.strictStyling):(t.selector.startsWith("@media")||t.selector.startsWith("@supports")||t.selector.startsWith("@page")||t.selector.startsWith("@document"))&&(c=this._scopeSelectors(t.content,e,s,o,r)),n=n.replace(/\s{2,}/g," ").trim(),new v(n,c)})}_scopeSelector(t,e,s,o,r){return t.split(",").map(t=>o&&t.indexOf("."+o)>-1?t.trim():this._selectorNeedsScoping(t,e)?r?this._applyStrictSelectorScope(t,e,s).trim():this._applySelectorScope(t,e,s).trim():t.trim()).join(", ")}_selectorNeedsScoping(t,e){return!this._makeScopeMatcher(e).test(t)}_makeScopeMatcher(t){return t=t.replace(/\[/g,"\\[").replace(/\]/g,"\\]"),new RegExp("^("+t+")"+_,"m")}_applySelectorScope(t,e,s){return this._applySimpleSelectorScope(t,e,s)}_applySimpleSelectorScope(t,e,s){if(g.lastIndex=0,g.test(t)){const o=this.strictStyling?`.${s}`:e;return t.replace(a,(t,e)=>e.replace(/([^:]*)(:*)(.*)/,(t,e,s,r)=>e+o+s+r)).replace(g,o+" ")}return e+" "+t}_applyStrictSelectorScope(t,e,o){const r="."+(e=e.replace(/\[is=([^\]]*)\]/g,(t,...e)=>e[0])),n=t=>{let s=t.trim();if(!s)return"";if(t.indexOf(h)>-1)s=this._applySimpleSelectorScope(t,e,o);else{const e=t.replace(g,"");if(e.length>0){const t=e.match(/([^:]*)(:*)(.*)/);t&&(s=t[1]+r+t[2]+t[3])}}return s},c=new s(t);let l,i="",p=0;const a=/( |>|\+|~(?!=))\s*/g;let u=!((t=c.content()).indexOf(h)>-1);for(;null!==(l=a.exec(t));){const e=l[1],s=t.slice(p,l.index).trim();i+=`${(u=u||s.indexOf(h)>-1)?n(s):s} ${e} `,p=a.lastIndex}const _=t.substring(p);return i+=(u=u||_.indexOf(h)>-1)?n(_):_,c.restore(i)}_insertPolyfillHostInCssText(t){return t.replace(m,n).replace(d,o).replace(S,r)}}class s{constructor(t){this.placeholders=[],this.index=0,t=t.replace(/(\[[^\]]*\])/g,(t,e)=>{const s=`__ph-${this.index}__`;return this.placeholders.push(e),this.index++,s}),this._content=t.replace(/(:nth-[-\w]+)(\([^)]+\))/g,(t,e,s)=>{const o=`__ph-${this.index}__`;return this.placeholders.push(s),this.index++,e+o})}restore(t){return t.replace(/__ph-(\d+)__/g,(t,e)=>this.placeholders[+e])}content(){return this._content}}const o="-shadowcsshost",r="-shadowcssslotted",n="-shadowcsscontext",c=")(?:\\(((?:\\([^)(]*\\)|[^)(]*)+?)\\))?([^,{]*)",l=new RegExp("("+o+c,"gim"),i=new RegExp("("+n+c,"gim"),p=new RegExp("("+r+c,"gim"),h=o+"-no-combinator",a=/-shadowcsshost-no-combinator([^\s]*)/,u=[/::shadow/g,/::content/g],_="([>\\s~+[.,{:][\\s\\S]*)?$",g=/-shadowcsshost/gim,d=/:host/gim,S=/::slotted/gim,m=/:host-context/gim,x=/\/\*\s*[\s\S]*?\*\//g,f=/\/\*\s*#\s*source(Mapping)?URL=[\s\S]+?\*\//g,C=/(\s*)([^;\{\}]+?)(\s*)((?:{%BLOCK%}?\s*;?)|(?:\s*;))/g,w=/([{}])/g,$="{",R="}",y="%BLOCK%";class v{constructor(t,e){this.selector=t,this.content=e}}function H(t,e){const s=function(t){const e=t.split(w),s=[],o=[];let r=0,n=[];for(let t=0;t<e.length;t++){const c=e[t];c===R&&r--,r>0?n.push(c):(n.length>0&&(o.push(n.join("")),s.push(y),n=[]),s.push(c)),c===$&&r++}return n.length>0&&(o.push(n.join("")),s.push(y)),new O(s.join(""),o)}(t);let o=0;return s.escapedString.replace(C,function(...t){const r=t[2];let n="",c=t[4],l="";c&&c.startsWith("{"+y)&&(n=s.blocks[o++],c=c.substring(y.length+1),l="{");const i=e(new v(r,n));return`${t[1]}${i.selector}${t[3]}${l}${i.content}${c}`})}class O{constructor(t,e){this.escapedString=t,this.blocks=e}}export{e as ShadowCss,t as scopeCss};