UNPKG

typography

Version:

Opinionated toolkit for building websites with beautiful typography

3 lines (2 loc) 5.53 kB
import t from"object-assign";import e from"compass-vertical-rhythm";import o from"modularscale";import i from"gray-percentage";import r from"lodash/set";import n from"lodash/forEach";import a from"lodash/isNumber";import l from"lodash/isString";import s from"lodash/isFunction";import m from"lodash/isArray";import d from"lodash/merge";import h from"lodash/reduce";import g from"typography-normalize";import c from"decamelize";import f from"lodash/isObject";function p(){return p=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(t[i]=o[i])}return t},p.apply(this,arguments)}var u=function(t,e,o){var i;return void 0===t&&(t={}),i=m(e)?e:[e],n(i,function(e){n(o,function(o,i){r(t,e+"."+i,o)})}),t},y=["inherit","default","serif","sans-serif","monospace","fantasy","cursive","-apple-system"],b=function(t){return-1!==y.indexOf(t)||t.startsWith("var(")?t:"'"+t+"'"},S=function t(e){return h(e,function(e,o,i){return e+=i+"{",n(o,function(o,i){if(f(o)){var r={};r[i]=o,e+=t(r)}else{var n=c(i,"-")+":"+o+";";["Webkit","ms","Moz","O"].forEach(function(t){i.slice(0,t.length)===t&&(n="-"+n)}),e+=n}}),e+="}"},"")},F=function(t,e,o){var i=S(o);return e.includeNormalize&&(i=""+g+i),i},v=function(g){var c=t({},{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},g),f=e(c);return f.scale=function(t){var e=parseInt(c.baseFontSize,10),i=o(t,c.scaleRatio)*e+"px";return f.adjustFontSizeTo(i)},p({options:c},f,{createStyles:function(){return this.toString()},toJSON:function(){return function(t,e){var o,g={},c=t.establishBaseline();g=u(g,"html",{font:c.fontSize+"/"+c.lineHeight+" "+e.bodyFontFamily.map(b).join(","),boxSizing:"border-box",overflowY:"scroll"}),g=u(g,["*","*:before","*:after"],{boxSizing:"inherit"}),g=u(g,"body",{color:e.bodyColor,fontFamily:e.bodyFontFamily.map(b).join(","),fontWeight:e.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"'}),g=u(g,"img",{maxWidth:"100%"}),o=a(e.blockMarginBottom)?t.rhythm(e.blockMarginBottom):l(e.blockMarginBottom)?e.blockMarginBottom:t.rhythm(1),g=u(g,["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:o}),g=u(g,"blockquote",{marginRight:t.rhythm(1),marginBottom:o,marginLeft:t.rhythm(1)}),g=u(g,["b","strong","dt","th"],{fontWeight:e.boldWeight}),g=u(g,"hr",{background:i(80),border:"none",height:"1px",marginBottom:"calc("+o+" - 1px)"}),g=u(g,["ol","ul"],{listStylePosition:"outside",listStyleImage:"none",marginLeft:t.rhythm(1)}),g=u(g,"li",{marginBottom:"calc("+o+" / 2)"}),g=u(g,["ol li","ul li"],{paddingLeft:0}),g=u(g,["li > ol","li > ul"],{marginLeft:t.rhythm(1),marginBottom:"calc("+o+" / 2)",marginTop:"calc("+o+" / 2)"}),g=u(g,["blockquote *:last-child","li *:last-child","p *:last-child"],{marginBottom:0}),g=u(g,["li > p"],{marginBottom:"calc("+o+" / 2)"}),g=u(g,["code","kbd","pre","samp"],p({},t.adjustFontSizeTo("85%"))),(g=u(g,["abbr","acronym"],{borderBottom:"1px dotted "+i(50),cursor:"help"}))["abbr[title]"]={borderBottom:"1px dotted "+i(50),cursor:"help",textDecoration:"none"},g=u(g,["table"],p({},t.adjustFontSizeTo(e.baseFontSize),{borderCollapse:"collapse",width:"100%"})),g=u(g,["thead"],{textAlign:"left"}),g=u(g,["td,th"],{textAlign:"left",borderBottom:"1px solid "+i(88),fontFeatureSettings:'"tnum"',MozFontFeatureSettings:'"tnum"',msFontFeatureSettings:'"tnum"',WebkitFontFeatureSettings:'"tnum"',paddingLeft:t.rhythm(2/3),paddingRight:t.rhythm(2/3),paddingTop:t.rhythm(.5),paddingBottom:"calc("+t.rhythm(.5)+" - 1px)"}),g=u(g,"th:first-child,td:first-child",{paddingLeft:0}),g=u(g,"th:last-child,td:last-child",{paddingRight:0}),g=u(g,["h1","h2","h3","h4","h5","h6"],{color:e.headerColor,fontFamily:e.headerFontFamily.map(b).join(","),fontWeight:e.headerWeight,textRendering:"optimizeLegibility"});var f=t.scale(1),y=t.scale(.6),S=t.scale(.4),F=t.scale(0),v=t.scale(-.2),B=t.scale(-.3);return n([f,y,S,F,v,B],function(t,o){g=r(g,"h"+(o+1)+".fontSize",t.fontSize),g=r(g,"h"+(o+1)+".lineHeight",e.headerLineHeight)}),m(e.plugins)&&(g=h(e.plugins,function(o,i){return d(o,i(t,e,o))},g)),e.overrideStyles&&s(e.overrideStyles)&&(g=d(g,e.overrideStyles(t,e,g))),e.overrideThemeStyles&&s(e.overrideThemeStyles)&&(g=d(g,e.overrideThemeStyles(t,e,g))),g}(f,c)},toString:function(){return F(0,c,this.toJSON())},injectStyles:function(){if("undefined"!=typeof document)if(document.getElementById("typography.js"))document.getElementById("typography.js").innerHTML=this.toString();else{var t=document.createElement("style");t.id="typography.js",t.innerHTML=this.toString();var e=document.head;e.firstChild?e.insertBefore(t,e.firstChild):e.appendChild(t)}}})};export{v as default}; //# sourceMappingURL=index.esm.js.map