@nfront/global-styles
Version:
A package for creating independent global CSS styles, and automatically placing them at the top of the `<head>` element. Use with for instance gatsby-plugin-global-styles: https://github.com/nfront/gatsby-plugin-global-styles
3 lines (2 loc) • 3.65 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t(e.globalStyles={},e.react)}(this,function(e,t){t=t&&t.hasOwnProperty("default")?t.default:t;var n=function(e,t){for(var n=[e[0]],r=0,o=t.length;r<o;r+=1)n.push(t[r],e[r+1]);return n},r=function(e){return"object"==typeof e&&e.constructor===Object},o=Object.freeze([]);function i(e){return"function"==typeof e}Object.freeze({});var l=/([A-Z])/g,a=/^ms-/,s={animationIterationCount:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,msGridRow:1,msGridRowSpan:1,msGridColumn:1,msGridColumnSpan:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1},c=function(e){return null==e||!1===e||""===e},u=function(e,t){var n=Object.keys(e).filter(function(t){return!c(e[t])}).map(function(t){return r(e[t])?u(e[t],t):t.replace(l,"-$1").toLowerCase().replace(a,"-ms-")+": "+(null==(n=e[t])||"boolean"==typeof n||""===n?"":"number"!=typeof n||0===n||t in s?String(n).trim():n+"px")+";";var n}).join(" ");return t?t+" {\n "+n+"\n}":n};function d(e,t){if(Array.isArray(e)){for(var n=[],o=0,l=e.length,a=void 0;o<l;o+=1)null!=(a=d(e[o],t))&&(Array.isArray(a)?n.push.apply(n,a):n.push(a));return n}return c(e)?null:i(e)?"function"!=typeof(s=e)||s.prototype&&s.prototype.isReactComponent||!t?e:d(e(t),t):r(e)?u(e):e.toString();var s}function p(e){for(var t=[],l=arguments.length-1;l-- >0;)t[l]=arguments[l+1];return i(e)||r(e)?d(n(o,[e].concat(t))):d(n(e,t))}var f=/^\s*\/\/.*$/gm,y=function(e,t){this.rules=e,this.elementId=t,this.compiledStyles="",this.ReactStyleComponent=this.ReactStyleComponent.bind(this),this.injectStyleInBrowser=this.injectStyleInBrowser.bind(this)};y.prototype.createStyles=function(e){var t=d(this.rules,e).join("").replace(f,"");this.compiledStyles=t},y.prototype.ReactStyleComponent=function(e){return this.createStyles(e),t.createElement("style",{id:this.elementId,dangerouslySetInnerHTML:{__html:this.compiledStyles}})},y.prototype.injectStyleInBrowser=function(){if("undefined"!=typeof document)if(document.getElementById(this.elementId))document.getElementById(this.elementId).innerHTML=this.compiledStyles;else{var e=document.createElement("style");e.id=this.elementId,e.innerHTML=this.compiledStyles;var t=document.head,n=t.firstChild;n?t.insertBefore(e,n):t.appendChild(e)}},y.prototype.renderStyles=function(e){this.createStyles(e),this.injectStyleInBrowser()},e.createGlobalStyle=function(e){for(var n=[],r=arguments.length-1;r-- >0;)n[r]=arguments[r+1];var o=p.apply(void 0,[e].concat(n)),i="GlobalStyle"+function(e){var t,n=0;if(0===e.length)return n;for(t=0;t<e.length;t+=1)n=(n<<5)-n+e.charCodeAt(t),n|=0;return n}(JSON.stringify(o)),l=new y(o,i),a=function(e){var n=l,r=i;"production"!==process.env.NODE_ENV&&t.Children.count(e.children)&&console.warn("The global style component "+r+" was given child JSX. createGlobalStyle doesn't render children.");var o=Object.assign({},e);return o.theme=function(e,t){return e.theme?e.theme:{typography:{fontFamily:"Arial"}}}(e),n.renderStyles(o),t.createElement(t.Fragment,null,null)};return a.globalStyle=l,a.elementId=i,a},e.css=p});
//# sourceMappingURL=index.umd.js.map