UNPKG

typography

Version:

Opinionated toolkit for building websites with beautiful typography

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