项目作者: facjure

项目描述 :
A toolkit for Kinetic Web Typography
高级语言: Clojure
项目地址: git://github.com/facjure/mesh.git
创建时间: 2014-04-22T00:09:09Z
项目社区:https://github.com/facjure/mesh

开源协议:Eclipse Public License 1.0

下载


Mesh

A Responsive Grid & Web Typography toolkit for Clojure & Clojurescript.

Built on Garden.

Rationale

Web Design is 95% Typography - iA

Features

My current priority is to build a Clojurescript interface to CSS
Grid
, CSS
Animations

specs in the context of Typography and Graphic Design.

Early research includes expressing:

  • A grid in a single fn
  • Available grids: columnar, container-row-column, fluid-nested-grid, golden-grid
  • Baseline Grid in a single fn
  • Modular Scale in a single fn
  • Viewport Math in a single fn
  • Baseline Typography
  • Typography mixins, and responsive utilities with gardener.
  • Create new DSLs

Quickstart

Early prototypes:

A simple 8-column grid with col-x classes:

  1. (grid/create-minimal-grid ".grid" (px 20))

Fluid, Fractional grids

  1. (def gutter (px 20))
  2. (def grids
  3. (list (grid/create ".grid" gutter)
  4. (grid/wrap-widths 978)
  5. (grid/create-nested-units)
  6. (grid/nuke-gutters-and-padding)
  7. (grid/respond-small (:mobile breakpoints) gutter)
  8. (grid/respond-medium (:tablet breakpoints))))

Nested Grids

Add the following to fluid grids:

  1. (grid/create-nested-units)

Baseline Typpography

  1. (grid/zoomable-baseline-grid 16 24)

Create new DSLs

You may be working with a Creative Director or a Print Designer who does not
understand CSS. But they understand Design. Wouldn’t it be nice to understand
their specs and codify them into data?

Designer: Make the headings serifs and scale-types using four breakpoints
(take 480 px increments). And yes, use our brand settings.

  1. (def settings
  2. {:min-width (px 400)
  3. :max-width (px 1200)
  4. :min-font (px 12)
  5. :max-font (px 32)
  6. :body-font (:eb-garamond typo/font-families)
  7. :header-font (:eb-garamond typo/font-families)
  8. :header-font-weight 600
  9. :header-color "#111"
  10. :scale :golden-ratio
  11. :breakpoints {:mobile (px 480)
  12. :tablet (px 960)
  13. :laptop (px 1440)
  14. :monitor (px 1920)}})
  15. (def fonts {:font-size-base (em 1.5)
  16. :line-height-base (em 1.45)
  17. :ff-serif ["EB Garamond" "Serif"]
  18. :ff-sans ["Fira Sans" "sans-serif"]
  19. :ff-mono ["Source Code Pro" "monospace"]})
  20. (defn headings [declarations]
  21. [:h1 :h2 :h3 :header declarations])
  22. ;; Create your own DSL
  23. (-> headings
  24. (scale-type settings)
  25. (make-serifs typo/font-families)))

Functional programmer: “Sure, let me build two higher order functions.”

  1. ;; a bad example
  2. (defn make-serifs [selector families]
  3. (fn [declarations]
  4. (let [styles (selector declarations)]
  5. (conj styles (font (:garamond families) 3 600 0.5 2)))))
  6. ;; slightly better
  7. (defn scale-type [selector params]
  8. (fn [declarations]
  9. (let [styles (selector declarations)]
  10. (conj styles
  11. (at-media {:min-width (get-in params [:breakpoints :mobile])}
  12. [:& {:font-size (* 1.5 (:min-font params))}])
  13. (at-media {:min-width (get-in params [:breakpoints :tablet])}
  14. [:& {:font-size (* 1.75 (:min-font params))}])
  15. (at-media {:min-width (get-in params [:breakpoints :laptop])}
  16. [:& {:font-size (* 2.25 (:min-font params))}])))))

Examples

Examples include example designs with Om and soon Reagent.

Run examples with the current mesh src, using figwheel:

  1. lein dev
  • typography: showcase of all grids with Clj (compile to css)
  • grids: showcase of all grids with Clj (compile to css)

Clojure or Clojurescript?

Styles can be compiled on the server, client, or generated as plain css files.

Write styles in Clojure when you prefer static styles or compiled styles on
server. Assuming you’re running lein garden auto with :stylesheet app.styles/index set in its build id, all styles will be compiled into css on
disk.

Write styles in Clojurescript when you want styles to be dynamically
included at runtime, via Js or Cljs. This is useful if you’re building
fine-grained components based on React-like libraries: rather than bundling
styles into a single file, just import individual styles as functions:

  1. (ns app.styles
  2. (:require [garden.core :refer [css]]))
  3. (def index
  4. (css grids)))
  5. (mesh.utils/insert-styles styles/index)

Invoke styles via plain old Javascript:

  1. mesh.dom.insert_styles(app.styles.index)

You don’t need complex build tools like Webpack in
Clojurescript. Just Convert CSS into data and pass them around as code.

Credits

Joel Holbrooks for creating Garden, Chris Coyler for countless
CSS-Tricks.

I learned a lot by studying the source of multiple libraries (see references),
and may have borrowed ideas from them. Starting this library would have been
much harder without the work of these designers.

References

Contributing

Mesh is currently in the development phase. I will be open to contributions
during Alpha.

Status

Development.

Clojars Project

License

Copyright © 2015-2019 Facjure, LLC.

Released under the Eclipse Public License, same as Clojure & Clojurescript.