css-ratiocinator

because your CSS is garbage

  • 所有者: begriffs/css-ratiocinator
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Logo

The CSS Ratiocinator automatically refactors your CSS and generates a
new stylesheet for your site. It works by examining your site's live DOM
in the browser and reverse engineering a new, more elegant definition
that captures styles down to the pixel.

It addresses the problem of old CSS whose styles accumulate and
contradict each other. After a certain point all CSS seems to grow only
by internal antagonism. The Ratiocinator wipes the slate clean and
provides a harmonious new beginning.

Build Status

Usage

This program runs from the command line using the
PhantomJS headless browser.

  1. Install PhantomJS
  2. Clone this repo
  3. In the cloned directory, run phantomjs ratiocinate.js URL
  4. The new CSS will appear.
  5. (optionally) Feed output through sass-convert

Faq

Mechanism

The Ratiocinator proceeds in two phases: assessment and consolidation.
During assessment it determines which nodes will need which styles,
accounting for browser defaults and cascade rules. The browser provides
a full list of computed style for every node, and our first step is to
prune redundancies from cascaded style in a depth-first process called
"lifting."

Lifting

The last step in assessment is stripping default styles. The final
style needn't specify CSS defaults, so we remove them prior to the
consolidation phase.

Next comes consolidation, where we find shared pieces of style
throughout the cleaned DOM tree and extract them to CSS declarations.

Consolidating

In the diagram above, the Ratiocinator will choose to output a
declaration for the styles in red before those in blue. Although there
are more blue items than red in element aside.foo, there are more red
elements overall. The red has greater "volume." Hence the Ratiocinator
will extract styles for all elements with class foo first and then for
aside elements second.

Finally the Ratiocinator detects media query width breakpoints and
samples the page style between them. It analyzes the responsive
portfolio and extracts common base-style. It outputs the base-style and
each width-specific style with appropriate media queries.

Bugs and Edge Cases

Currently, anything Phantom considers to be an invalid property, value,
or selector is discarded. This means that the following CSS...

body {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
}
::selection{
  background:rgba(246,55,0,0.9);
  color:#fff;
}
::-moz-selection{
  background:rgba(246,55,0,0.9);
  color:#fff;
}

Is compressed to the following CSS...

body {
  display: -webkit-box;
}

This is an invalid compression. A solution is being worked on in
issue #52.

Contributing

It is currently very easy to contribute. Just find something that the
Ratiocinator does wrong and tell me. The best complaints are very
specific, preferably made into a new test and submitted via a pull
request. Luckily that's easy too:

  1. Find some styles that the Ratiocinator is botching.
  2. Think of the smallest example that will illustrate the problem.
  3. Add a new test by copying test/template.html and filling in the blanks.
  4. Save your new test in the test/ folder.
  5. Run phantomjs test.js and make sure it fails.
  6. Submit pull request to the bug-reports branch.

License

The CSS Ratiocinator is Copyright © 2012 Joe Nelson. It is free
software, and may be redistributed under the terms specified in the
LICENSE file.

主要指标

概览
名称与所有者begriffs/css-ratiocinator
主编程语言JavaScript
编程语言JavaScript (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2012-05-25 21:08:34
推送于2015-07-24 17:38:47
最后一次提交2015-07-24 10:38:46
发布数0
用户参与
星数1k
关注者数36
派生数45
提交数175
已启用问题?
问题数47
打开的问题数15
拉请求数11
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?