UNPKG

typography

Version:

Opinionated toolkit for building websites with beautiful typography

3 lines (2 loc) 6.52 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("object-assign"),require("compass-vertical-rhythm"),require("modularscale"),require("gray-percentage"),require("lodash/set"),require("lodash/forEach"),require("lodash/isNumber"),require("lodash/isString"),require("lodash/isFunction"),require("lodash/isArray"),require("lodash/merge"),require("lodash/reduce"),require("typography-normalize"),require("decamelize"),require("lodash/isObject")):"function"==typeof define&&define.amd?define(["object-assign","compass-vertical-rhythm","modularscale","gray-percentage","lodash/set","lodash/forEach","lodash/isNumber","lodash/isString","lodash/isFunction","lodash/isArray","lodash/merge","lodash/reduce","typography-normalize","decamelize","lodash/isObject"],t):(e||self).typography=t(e.objectAssign,e.compassVerticalRhythm,e.modularscale,e.grayPercentage,e.set,e.each,e.isNumber,e.isString,e.isFunction,e.isArray,e.merge,e.reduce,e.typographyNormalize,e.decamelize,e.isObject)}(this,function(e,t,i,o,r,a,n,l,d,s,u,h,c,g,f){function m(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=m(e),y=m(t),b=m(i),S=m(o),F=m(r),v=m(a),z=m(n),B=m(l),j=m(d),x=m(s),k=m(u),q=m(h),W=m(c),L=m(g),T=m(f);function O(){return O=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(e[o]=i[o])}return e},O.apply(this,arguments)}var M=function(e,t,i){var o;return void 0===e&&(e={}),o=x.default(t)?t:[t],v.default(o,function(t){v.default(i,function(i,o){F.default(e,t+"."+o,i)})}),e},R=["inherit","default","serif","sans-serif","monospace","fantasy","cursive","-apple-system"],C=function(e){return-1!==R.indexOf(e)||e.startsWith("var(")?e:"'"+e+"'"},N=function e(t){return q.default(t,function(t,i,o){return t+=o+"{",v.default(i,function(i,o){if(T.default(i)){var r={};r[o]=i,t+=e(r)}else{var a=L.default(o,"-")+":"+i+";";["Webkit","ms","Moz","O"].forEach(function(e){o.slice(0,e.length)===e&&(a="-"+a)}),t+=a}}),t+="}"},"")},H=function(e,t,i){var o=N(i);return t.includeNormalize&&(o=""+W.default+o),o};return function(e){var t=p.default({},{baseFontSize:"16px",baseLineHeight:1.45,headerLineHeight:1.1,scaleRatio:2,googleFonts:[],headerFontFamily:["-apple-system","BlinkMacSystemFont","Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue","sans-serif"],bodyFontFamily:["georgia","serif"],headerColor:"inherit",bodyColor:"hsla(0,0%,0%,0.8)",headerWeight:"bold",bodyWeight:"normal",boldWeight:"bold",includeNormalize:!0,blockMarginBottom:1},e),i=y.default(t);return i.scale=function(e){var o=parseInt(t.baseFontSize,10),r=b.default(e,t.scaleRatio)*o+"px";return i.adjustFontSizeTo(r)},O({options:t},i,{createStyles:function(){return this.toString()},toJSON:function(){return function(e,t){var i,o={},r=e.establishBaseline();o=M(o,"html",{font:r.fontSize+"/"+r.lineHeight+" "+t.bodyFontFamily.map(C).join(","),boxSizing:"border-box",overflowY:"scroll"}),o=M(o,["*","*:before","*:after"],{boxSizing:"inherit"}),o=M(o,"body",{color:t.bodyColor,fontFamily:t.bodyFontFamily.map(C).join(","),fontWeight:t.bodyWeight,wordWrap:"break-word",fontKerning:"normal",MozFontFeatureSettings:'"kern", "liga", "clig", "calt"',msFontFeatureSettings:'"kern", "liga", "clig", "calt"',WebkitFontFeatureSettings:'"kern", "liga", "clig", "calt"',fontFeatureSettings:'"kern", "liga", "clig", "calt"'}),o=M(o,"img",{maxWidth:"100%"}),i=z.default(t.blockMarginBottom)?e.rhythm(t.blockMarginBottom):B.default(t.blockMarginBottom)?t.blockMarginBottom:e.rhythm(1),o=M(o,["h1","h2","h3","h4","h5","h6","hgroup","ul","ol","dl","dd","p","figure","pre","table","fieldset","blockquote","form","noscript","iframe","img","hr","address"],{marginLeft:0,marginRight:0,marginTop:0,paddingBottom:0,paddingLeft:0,paddingRight:0,paddingTop:0,marginBottom:i}),o=M(o,"blockquote",{marginRight:e.rhythm(1),marginBottom:i,marginLeft:e.rhythm(1)}),o=M(o,["b","strong","dt","th"],{fontWeight:t.boldWeight}),o=M(o,"hr",{background:S.default(80),border:"none",height:"1px",marginBottom:"calc("+i+" - 1px)"}),o=M(o,["ol","ul"],{listStylePosition:"outside",listStyleImage:"none",marginLeft:e.rhythm(1)}),o=M(o,"li",{marginBottom:"calc("+i+" / 2)"}),o=M(o,["ol li","ul li"],{paddingLeft:0}),o=M(o,["li > ol","li > ul"],{marginLeft:e.rhythm(1),marginBottom:"calc("+i+" / 2)",marginTop:"calc("+i+" / 2)"}),o=M(o,["blockquote *:last-child","li *:last-child","p *:last-child"],{marginBottom:0}),o=M(o,["li > p"],{marginBottom:"calc("+i+" / 2)"}),o=M(o,["code","kbd","pre","samp"],O({},e.adjustFontSizeTo("85%"))),(o=M(o,["abbr","acronym"],{borderBottom:"1px dotted "+S.default(50),cursor:"help"}))["abbr[title]"]={borderBottom:"1px dotted "+S.default(50),cursor:"help",textDecoration:"none"},o=M(o,["table"],O({},e.adjustFontSizeTo(t.baseFontSize),{borderCollapse:"collapse",width:"100%"})),o=M(o,["thead"],{textAlign:"left"}),o=M(o,["td,th"],{textAlign:"left",borderBottom:"1px solid "+S.default(88),fontFeatureSettings:'"tnum"',MozFontFeatureSettings:'"tnum"',msFontFeatureSettings:'"tnum"',WebkitFontFeatureSettings:'"tnum"',paddingLeft:e.rhythm(2/3),paddingRight:e.rhythm(2/3),paddingTop:e.rhythm(.5),paddingBottom:"calc("+e.rhythm(.5)+" - 1px)"}),o=M(o,"th:first-child,td:first-child",{paddingLeft:0}),o=M(o,"th:last-child,td:last-child",{paddingRight:0}),o=M(o,["h1","h2","h3","h4","h5","h6"],{color:t.headerColor,fontFamily:t.headerFontFamily.map(C).join(","),fontWeight:t.headerWeight,textRendering:"optimizeLegibility"});var a=e.scale(1),n=e.scale(.6),l=e.scale(.4),d=e.scale(0),s=e.scale(-.2),u=e.scale(-.3);return v.default([a,n,l,d,s,u],function(e,i){o=F.default(o,"h"+(i+1)+".fontSize",e.fontSize),o=F.default(o,"h"+(i+1)+".lineHeight",t.headerLineHeight)}),x.default(t.plugins)&&(o=q.default(t.plugins,function(i,o){return k.default(i,o(e,t,i))},o)),t.overrideStyles&&j.default(t.overrideStyles)&&(o=k.default(o,t.overrideStyles(e,t,o))),t.overrideThemeStyles&&j.default(t.overrideThemeStyles)&&(o=k.default(o,t.overrideThemeStyles(e,t,o))),o}(i,t)},toString:function(){return H(0,t,this.toJSON())},injectStyles:function(){if("undefined"!=typeof document)if(document.getElementById("typography.js"))document.getElementById("typography.js").innerHTML=this.toString();else{var e=document.createElement("style");e.id="typography.js",e.innerHTML=this.toString();var t=document.head;t.firstChild?t.insertBefore(e,t.firstChild):t.appendChild(e)}}})}}); //# sourceMappingURL=index.umd.js.map