diff --git a/.editorconfig b/.editorconfig index f71224a..5157391 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,4 @@ -# 本文件用于在不同的编辑器中统一代码风格 -# 请为你的编辑器安装 EditorConfig 插件 +# This file is for unifying the coding style for different editors and IDEs # editorconfig.org root = true @@ -10,17 +9,9 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[**.js] -indent_style = space -indent_size = 4 - -[**.styl] -indent_style = space +[*.{js,styl,html,json}] indent_size = 4 - -[**.html] indent_style = space -indent_size = 4 [*.md] trim_trailing_whitespace = false diff --git a/.fecsignore b/.fecsignore new file mode 100644 index 0000000..3235caf --- /dev/null +++ b/.fecsignore @@ -0,0 +1,2 @@ +test/** +demo/** diff --git a/.fecsrc b/.fecsrc new file mode 100644 index 0000000..78d9af3 --- /dev/null +++ b/.fecsrc @@ -0,0 +1,10 @@ +{ + "eslint": { + "env": { + "node": true + }, + "rules": { + "no-console": 0 + } + } +} diff --git a/.gitignore b/.gitignore index fba44de..eeda977 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -*.log +.idea/ node_modules/ .DS_Store demo/**/*.css +*.log diff --git a/.npmignore b/.npmignore index 5c05e59..4415c0a 100644 --- a/.npmignore +++ b/.npmignore @@ -1,2 +1,3 @@ demo/ test/ +demo.js diff --git a/.travis.yml b/.travis.yml index 6e5919d..7ab627a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: node_js node_js: - "0.10" + - "0.12" diff --git a/History.md b/History.md index 333db60..954a3a2 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,28 @@ +2.0.0 / 2015-06-17 +================== + + * **Breaking Change** 改进 Function:`bg()`, `ir()` [#18](https://github.com/ecomfe/rider/issues/18) + * **Breaking Change** 改进 Root Mixin:`font-face()` [#16](https://github.com/ecomfe/rider/issues/16) [#24](https://github.com/ecomfe/rider/issues/24) + * **Breaking Change** 改进 Block Mixin:`+breakpoint()`,移除组合能力,迁出 retina 支持 [#19](https://github.com/ecomfe/rider/issues/19) + * **Breaking Change** 移除:retina 支持中的浏览器兼容代码 [#17](https://github.com/ecomfe/rider/issues/17) + * **Breaking Change** 移除 全局变量:`$-image-dppx`,retina 图片机制已更新 + * 增加 全局变量:`$-code-font-family` 作为代码段默认字体 + * 增加 全局变量:`$-image-dppx-range` 作为 retina 图片的探测范围 + * 增加 全局变量:`$-image-dppx-separator` 作为 retina 图片的分隔符 + * 增加 全局变量:`$-image-dppx-quality-first` 作为 retina 图片质量优先模式的开关 + * 增加 全局变量:`$-unit-precision` 作为单位转换的小数点精度控制 + * 增加 Function:`bg2x()`, `bg3x()`, `bg-dppx()` [#23](https://github.com/ecomfe/rider/issues/23) + * 增加 Function:`file-exists()`, `is-url()`, `get-retina-src()` [#15](https://github.com/ecomfe/rider/issues/15) + * 增加 Mixin:`normalize()` 作为布局初始化的补充 [#8](https://github.com/ecomfe/rider/issues/8) + * 增加 Mixin:`circle()` 生成圆形或椭圆 + * 增加 Block Mixin:`+retina()` [#20](https://github.com/ecomfe/rider/issues/20) + * 改进 Function:`rem()`, `em()`, `px()` 单位转换定义截取小数点位数 [#4](https://github.com/ecomfe/rider/issues/4) + * 改进 Mixin:`animate()` 升级至 animate.css 3.2.6 版 [#5](https://github.com/ecomfe/rider/issues/5) + * 改进:测试脚本启用 inline diff [#7](https://github.com/ecomfe/rider/issues/7) + * 改进:简化 demo 的支持部分 [#6](https://github.com/ecomfe/rider/issues/6) + * 改进:文档重新经过深入整理 [#21](https://github.com/ecomfe/rider/issues/21) + 0.4.4 / 2014-11-06 ================== diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9418541 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Baidu Inc. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 83ceeb0..7565028 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,35 @@ -rider [![NPM version](https://badge.fury.io/js/rider.png)](https://npmjs.org/package/rider) [![Build Status](https://travis-ci.org/ecomfe/rider.png)](https://travis-ci.org/ecomfe/rider) [![DevDependencies Status](https://david-dm.org/ecomfe/rider/dev-status.png)](https://david-dm.org/ecomfe/rider#info=devDependencies) +rider === -`rider` 是一个基于 [`stylus`](https://github.com/LearnBoost/stylus)、专注于 **移动 Web** 的 CSS 样式库。 +[![NPM version](https://img.shields.io/npm/v/rider.svg?style=flat-square)](https://npmjs.org/package/rider) [![Build Status](https://img.shields.io/travis/ecomfe/rider.svg?style=flat-square)](https://travis-ci.org/ecomfe/rider) [![License](https://img.shields.io/npm/l/rider.svg?style=flat-square)](./LICENSE) [![EFE Mobile Team](https://img.shields.io/badge/EFE-Mobile_Team-blue.svg?style=flat-square)](http://efe.baidu.com) -它提供了样式初始化、顺时针简写、缓动函数、图片、排版、单位转换、形状、动画、响应式工具等功能,可以让你的前端样式开发更轻松、更省心。 +`rider` 是基于 [Stylus](http://stylus-lang.com) 与后处理器、无侵入风格的 CSS 样式工具库。 -## 文档 +基于 `rider` 开发 **项目** 或 **UI 样式库**,能有效提高开发效率,延长代码生命周期。 -+ 安装与配置 - + [在 `edp` 环境使用](https://github.com/ecomfe/edp-provider-rider) - + [在 `connect`/`express` 环境使用](./doc/connect.md) -+ [API](./doc/api.md) -+ [代码风格](./doc/code-style.md) -+ [常见问题](./doc/faq.md) -+ [DEMO与单元测试](./doc/demo-and-ut.md) +## 功能 + + * [特性](./doc/feature.md) + * [样式初始化](./doc/initialize.md) + * [顺时针简写](./doc/clockhand.md) + * [缓动函数](./doc/easing.md) + * [图片](./doc/image.md) + * [排版](./doc/typography.md) + * [形状](./doc/shape.md) + * [动画](./doc/animate.md) + * [单位转换](./doc/unit.md) + * [响应式工具](./doc/breakpoint.md) + * [Retina 支持](./doc/retina.md) + * [辅助函数](./doc/helper.md) + +## 使用 + + * 安装与配置 + * [edp 环境](https://github.com/ecomfe/edp-provider-rider) + * [connect/express 环境](./doc/connect.md) + * [代码风格](./doc/code-style.md) + * [常见问题](./doc/faq.md) + +## License + +MIT © [Baidu Inc.](./LICENSE) diff --git a/demo.js b/demo.js new file mode 100644 index 0000000..d26813a --- /dev/null +++ b/demo.js @@ -0,0 +1,51 @@ +/** + * @file rider demo + * @author firede(firede@firede.us) + */ + +var path = require('path'); +var http = require('http'); + +var connect = require('connect'); +var serveStatic = require('serve-static'); + +var stylus = require('stylus'); +var rider = require('./lib/rider'); +var ap = require('autoprefixer-core'); + +var app = connect(); +var port = 8888; + +function compile(str, filePath) { + return stylus(str) + .set('filename', filePath) + .define('url', stylus.resolver()) + .use(rider()) + .on('end', prefixer); +} + +function prefixer(_, css) { + return ap( + { + browsers: [ + '> 5%', + 'iOS >= 6', + 'Android >= 2.3', + 'ExplorerMobile >= 10' + ] + } + ).process(css).css; +} + +app.use(stylus.middleware({ + src: path.join(__dirname, 'demo'), + compile: compile +})); + +app.use( + serveStatic(path.join(__dirname, 'demo')) +); + +http.createServer(app).listen(port, function () { + console.log('Rider demo started on port %d', port); +}); diff --git a/demo/animate.html b/demo/animate.html new file mode 100644 index 0000000..e69de29 diff --git a/demo/css/animate.styl b/demo/css/animate.styl new file mode 100644 index 0000000..62cceba --- /dev/null +++ b/demo/css/animate.styl @@ -0,0 +1,5 @@ +.test + animate('bounce') + +.abc + animate('bounce', 0.5s) diff --git a/demo/public/breakpoint.styl b/demo/css/breakpoint.styl similarity index 100% rename from demo/public/breakpoint.styl rename to demo/css/breakpoint.styl diff --git a/demo/public/easing.styl b/demo/css/easing.styl similarity index 100% rename from demo/public/easing.styl rename to demo/css/easing.styl diff --git a/demo/public/index.styl b/demo/css/index.styl similarity index 100% rename from demo/public/index.styl rename to demo/css/index.styl diff --git a/demo/public/initialize.styl b/demo/css/initialize.styl similarity index 100% rename from demo/public/initialize.styl rename to demo/css/initialize.styl diff --git a/demo/public/layout.styl b/demo/css/layout.styl similarity index 92% rename from demo/public/layout.styl rename to demo/css/layout.styl index 123d374..36dc202 100644 --- a/demo/public/layout.styl +++ b/demo/css/layout.styl @@ -2,7 +2,7 @@ initialize() // Fonts -font-face('rider-icon', 'font/rider-icon', '1') +font-face('rider-icon', '../font/rider-icon') [class^="icon-"], [class*=" icon-"] font-family: 'rider-icon' @@ -37,7 +37,7 @@ font-face('rider-icon', 'font/rider-icon', '1') font-size: rem(16) margin: 0 auto &.logo - ir: 'img/logo.png' + ir: '../img/logo.png' size: 75px 44px .next .prev diff --git a/demo/public/shape.styl b/demo/css/shape.styl similarity index 85% rename from demo/public/shape.styl rename to demo/css/shape.styl index 57c82fd..fd21b34 100644 --- a/demo/public/shape.styl +++ b/demo/css/shape.styl @@ -37,3 +37,10 @@ absolute: 15px -10px _ _ triangle: right 10px #939 +.circle-test-1 + circle: 60px 80px + background: #ccc + +.circle-test-2 + circle: 2rem + background: #ccc diff --git a/demo/views/easing.ejs b/demo/easing.html similarity index 98% rename from demo/views/easing.ejs rename to demo/easing.html index 24a2ccc..047c63e 100644 --- a/demo/views/easing.ejs +++ b/demo/easing.html @@ -4,7 +4,7 @@ - + easing diff --git a/demo/public/img/logo.png b/demo/img/logo.png similarity index 100% rename from demo/public/img/logo.png rename to demo/img/logo.png diff --git a/demo/views/index.ejs b/demo/index.html similarity index 86% rename from demo/views/index.ejs rename to demo/index.html index 4e256fe..fc65b08 100644 --- a/demo/views/index.ejs +++ b/demo/index.html @@ -4,7 +4,7 @@ - + rider @@ -13,7 +13,7 @@

rider

- + easing
@@ -22,7 +22,7 @@

rider

- + shape
@@ -31,7 +31,7 @@

rider

- + initialize
diff --git a/demo/views/initialize.ejs b/demo/initialize.html similarity index 99% rename from demo/views/initialize.ejs rename to demo/initialize.html index 8d056e1..739d95d 100644 --- a/demo/views/initialize.ejs +++ b/demo/initialize.html @@ -4,7 +4,7 @@ - + initialize diff --git a/demo/server.js b/demo/server.js deleted file mode 100644 index 1af4f71..0000000 --- a/demo/server.js +++ /dev/null @@ -1,49 +0,0 @@ -var express = require('express'); -var stylus = require('stylus'); -var rider = require('../lib/rider'); -var ap = require('autoprefixer-core'); -var path = require('path'); - -var app = express(); - -function compile(str, filePath) { - return stylus(str) - .set('filename', filePath) - .set('resolve url', true) - .use(rider()) - .on('end', prefixer); -} - -function prefixer(err, css) { - return ap( - { - browsers: ['Android >= 2.3', 'iOS >= 5', 'ExplorerMobile >= 10'] - } - ).process(css).css; -} - -app.set('views', path.join(__dirname, '/views')); -app.set('view engine', 'ejs'); -app.use(stylus.middleware({ - src: path.join(__dirname, 'public'), - compile: compile -})); -app.use(express.static(path.join(__dirname, 'public'))); - -app.get('/:page?', function (req, res) { - var page = req.params.page || 'index'; - var viewPath = path.join(app.get('views'), page + '.ejs'); - var fs = require('fs'); - - if (fs.existsSync(viewPath)) { - res.set('Content-Type', 'text/html'); - res.render(page); - } - else { - res.status(404).end(); - } -}); - -var server = app.listen(8888, function () { - console.log('Rider example started on port %d', server.address().port); -}); diff --git a/demo/views/shape.ejs b/demo/shape.html similarity index 78% rename from demo/views/shape.ejs rename to demo/shape.html index 0042324..c36c215 100644 --- a/demo/views/shape.ejs +++ b/demo/shape.html @@ -4,7 +4,7 @@ - + shape @@ -17,7 +17,7 @@

size: 50px

- +

size: 100px, 50px

@@ -38,6 +38,15 @@

triangle: right 10px #939 (with &:after)

+

circle: 60px 80px

+
+
+
+ +

circle: 2rem

+
+
+
diff --git a/doc/animate.md b/doc/animate.md new file mode 100644 index 0000000..761971a --- /dev/null +++ b/doc/animate.md @@ -0,0 +1,72 @@ +动画 +=== + +### animate: name, duration, fill-mode + +快速添加来自 `Animate.css` 的动画。 + +应用于 CSS 根节点时,只生成动画的 `@keyframes`。 +应用于 CSS 选择器时,生成动画的 `@keyframes` 与 `animation` 相关属性。 + +同一个动画,`@keyframes` 只会被引入一次。 + +支持的动画有: + +`bounce` `bounceIn` `bounceInDown` `bounceInLeft` `bounceInRight` +`bounceInUp` `bounceOut` `bounceOutDown` `bounceOutLeft` +`bounceOutRight` `bounceOutUp` `fadeIn` `fadeInDown` `fadeInDownBig` +`fadeInLeft` `fadeInLeftBig` `fadeInRight` `fadeInRightBig` +`fadeInUp` `fadeInUpBig` `fadeOut` `fadeOutDown` `fadeOutDownBig` +`fadeOutLeft` `fadeOutLeftBig` `fadeOutRight` `fadeOutRightBig` +`fadeOutUp` `fadeOutUpBig` `flash` `flip` `flipInX` `flipInY` +`flipOutX` `flipOutY` `hinge` `lightSpeedIn` `lightSpeedOut` `pulse` +`rollIn` `rollOut` `rotateIn` `rotateInDownLeft` `rotateInDownRight` +`rotateInUpLeft` `rotateInUpRight` `rotateOut` `rotateOutDownLeft` +`rotateOutDownRight` `rotateOutUpLeft` `rotateOutUpRight` +`rubberBand` `shake` `slideInDown` `slideInLeft` `slideInRight` +`slideOutLeft` `slideOutRight` `slideOutUp` `swing` `tada` `wobble` +`zoomIn` `zoomInDown` `zoomInLeft` `zoomInRight` `zoomInUp` `zoomOut` +`zoomOutDown` `zoomOutLeft` `zoomOutRight` `zoomOutUp` + +各种动画的效果可参考 [Animate.css](http://daneden.github.io/animate.css/),使用示例如下: + +```stylus +// 在根节点使用 +animate('flash') + +// 在选择器中使用 +.box + animate('pulse', .5s) +``` + +生成的 CSS: + +```css +/* 在根节点使用,只生成 @keyframes */ +@keyframes flash { + 0%, 50%, 100% { + opacity: 1; + } + 25%, 75% { + opacity: 0; + } +} + +/* 在选择器中使用,生成 @keyframes 与 animation 相关属性 */ +.box { + animation-name: pulse; + animation-duration: 0.5s; + animation-fill-mode: both; +} +@keyframes pulse { + 0% { + transform: scale3d(1, 1, 1); + } + 50% { + transform: scale3d(1.05, 1.05, 1.05); + } + 100% { + transform: scale3d(1, 1, 1); + } +} +``` diff --git a/doc/api.md b/doc/api.md index 5df05df..1630f15 100644 --- a/doc/api.md +++ b/doc/api.md @@ -9,11 +9,12 @@ API ---|---|--- `$-base-font-size` | `16px` | 用于设置默认文字大小、常用单位的转换 `$-base-font-family` | `'Helvetica Neue', sans-serif` | 默认字体 -`$-prevent-user-select` | `false` | 屏蔽用户选择文本的能力,通常用在 Hybrid App 场景 +`$-code-font-family` | `Menlo, Consolas, monospace` | 代码的默认字体 `$-prevent-text-size-adjust` | `true` | 屏蔽屏幕翻转时,浏览器缩放字体的行为 `$-prevent-tap-highlight` | `true` | 屏蔽 `a` 标签的点击高亮效果 `$-image-dppx` | `2` | 图片每像素的点数,用于支持 retina 设备 `$-breakpoint-slice` | `0 400px 600px 800px 1050px` | 响应式Web设计屏幕尺寸的划分 +`$-unit-precision` | `5` | 单位精度,转换后保留的小数位数 ## 样式初始化 @@ -409,7 +410,7 @@ css: } ``` -### font-face: font-family, font-path, version-suffix +### font-face: font-family, font-path 快速引入字体。 @@ -417,20 +418,19 @@ css: + `font-family` 字体名 + `font-path` 字体路径,是字体去掉后缀名之后的部分 -+ `version-suffix` `(可选)` 版本后缀,用来更新字体版本 **使用方法** stylus: ```haml -font-face('rider-icon', 'font/rider-icon', '88') +font-face('rider-icon', 'font/rider-icon') ``` ```css @font-face { font-family: 'rider-icon'; - src: url("font/rider-icon.woff?88") format('woff'), url("font/rider-icon.ttf?88") format('truetype'); + src: url("font/rider-icon.woff") format('woff'), url("font/rider-icon.ttf?88") format('truetype'); font-weight: normal; font-style: normal; } @@ -554,13 +554,16 @@ css: bounce bounceIn bounceInDown bounceInLeft bounceInRight bounceInUp bounceOut bounceOutDown bounceOutLeft bounceOutRight bounceOutUp - fadeIn fadeInDown fadeInLeft fadeInRight fadeInUp fadeOut fadeOutDown - fadeOutLeft fadeOutRight fadeOutUp flash flip flipInX flipInY - flipOutX flipOutY hinge lightSpeedIn lightSpeedOut pulse rollIn rollOut - rotateIn rotateInDownLeft rotateInDownRight rotateInUpLeft rotateInUpRight - rotateOut rotateOutDownLeft rotateOutDownRight rotateOutUpLeft - rotateOutUpRight rubberBand shake slideInDown slideInLeft slideInRight - slideOutLeft slideOutRight slideOutUp swing tada wobble + fadeIn fadeInDown fadeInDownBig fadeInLeft fadeInLeftBig fadeInRight + fadeInRightBig fadeInUp fadeInUpBig fadeOut fadeOutDown fadeOutDownBig + fadeOutLeft fadeOutLeftBig fadeOutRight fadeOutRightBig fadeOutUp fadeOutUpBig + flash flip flipInX flipInY flipOutX flipOutY hinge lightSpeedIn lightSpeedOut + pulse rollIn rollOut rotateIn rotateInDownLeft rotateInDownRight + rotateInUpLeft rotateInUpRight rotateOut rotateOutDownLeft rotateOutDownRight + rotateOutUpLeft rotateOutUpRight rubberBand shake slideInDown slideInLeft + slideInRight slideOutLeft slideOutRight slideOutUp swing tada wobble + zoomIn zoomInDown zoomInLeft zoomInRight zoomInUp + zoomOut zoomOutDown zoomOutLeft zoomOutRight zoomOutUp 动画效果可以参考 [Animate.css](http://daneden.github.io/animate.css/) diff --git a/doc/breakpoint.md b/doc/breakpoint.md new file mode 100644 index 0000000..d51ff1b --- /dev/null +++ b/doc/breakpoint.md @@ -0,0 +1,170 @@ +响应式工具 +=== + +`rider` 提供的响应式工具叫 `Breakpoint`(思路来自 [breakpoint-slicer](https://github.com/lolmaus/breakpoint-slicer)),以 `Block Mixin` 的方式调用。 + +在做 **响应式布局** 时,按照 **屏幕宽度** 的范围,划分成几个 **切片**: + + Breakpoint: 0 400px 600px 800px 1050px + ├───────────────────┼─────────┼──────────┼───────────┼────────> + 切片 #: 1 2 3 4 5 + +以上面的划分方式为例,我们可以使用 **切片** 的编号来表示宽度的区间。 + +切片的划分与 **设计** 强相关,每个项目的划分方式可能是不同的。 +**建议** 在项目开始时,先通过全局配置 `$-breakpoint-slice` 定义好切片的划分方式。 + +生成 Media Query 阶段,如果是根据 **切片** 设置 `min-width`,会自动加 `1px` 错开上一个区间,以确保边界值正常。 + +**注意**:因为新版 Stylus 对 `@media` 标签嵌套已有较好的支持,`rider` 2.0 之前的版本的 **规则组合** 能力现已移除。 + +相关的[全局配置](./setting.md): + + * `$-breakpoint-slice` + +### +below(value) + +限定低于目标尺寸或 **切片** 边界值。 + + Breakpoint: 0 400px 600px 800px 1050px + ├───────────────────┼─────────┼──────────┼───────────┼────────> + 切片 #: 1 2 3 4 5 + · · · below(3) · · + <────────────────────────────────────────┤ + +`value` 带单位时为具体的值,不带单位时为对应 **切片** 的值。 + +```stylus +.test + // 直接使用 + +below(3) + foo: bar + + // 与 +retina() 嵌套使用 + +retina() + +below(3) + bar: baz +``` + +生成的 CSS: + +```css +@media (max-width: 800px) { + .test { + foo: bar; + } +} + +@media (min-resolution: 1.5dppx) and (max-width: 800px), (min-resolution: 144dpi) and (max-width: 800px) { + .test { + bar: baz; + } +} +``` + +### +above(value) + +限定高于目标尺寸或 **切片** 边界值。 + + Breakpoint: 0 400px 600px 800px 1050px + ├───────────────────┼─────────┼──────────┼───────────┼────────> + 切片 #: 1 2 3 4 5 + · · · above(3) · · + ├───────────────────────────────> + +`value` 带单位时为具体的值,不带单位时为对应 **切片** 的值。 + +stylus: + +```stylus +// Block Mixin 与选择器的嵌套可按逻辑顺序书写 +// 最终生成的 @media 将会提至最顶层 ++above(3) + .test + foo: bar + +// 也可以直接指定具体的值 ++above(681px) + .tablet + color: #f00 +``` + +生成的 CSS: + +```css +@media (min-width: 601px) { + .test { + foo: bar; + } +} + +@media (min-width: 681px) { + .tablet { + color: #f00; + } +} +``` + +### +at(value) + +限定指定 **切片** 范围。`value` 为切片编号。 + + Breakpoint: 0 400px 600px 800px 1050px + ├───────────────────┼─────────┼──────────┼───────────┼────────> + 切片 #: 1 2 3 4 5 + · · · at(3) · · + ├──────────┤ + +```stylus +.test + foo: bar + +at(3) + bar: baz +``` + +生成的 CSS: + +```css +.test { + foo: bar; +} +@media (min-width: 601px) and (max-width: 800px) { + .test { + bar: baz; + } +} +``` + +### +between(from-value, to-value) + +限定目标尺寸或 **切片** 边界值的区间。 + + Breakpoint: 0 400px 600px 800px 1050px + ├───────────────────┼─────────┼──────────┼───────────┼────────> + 切片 #: 1 2 3 4 5 + · · between(3) · · + ├────────────────────┤ + +`value` 带单位时为具体的值,不带单位时为对应 **切片** 的值。 + +```stylus +// breakpoint 可与 @media 嵌套使用 +@media (orientation: landscape) + .test + +between(2, 3) + foo: bar +``` + +生成的 CSS: + +```css +@media (orientation: landscape) and (min-width: 401px) and (max-width: 800px) { + .test { + foo: bar; + } +} +``` + +### +breakpoint(from-value, to-value) + +以上 `Block Mixin` 的底层实现,现用法同 `+between()`,**不建议** 直接使用。 diff --git a/doc/clockhand.md b/doc/clockhand.md new file mode 100644 index 0000000..4b87950 --- /dev/null +++ b/doc/clockhand.md @@ -0,0 +1,117 @@ +顺时针简写 +=== + +在 `CSS` 语法中,可以通过 `顺时针` 的方式简写属性的值,比如 `padding`、`margin` 等。其规则如下: + + 上 右 下 左 => 1 2 3 4 + 上 右 下 => 1 2 3 2 + 上 右 => 1 2 1 2 + 上 => 1 1 1 1 + +类似的还有 `border-radius` 中,按照 `左上`、`右上`、`右下`、`左下` 顺序的简写方式。 + +但是,因为不存在代表 **未定义** 的占位符,使用简写后,每个方向都被设置了 **值**。 +为了解决这个问题,我们引入了一个 `_` 占位符,用来表示 **未定义** 的状态。 + +同时,我们也对一些符合 `顺时针简写` 规律的用法进行了拓展,使其用起来更高效。 + +### absolute: top right bottom left + +将当前容器设为 `absolute`,并设置定位的值。 + +```stylus +.mask + absolute: 0 +.toolbar + absolute: 60px 0 _ +``` + +生成的 CSS: + +```css +.mask { + position: absolute; + top: 0; + right: 0; + bottom: 0; + left: 0; +} +.toolbar { + position: absolute; + top: 60px; + right: 0; + left: 0; +} +``` + +### fixed: top right bottom left + +将当前容器设为 `fixed`,并设置定位的值。 + +```stylus +.back-to-top + fixed: _ 0 20px _ + // => position: fixed; right: 0; bottom: 20px; +``` + +### relative: top right bottom left + +将当前容器设为 `relative`,并设置定位的值。 + +```stylus +.box + relative: 10px _ _ _ + // => position: relative; top: 10px; +``` + +### padding: padding-top padding-right padding-bottom padding-left + +替换了 CSS 的 `padding`,处理使用了 `_` 占位符的情况。 + +```stylus +.content + padding: 20px + // => padding: 20px; + +.content code + padding: _ 5px + // => padding-right: 5px; padding-left: 5px; +``` + +### margin: margin-top margin-right margin-bottom margin-left + +替换了 CSS 的 `margin`,处理使用了 `_` 占位符的情况。 + +```stylus +.main + margin: _ auto + // => margin-right: auto; margin-left: auto; +``` + +### border-color: border-top-color border-right-color border-bottom-color border-left-color + +替换了CSS的 `border-color`,处理使用了 `_` 占位符的情况。 + +```stylus +.box + border-color: #f7f7f7 _ + // => border-top-color: #f7f7f7; border-bottom-color: #f7f7f7; +``` + +### border-style: border-top-style border-right-style border-bottom-style border-left-style + +替换了CSS的 `border-style`,处理使用了 `_` 占位符的情况。 + +### border-width: border-top-width border-right-width border-bottom-width border-left-width + +替换了CSS的 `border-width`,处理使用了 `_` 占位符的情况。 + +### clockhand: values, property-prefix, property-suffix, sides + +生成符合 **顺时针简写** 规则的属性,以上 Mixin 均是通过它来生成的,很少会直接用到。 + +```stylus +.test + clockhand: 1 2 3 4, 'foo', 'bar', (a b c d) + // => foo-a-bar: 1; foo-b-bar: 2; foo-c-bar: 3; foo-d-bar: 4; +``` diff --git a/doc/code-style.md b/doc/code-style.md index e34657e..dc46ed3 100644 --- a/doc/code-style.md +++ b/doc/code-style.md @@ -22,7 +22,7 @@ Mixin 字母全小写,多个单词用 `-` 连接,如: relative border-width -*说明:Mixin 的命名规则,是为了与 CSS 风格保持一致,以便对 CSS 进行增强。* +Mixin 的命名规则,是为了与 CSS 风格保持一致,以便对 CSS 进行增强。 ## 整体风格 @@ -33,14 +33,16 @@ Mixin 字母全小写,多个单词用 `-` 连接,如: initialize() .box - // 在给属性赋值、给 Mixin 传参数时,**用** `:`(冒号)分隔 - // 语句的结尾 **不加** `;`(分号) + // 采用 4 空格缩进 + // 在给属性赋值、给 Mixin 传参数时,用 `:`(冒号)分隔 + // 语句的结尾不加 `;`(分号) display: block size: 80px 60px box-shadow: 2px 2px 5px #999 + // 使用 Function 时,加括号传递参数 font-size: rem(14) -// 当 Mixin 应用于 CSS root 时,加括号执行 +// 当 Mixin 应用于 CSS 根节点时,加括号执行 font-face('rider-icon', 'font/rider-icon') ``` diff --git a/doc/connect.md b/doc/connect.md index 46a35d8..8078d42 100644 --- a/doc/connect.md +++ b/doc/connect.md @@ -54,3 +54,9 @@ initialize() // etc... ``` + +## 后处理器 + +`rider` 是一个面向标准 CSS 输出的样式库,需要与 `Autoprefixer` 等后处理器配合使用。 + +请参考 [autoprefixer-core](https://github.com/postcss/autoprefixer-core)、[css-mqpacker](https://github.com/hail2u/node-css-mqpacker) 的文档对后处理器进行配置。 diff --git a/doc/demo-and-ut.md b/doc/demo-and-ut.md deleted file mode 100644 index f46051d..0000000 --- a/doc/demo-and-ut.md +++ /dev/null @@ -1,36 +0,0 @@ -DEMO与单元测试 -=== - -发布版是不包含 `demo` 和 `test` 的,所以需要先将仓库 clone 到本地: - -```shell -$ git clone https://github.com/ecomfe/rider.git -``` - -之后进入项目根目录,安装依赖的 package: - -```shell -$ npm install -``` - -## DEMO - -在仓库根目录执行: - -```shell -$ node demo/server.js -``` - -访问网址: - - http://localhost:8888 - -## 测试用例 - -执行测试: - -```shell -$ npm test -``` - -测试用例在 `test/cases` 目录中,`.styl` 文件与同名的 `.css` 文件对应。 diff --git a/doc/easing.md b/doc/easing.md new file mode 100644 index 0000000..e63b1da --- /dev/null +++ b/doc/easing.md @@ -0,0 +1,27 @@ +缓动函数 +=== + +CSS默认提供的缓动函数有限,我们通过贝塞尔曲线对缓动函数进行了扩充。 + +### easing(type) + +生成 **指定类型** 的缓动函数。 + +支持的类型有: + +`in-sine` `out-sine` `in-out-sine` +`in-quad` `out-quad` `in-out-quad` +`in-cubic` `out-cubic` `in-out-cubic` +`in-quart` `out-quart` `in-out-quart` +`in-quint` `out-quint` `in-out-quint` +`in-expo` `out-expo` `in-out-expo` +`in-circ` `out-circ` `in-out-circ` +`in-back` `out-back` `in-out-back` + +各缓动函数的效果可以参考 [easings.net](http://easings.net/zh-cn),使用示例如下: + +```stylus +.box + transition: all 1s easing('in-sine') + // => transition: all 1s cubic-bezier(0.47, 0, 0.745, 0.715); +``` diff --git a/doc/faq.md b/doc/faq.md index e8f23f4..fe58ab6 100644 --- a/doc/faq.md +++ b/doc/faq.md @@ -1,17 +1,17 @@ 常见问题 === -## @require 和 @import 用哪个? +### @require 和 @import 用哪个? 根据需求而定,通常使用 `@require`。 `@require` 多次引入同一文件时只会执行一次,`@import` 每次都会执行。 -## RIA项目如何组织各视图样式? +### SPA项目如何组织各视图样式? -可以用 `CSS Class` 做命名空间,配合 `@require` 来拆分文件组织代码。但要让级别扁平化,避免多级嵌套: +可以用 `CSS Class` 做命名空间,配合 `@require` 来拆分文件组织代码。但请注意级别扁平化,避免太多嵌套级别: -```haml +```stylus .view-detail @require 'detail' .view-detail-comment @@ -20,3 +20,11 @@ .view-list @require 'list' ``` + +### 生成的 Media Query 太多怎么办? + +Breakpoint 让响应式代码的可读性更好,但会生成较多的 Media Query,建议使用后处理器 [css-mqpacker](https://github.com/hail2u/node-css-mqpacker) 进行优化,注意合并规则中的[顺序问题](https://github.com/hail2u/node-css-mqpacker#known-issues)。 + +### 其他问题? + +欢迎给我们 [提 issue](https://github.com/ecomfe/rider/issues/new)。 diff --git a/doc/feature.md b/doc/feature.md new file mode 100644 index 0000000..ee5c433 --- /dev/null +++ b/doc/feature.md @@ -0,0 +1,124 @@ +特性 +=== + +## 高效工作流 + +`rider` 通过前后处理器混合的方式,提供了更高效的工作流。 + + DSL(Stylus) → 标准 CSS → 生产环境 CSS + +通过 **预处理器** 处理样式层的抽象、复用,减少冗余;通过 **后处理器** 处理兼容性问题、优化输出。 + +在写 Stylus 时,只需面向 **标准 CSS** 开发;在后处理阶段,自动将 **标准 CSS** 转换为对目标浏览器优化后的 **生产环境 CSS**。 + +### 工作流的三个阶段 + +**DSL(Stylus):** + +```stylus +.navbar + fixed: _ 0 0 + display: flex + box-sizing: border-box +``` + +**标准 CSS:** + +```css +.navbar { + position: fixed; + right: 0; + bottom: 0; + left: 0; + display: flex; + box-sizing: border-box; +} +``` + +**生产环境 CSS:** + +```css +.navbar { + position: fixed; + right: 0; + bottom: 0; + left: 0; + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-box-sizing: border-box; + box-sizing: border-box; +} +``` + +## 无侵入风格 + +在预处理阶段,`rider` 的各种功能均通过 `Mixin`, `Function` 或 `Block Mixin` 的方式提供,只有在主动调用时才输出代码。 + +我们不提供直接给 HTML 调用的类名,不会用「样式类」污染 HTML 代码的语义。 + +所以,您能在享受 `rider` 各种便捷工具的同时,写出干净且符合语义的 HTML 代码。 + +### Bootstrap 风格与无侵入风格的对比 + +**Bootstrap 风格:** + +```html + + +
+

...

+ +
+``` + +```css +/* 无论是否用到,都输出所有样式 */ + +.col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, +.col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, +.col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, +.col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, +.col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, +.col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, +.col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, +.col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, +.col-md-12, .col-lg-12 { + /* 通用样式 */ +} +.col-xs-1, .col-xs-2, .col-xs-3, .col-xs-4, +.col-xs-5, .col-xs-6, .col-xs-7, .col-xs-8, +.col-xs-9, .col-xs-10, .col-xs-11, .col-xs-12 { + /* 另一组通用样式 */ +} +.text-danger { + /* ... */ +} +/* 更多没有被用到的样式 */ +``` + +**无侵入风格:** + +```html + + +
+

...

+ +
+``` + +```css +/* 无调用,不输出 */ + +.order { + /* 通过 Mixin, Function 生成样式 */ +} +.order .total-prices { + /* ... */ +} +.order .pay { + /* ... */ +} +``` diff --git a/doc/helper.md b/doc/helper.md new file mode 100644 index 0000000..56f073d --- /dev/null +++ b/doc/helper.md @@ -0,0 +1,51 @@ +辅助函数 +=== + +### file-exists(file) + +检测 **文件路径** 是否存在。 + +相关:[图片](./image.md),[排版](./typography.md) + +```stylus +.header + $img = '../img/bg.png' + if file-exists($img) + background: url($img) cover no-repeat + else + background: #369 +``` + +### is-url(url) + +检测是否是 URL。 + +这里的检测并不严格,此函数的目的主要是快速区分 **远程路径** 与 **本地路径**。 + +相关:[排版](./typography.md) + +```stylus +is-url('../font/icon.ttf') +// => false + +is-url('http://efe.baidu.com/font/icon.ttf') +// => true +``` + +### get-retina-src(src, dppx, separator) + +获取高分辨率版本的图片地址。 + + * `src` - 图片路径 + * `dppx` - 图片尺寸的倍数 + * `separator` _(可选)_ - 分隔符,默认为 `@` + +相关:[图片](./image.md) + +```stylus +get-retina-src('../img/logo.png', 2) +// => '../img/logo@2x.png' + +get-retina-src('../img/logo.png', 3, '-') +// => '../img/logo-3x.png' +``` diff --git a/doc/image.md b/doc/image.md new file mode 100644 index 0000000..83b5dd7 --- /dev/null +++ b/doc/image.md @@ -0,0 +1,141 @@ +图片 +=== + +图片工具提供的功能需 **依赖本地能力**,所以以下 `src` 要求使用已存在的 **本地** 图片路径。 +如需使用 **远程** 图片,请直接写 CSS。 + +### bg: src, width, height + +设置背景图片。 + +假如本地存在 `logo.png`, `logo@2x.png`, `logo@3x.png` 三种尺寸的图片,只需在 `src` 中填入一倍尺寸的图片路径即可,二倍、三倍尺寸的图片会自动设置妥当。 + + * `src` - 一倍尺寸的图片路径 + * `width` _(可选)_ - 图片宽度。不填或值为 `null` 时,会自动获取一倍尺寸图片的宽度 + * `height` _(可选)_ - 图片高度。不填或值为 `null` 时,会自动获取一倍尺寸图片的高度 + +相关的[全局配置](./setting.md): + + * `$-image-dppx-range` + * `$-image-dppx-separator` + * `$-image-dppx-quality-first` + +```stylus +// 测试环境 +// 存在 "../img/logo.png" 与 "../img/logo@2x.png" 文件 +// 图片 "../img/logo.png" 的宽度为 120px,高度为 80px +.logo + bg: '../img/logo.png' +``` + +生成的 CSS: + +```css +.logo { + background-image: url("../img/logo.png"); + background-size: 120px 80px; + background-repeat: no-repeat; +} +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .logo { + background-image: url("../img/logo@2x.png"); + } +} +``` + +同样是上面的例子,开启了 **质量优先模式** (`$-image-dppx-quality-first`) 后,生成的 CSS: + +```css +.logo { + background-image: url("../img/logo.png"); + background-size: 120px 80px; + background-repeat: no-repeat; +} +@media (min-resolution: 1.5dppx), (min-resolution: 144dpi) { + .logo { + background-image: url("../img/logo@2x.png"); + } +} +``` + +可以看到,在 `dppx` 大于等于 `1.5` 时,就使用了 `@2x` 质量的图片。 + +### ir: src, x, y, width, height + +图片替换。隐藏文字并设置背景图片,可指定背景图片坐标。 + +与 `bg()` 类似,具备 Retina 图片的探测与背景图片的设置能力。 +增加了容器内文字隐藏与 `background-position` 坐标设置的功能。 + + * `src` - 一倍尺寸的图片路径 + * `x` _(可选)_ - + * `y` _(可选)_ - + * `width` _(可选)_ - 图片宽度。不填或值为 `null` 时,会自动获取一倍尺寸图片的宽度 + * `height` _(可选)_ - 图片高度。不填或值为 `null` 时,会自动获取一倍尺寸图片的高度 + +相关的[全局配置](./setting.md): + + * `$-image-dppx-range` + * `$-image-dppx-separator` + * `$-image-dppx-quality-first` + +相关:[排版](./typography.md) + +```stylus +// 测试环境 +// 存在 "../img/logo.png" 与 "../img/logo@2x.png" 文件 +// 图片 "../img/logo.png" 的宽度为 120px,高度为 80px +.logo + ir: '../img/logo.png' +``` + +生成的 CSS: + +```css +.logo { + color: transparent; + font: 0/0 a; + text-shadow: none; + background-image: url("../img/logo.png"); + background-size: 120px 80px; + background-repeat: no-repeat; +} +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .logo { + background-image: url("../img/logo@2x.png"); + } +} +``` + +### bg-dppx: dppx, src, width, height + +根据传入的 **图片尺寸倍数** 与 **图片地址**,获取并计算出所需尺寸,生成相关样式。 + + * `dppx` - 图片的尺寸倍数 + * `src` - 图片路径 + * `width` _(可选)_ - 图片宽度。不填或值为 `null` 时,会计算出所需的图片宽度 + * `height` _(可选)_ - 图片高度。不填或值为 `null` 时,会计算出所需的图片高度 + +```stylus +// 传入 2 倍尺寸的图片,实际宽高为:640px, 88px +.slogan + bg-dppx: 2, '../img/slogan.png' +``` + +转换为 CSS: + +```css +.slogan { + background-image: url("../img/slogan.png"); + background-size: 320px 44px; + background-repeat: no-repeat; +} +``` + +### bg2x: src, width, height + +使用效果参考 `bg-dppx`,它这是 `bg-dppx: 2, src, width, height` 的简写。 + +### bg3x: src, width, height + +使用效果参考 `bg-dppx`,它这是 `bg-dppx: 3, src, width, height` 的简写。 diff --git a/doc/initialize.md b/doc/initialize.md new file mode 100644 index 0000000..db2bb7c --- /dev/null +++ b/doc/initialize.md @@ -0,0 +1,123 @@ +样式初始化 +=== + +由于应用场景的多样化,`rider` 提供了三种样式初始化的方式。请根据你的项目特点,选择最合适的方案。 + +## Normalize + +样式归一化,基于 [`normalize.css`](http://necolas.github.io/normalize.css/) 定制的 Stylus 版本。 + +如果你希望各种元素都有 **可用的默认样式**,并基于此进行开发,那么 `Normalize` 就是为你准备的。这也是社区中 **最流行** 的样式初始化方案。 + +比如,你的内容区域有 ``、`` 标签,即使你不去特意的定义它的样式,也能够得到符合寓意的展现。 + +### normalize() + +对全局样式进行归一化。 + +相关的[全局配置](./setting.md): + + * `$-base-font-size` + * `$-base-font-family` + * `$-code-font-family` + * `$-prevent-text-size-adjust` + * `$-prevent-tap-highlight` + +如有希望调整的配置,请在调用 Mixin 之前进行声明。 + +```stylus +// 修改默认的代码字体 +$-code-font-family = Monaco, Consolas, monospace + +// 进行样式归一化 +normalize() +``` + +### normalize-form() + +归一化表单样式。 + +**注意**:如果已使用 `normalize()` 或 `initialize()` 进行过初始化,请 **不要** 使用这个 Mixin。 + +## Initialize + +以 `CSS reset` 为主,`CSS normalize` 为辅的样式初始化方案。 + +适合设计中各种 **用户界面元素** 均需要 **精确定义** 的使用场景。 + +如果网站的每一部分都是精心设计的,默认样式不可能生效,那么 `Initialize` 给你的 **一张白纸** 会让你的创作过程更省心。 + +### initialize() + +对全局样式进行初始化。 + +相关的[全局配置](./setting.md): + + * `$-base-font-size` + * `$-base-font-family` + * `$-prevent-text-size-adjust` + * `$-prevent-tap-highlight` + +如有希望调整的配置,请在调用 Mixin 之前进行声明。 + +```stylus +// 修改默认的基础字体大小 +$-base-font-size = 14px + +// 进行样式初始化 +initialize() +``` + +## 局部 CSS Reset + +适合用于运行在第三方环境,需要确保 **不影响外部容器样式** 的初始化方案。 + +比如在第三方页面投放的广告、在第三方平台运行的应用等,根据需要对 **特定区域** 进行初始化。 + +注意:在使用了 `normalize()` 或 `initialize()` 的环境中,不推荐使用这些 Mixin。 + +### reset-font() + +重置文字字体、尺寸、样式、垂直对齐方式。 + +```stylus +.ad-slot + reset-font() +``` + +### reset-box-model() + +重置盒模型。处于可访问性考虑,不会重置 `outline`。 + +```stylus +.app-container + reset-box-model() +``` + +### reset-list() + +重置列表样式。应用于 `ul`、`ol` 类型元素。 + +```stylus +.menu-list + reset-list() +``` + +### reset-table() + +重置表格样式。应用于 `table` 类型元素。 + +```stylus +.data-table + reset-table() +``` + +### reset-table-cell() + +初始化单元格样式。应用于 `td`、`th` 类型元素。 + +```stylus +.data-table td + reset-table-cell() +``` + diff --git a/doc/retina.md b/doc/retina.md new file mode 100644 index 0000000..b8f2b44 --- /dev/null +++ b/doc/retina.md @@ -0,0 +1,35 @@ +Retina 支持 +=== + +### +retina(dppx) + +用于限定仅在 Retina 屏幕生效的样式代码,屏幕密度依靠 `dppx` 单位描述。 + + * `dppx` - 每像素包含的点数,默认值为 `1.5`。 + +```stylus +.box + color: #f00 + +retina() + color: #0f0 + +retina(2) + color: #00f +``` + +生成的 CSS: + +```css +.box { + color: #f00; +} +@media (min-resolution: 1.5dppx), (min-resolution: 144dpi) { + .box { + color: #0f0; + } +} +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .box { + color: #00f; + } +} +``` diff --git a/doc/setting.md b/doc/setting.md new file mode 100644 index 0000000..159ca37 --- /dev/null +++ b/doc/setting.md @@ -0,0 +1,89 @@ +# 全局配置 + +`rider` 的 **默认配置** 能够适应大多数场景,但如有需要,我们可以通过 **覆盖全局配置** 对样式工具库进行微调。 + +建议在样式入口文件的 **最前方** 设置全局配置,以确保调用相关方法时能够生效。 + +### $-base-font-size + +用于设置文档的 **基础** 文字大小。**单位转换** 函数就是根据此配置计算的。 + +默认值:`16px` + +相关:[样式初始化](./initialize.md),[单位转换](./unit.md) + +### $-base-font-family + +基础字体族群。 + +默认值:`'Helvetica Neue', Arial, sans-serif` + +相关:[样式初始化](./initialize.md) + +### $-code-font-family + +代码字体族群。 + +默认值:`Menlo, Consolas, monospace` + +相关:[样式初始化](./initialize.md) + +### $-prevent-text-size-adjust + +是否 **阻止** 屏幕翻转时,浏览器缩放字体的行为。 + +默认值:`true` + +相关:[样式初始化](./initialize.md) + +### $-prevent-tap-highlight + +是否 **屏蔽** 移动浏览器中,`a`、`nav` 等标签 **点击触发** 时的高亮效果。 + +默认值:`true` + +相关:[样式初始化](./initialize.md) + +### $-image-dppx-range + +使用图片工具时,探测设定 DPPX 范围内的 Retina 图片。 + +默认值:`(2 3)` + +相关:[图片](./image.md) + +### $-image-dppx-separator + +使用图片工具时,拼装带 DPPX 值的路径所用的分隔符。 + +比如,当该配置为 `@` 时,`./logo.png` 的 `3dppx` 版本图片为 `./logo@3x.png`。 + +默认值:`@` + +相关:[图片](./image.md) + +### $-image-dppx-quality-first + +使用图片工具时,是否启用 **质量优先** 模式。 + +该配置启用时,将为比设定值低 `0.5dppx` 以内的设备,使用质量更高的图片。 + +默认值:`false` + +相关:[图片](./image.md) + +### $-breakpoint-slice + +响应式工具 Breakpoint 所使用的屏幕切片分段。 + +默认值:`0 400px 600px 800px 1050px` + +相关:[响应式工具](./breakpoint.md) + +### $-unit-precision + +单位转换的精度,小数点后保留的位数。 + +默认值:`5` + +相关:[单位转换](./unit.md) diff --git a/doc/shape.md b/doc/shape.md new file mode 100644 index 0000000..9a255f5 --- /dev/null +++ b/doc/shape.md @@ -0,0 +1,85 @@ +形状 +=== + +### size: width, height + +绘制矩形,快速设置容器的 **宽度** 和 **高度**。 + + * `width` - 宽度,默认单位为 `px` + * `height` _(可选)_ - 高度,默认单位为 `px`,留空为绘制正方形 + +```stylus +.square + size: 5em +.rectangle + size: 100 20 +``` + +生成的 CSS: + +```css +.square { + width: 5em; + height: 5em; +} +.rectangle { + width: 100px; + height: 20px; +} +``` + +### circle: width, height + +绘制圆形。 + + * `width` - 宽度,默认单位为 `px` + * `height` _(可选)_ - 高度,默认单位为 `px`,留空为绘制正圆形 + +```stylus +.avatar + circle: 30px +.bubble + circle: 100px 80px +``` + +生成的 CSS: + +```css +.avatar { + border-radius: 30px; + width: 30px; + height: 30px; +} +.bubble { + border-radius: 100px/80px; + width: 100px; + height: 80px; +} +``` + +### triangle: direction, size, color + +绘制三角形。 + + * `direction` - 方向,取值范围为 `top`、`right`、`bottom`、`left` + * `size` - 尺寸 + * `color` - 颜色 + +```stylus +.box:after + // 通常在 :before, :after 选择器下 + // 与 absolute, content 配合使用 + triangle: top 5px #369 +``` + +生成的 CSS: + +```css +.box:after { + width: 0px; + height: 0px; + border-left: 5px solid transparent; + border-right: 5px solid transparent; + border-bottom: 5px solid #369; +} +``` diff --git a/doc/typography.md b/doc/typography.md new file mode 100644 index 0000000..1222892 --- /dev/null +++ b/doc/typography.md @@ -0,0 +1,117 @@ +排版 +=== + +### clearfix() + +清除浮动。 + +参考:[A new micro clearfix hack](http://h5bp.com/q) + +```stylus +.container + clearfix() +``` + +生成的 CSS: + +```css +.container:after, +.container:before { + content: ' '; + display: table; +} +.container:after { + clear: both; +} +``` + +### hide-text() + +隐藏容器内的文字。 + +参考:[Update CSS image replacement technique](https://github.com/h5bp/html5-boilerplate/commit/aa0396eae757c9e03dda4e463fb0d4db5a5f82d7) + +```stylus +.banner + hide-text() +``` + +生成的 CSS: + +```css +.banner { + color: transparent; + font: 0/0 a; + text-shadow: none; +} +``` + +### ellipsis(line) + +溢出文本显示省略号。 + +**多行截断** 仅在 `webkit` 内核下有生效,且要保证容器上下的 `padding` 为 `0`,否则本该被截断的文字会溢出。 + + * `line` _(可选)_ - 想要截断的行数,留空则默认为 **单行截断**。 + +```stylus +.title + ellipsis() +.desc + ellipsis(3) +``` + +生成的 CSS: + +```css +.title { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.desc { + overflow: hidden; + text-overflow: ellipsis; + display: -webkit-box; + -webkit-line-clamp: 3; + -webkit-box-orient: vertical; +} +``` + +### font-face: font-family, font-path, font-weight, font-style + +快速引入本地路径的字体。 + +通过检测 `font-path` 对应的各种 **字体格式** 是否存在,生成最合适的配置。 + +若需要引入远程路径的字体,请直接手写 `@font-face`。 + + * `font-family` - 字体名 + * `font-path` - 字体路径,指字体 **去掉后缀** 之后的部分 + * `font-weight` _(可选)_ - 字重,默认为 `normal` + * `font-style` _(可选)_ - 字体样式,默认为 `normal` + +检测的字体格式有: + + * eot + * woff + * woff2 + * ttf + * svg + +```stylus +// 对应路径下有 ttf, woff 两种格式的字体 +font-face('Open Sans', '../font/open-sans-bold', 700) +``` + +生成的 CSS: + +```css +@font-face { + font-family: 'Open Sans'; + src: url("../font/open-sans-bold.woff") format('woff'), + url("../font/open-sans-bold.ttf") format('truetype'); + font-weight: 700; + font-style: normal; +} +``` diff --git a/doc/unit.md b/doc/unit.md new file mode 100644 index 0000000..e06cd9f --- /dev/null +++ b/doc/unit.md @@ -0,0 +1,64 @@ +单位转换 +=== + +### rem(value) + +将 `value` 转换成单位为 `rem` 的值。 + +`value` 支持以 `px` 或 `rem` 为单位的数值。默认单位为 `px`。 + +相关的[全局配置](./setting.md): + + * `$-base-font-size` + +```stylus +// 当基础字体大小为 16px 时: +.box + font-size: rem(20) + // => font-size: 1.25rem; + font-size: rem(14px) + // => font-size: 0.875rem; + font-size: rem(2rem) + // => font-size: 2rem; +``` + +### px(value) + +将 `value` 转换成单位为 `px` 的值。 + +`value` 支持以 `rem` 或 `px` 为单位的数值。默认单位为 `px`。 + +相关的[全局配置](./setting.md): + + * `$-base-font-size` + +```stylus +.box + width: px(1rem) + // => width: 16px; + width: px(1.5rem) + // => width: 24px; + width: px(20) + // => width: 20px; +``` + +### em(value, upper-value) + +根据继承自上级元素字体大小,将 `value` 转换成单位为 `em` 的值。 + +`value` 支持以 `rem` 或 `px` 为单位的数值。默认单位为 `px`。 +`upper-value` 是手动传入的继承自上级元素的字体大小(默认值:`$-base-font-size`)。 + +相关的[全局配置](./setting.md): + + * `$-base-font-size` + +```stylus +.box + foo: em(20) + // => foo: 1.25em; + foo: em(16, 10) + // => foo: 1.6em; + foo: em(1rem, 10) + // => foo: 1.6em; +``` diff --git a/lib/helpers.js b/lib/helpers.js new file mode 100644 index 0000000..bb46e79 --- /dev/null +++ b/lib/helpers.js @@ -0,0 +1,57 @@ +/** + * @file 帮助函数 + * @author firede(firede@firede.us) + */ + +var path = require('path'); +var utils = require('stylus').utils; + +/** + * 检查文件是否存在 + * + * @param {Object} file 文件路径对象 + * @return {boolean} + */ +exports['file-exists'] = function fileExists(file) { + utils.assertString(file, 'file'); + return !!utils.lookup(file.val, this.paths); +}; + +/** + * 检查是否是Url + * 这里检查的并不严格,主要是为了快速区分path类型 + * + * @param {Object} url Url路径对象 + * @return {boolean} + */ +exports['is-url'] = function isUrl(url) { + utils.assertString(url, 'url'); + + var obj = url.val.match(/^(https?:)?\/\//i); + + return !!obj; +}; + +/** + * 获取添加dppx后缀的图片地址 + * + * @param {Object} src 图片路径对象 + * @param {Object} dppx dppx对象 + * @param {Object} separator 分隔符对象,默认值为 `@` + * @return {string} + */ +exports['get-retina-src'] = function getRetinaSrc(src, dppx, separator) { + utils.assertString(src, 'src'); + utils.assertPresent(dppx, 'dppx'); + + // 校验 dppx 的类型 + if (typeof dppx.val !== 'number') { + throw new Error('TypeError: expected number, but got: ' + dppx); + } + + var originName = src.val; + var extName = path.extname(originName); + var separatorValue = separator ? separator.val : '@'; + + return originName.slice(0, -extName.length) + separatorValue + dppx.val + 'x' + extName; +}; diff --git a/lib/rider.js b/lib/rider.js index e98b1ce..79f04c8 100644 --- a/lib/rider.js +++ b/lib/rider.js @@ -1,14 +1,15 @@ /** - * rider - * + * @file rider * @author firede(firede@firede.us) */ +var helpers = require('./helpers'); /** - * stylus plugin + * stylus 插件 * - * @param {Object} options + * @param {Object=} options 可选参数 + * @param {boolean=} options.implicit 隐式调用 * @return {Function} */ function plugin(options) { @@ -20,12 +21,19 @@ function plugin(options) { } return function (style) { - // include rider + // 包含 rider 的目录 style.include(__dirname); - // implicit import handling + // 定义通过 JavaScript 扩展的函数 + for (var key in helpers) { + if (helpers.hasOwnProperty(key)) { + style.define(key, helpers[key]); + } + } + + // 隐式导入 rider if (implicit) { - style.import('rider'); // jshint ignore: line + style.import('rider'); } }; } diff --git a/lib/rider/animate.styl b/lib/rider/animate.styl index e8a4620..86bbd1d 100644 --- a/lib/rider/animate.styl +++ b/lib/rider/animate.styl @@ -1,8 +1,8 @@ -// animate +// 动画 // // @author firede(firede@firede.us) -// @desc ported from Animate.css v3 -// @see http://daneden.github.io/animate.css/ +// @desc ported from Animate.css v3.2.6 +// @see http://daneden.github.io/animate.css animate($name, $duration = 1s, $fill-mode = both) @@ -17,8 +17,12 @@ animate($name, $duration = 1s, $fill-mode = both) animation-duration: $duration animation-fill-mode: $fill-mode - // process special animation - if $name in (flip flipInX flipInY flipOutX flipOutY) + // 处理特殊动画 + if $name == bounce + transform-origin: center bottom + if $anme == flip + backface-visibility: visible + if $name in (flipInX flipInY flipOutX flipOutY) backface-visibility: visible !important if $name == lightSpeedIn animation-timing-function: ease-out @@ -26,4 +30,3 @@ animate($name, $duration = 1s, $fill-mode = both) animation-timing-function: ease-in if $name == swing transform-origin: top center - diff --git a/lib/rider/animate/bounce.styl b/lib/rider/animate/bounce.styl index 54c6a60..8052dfa 100644 --- a/lib/rider/animate/bounce.styl +++ b/lib/rider/animate/bounce.styl @@ -1,7 +1,12 @@ @keyframes bounce - 0%, 20%, 50%, 80%, 100% - transform: translateY(0) - 40% - transform: translateY(-30px) - 60% - transform: translateY(-15px) + 0%, 20%, 53%, 80%, 100% + transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000) + transform: translate3d(0, 0, 0) + 40%, 43% + transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060) + transform: translate3d(0, -30px, 0) + 70% + transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060) + transform: translate3d(0, -15px, 0) + 90% + transform: translate3d(0, -4px, 0) diff --git a/lib/rider/animate/bounceIn.styl b/lib/rider/animate/bounceIn.styl index d6726c9..77008cb 100644 --- a/lib/rider/animate/bounceIn.styl +++ b/lib/rider/animate/bounceIn.styl @@ -1,12 +1,18 @@ @keyframes bounceIn + 0%, 20%, 40%, 60%, 80%, 100% + transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000) 0% opacity: 0 - transform: scale(.3) - 50% + transform: scale3d(.3, .3, .3) + 20% + transform: scale3d(1.1, 1.1, 1.1) + 40% + transform: scale3d(.9, .9, .9) + 60% opacity: 1 - transform: scale(1.05) - 70% - transform: scale(.9) + transform: scale3d(1.03, 1.03, 1.03) + 80% + transform: scale3d(.97, .97, .97) 100% opacity: 1 - transform: scale(1) + transform: scale3d(1, 1, 1) diff --git a/lib/rider/animate/bounceInDown.styl b/lib/rider/animate/bounceInDown.styl index 3f1735f..f5c9e7c 100644 --- a/lib/rider/animate/bounceInDown.styl +++ b/lib/rider/animate/bounceInDown.styl @@ -1,11 +1,15 @@ @keyframes bounceInDown + 0%, 60%, 75%, 90%, 100% + transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000) 0% opacity: 0 - transform: translateY(-2000px) + transform: translate3d(0, -3000px, 0) 60% opacity: 1 - transform: translateY(30px) - 80% - transform: translateY(-10px) + transform: translate3d(0, 25px, 0) + 75% + transform: translate3d(0, -10px, 0) + 90% + transform: translate3d(0, 5px, 0) 100% - transform: translateY(0) + transform: none diff --git a/lib/rider/animate/bounceInLeft.styl b/lib/rider/animate/bounceInLeft.styl index d8d94fb..9517891 100644 --- a/lib/rider/animate/bounceInLeft.styl +++ b/lib/rider/animate/bounceInLeft.styl @@ -1,11 +1,15 @@ @keyframes bounceInLeft + 0%, 60%, 75%, 90%, 100% + transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000) 0% opacity: 0 - transform: translateX(-2000px) + transform: translate3d(-3000px, 0, 0) 60% opacity: 1 - transform: translateX(30px) - 80% - transform: translateX(-10px) + transform: translate3d(25px, 0, 0) + 75% + transform: translate3d(-10px, 0, 0) + 90% + transform: translate3d(5px, 0, 0) 100% - transform: translateX(0) + transform: none diff --git a/lib/rider/animate/bounceInRight.styl b/lib/rider/animate/bounceInRight.styl index bd25a79..2b7d24d 100644 --- a/lib/rider/animate/bounceInRight.styl +++ b/lib/rider/animate/bounceInRight.styl @@ -1,11 +1,15 @@ @keyframes bounceInRight + 0%, 60%, 75%, 90%, 100% + transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000) 0% opacity: 0 - transform: translateX(2000px) + transform: translate3d(3000px, 0, 0) 60% opacity: 1 - transform: translateX(-30px) - 80% - transform: translateX(10px) + transform: translate3d(-25px, 0, 0) + 75% + transform: translate3d(10px, 0, 0) + 90% + transform: translate3d(-5px, 0, 0) 100% - transform: translateX(0) + transform: none diff --git a/lib/rider/animate/bounceInUp.styl b/lib/rider/animate/bounceInUp.styl index e6f597d..32fe373 100644 --- a/lib/rider/animate/bounceInUp.styl +++ b/lib/rider/animate/bounceInUp.styl @@ -1,11 +1,15 @@ @keyframes bounceInUp + 0%, 60%, 75%, 90%, 100% + transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000) 0% opacity: 0 - transform: translateY(2000px) + transform: translate3d(0, 3000px, 0) 60% opacity: 1 - transform: translateY(-30px) - 80% - transform: translateY(10px) + transform: translate3d(0, -20px, 0) + 75% + transform: translate3d(0, 10px, 0) + 90% + transform: translate3d(0, -5px, 0) 100% - transform: translateY(0) + transform: translate3d(0, 0, 0) diff --git a/lib/rider/animate/bounceOut.styl b/lib/rider/animate/bounceOut.styl index 0113344..5b34b2a 100644 --- a/lib/rider/animate/bounceOut.styl +++ b/lib/rider/animate/bounceOut.styl @@ -1,11 +1,9 @@ @keyframes bounceOut - 0% - transform: scale(1) - 25% - transform: scale(.95) - 50% + 20% + transform: scale3d(.9, .9, .9) + 50%, 55% opacity: 1 - transform: scale(1.1) + transform: scale3d(1.1, 1.1, 1.1) 100% opacity: 0 - transform: scale(.3) + transform: scale3d(.3, .3, .3) diff --git a/lib/rider/animate/bounceOutDown.styl b/lib/rider/animate/bounceOutDown.styl index 8b577a9..07af340 100644 --- a/lib/rider/animate/bounceOutDown.styl +++ b/lib/rider/animate/bounceOutDown.styl @@ -1,9 +1,9 @@ @keyframes bounceOutDown - 0% - transform: translateY(0) 20% + transform: translate3d(0, 10px, 0) + 40%, 45% opacity: 1 - transform: translateY(-20px) + transform: translate3d(0, -20px, 0) 100% opacity: 0 - transform: translateY(2000px) + transform: translate3d(0, 2000px, 0) diff --git a/lib/rider/animate/bounceOutLeft.styl b/lib/rider/animate/bounceOutLeft.styl index f2e6bb1..9a7de10 100644 --- a/lib/rider/animate/bounceOutLeft.styl +++ b/lib/rider/animate/bounceOutLeft.styl @@ -1,9 +1,7 @@ @keyframes bounceOutLeft - 0% - transform: translateX(0) 20% opacity: 1 - transform: translateX(20px) + transform: translate3d(20px, 0, 0) 100% opacity: 0 - transform: translateX(-2000px) + transform: translate3d(-2000px, 0, 0) diff --git a/lib/rider/animate/bounceOutRight.styl b/lib/rider/animate/bounceOutRight.styl index b67b53e..5fb3979 100644 --- a/lib/rider/animate/bounceOutRight.styl +++ b/lib/rider/animate/bounceOutRight.styl @@ -1,9 +1,7 @@ @keyframes bounceOutRight - 0% - transform: translateX(0) 20% opacity: 1 - transform: translateX(-20px) + transform: translate3d(-20px, 0, 0) 100% opacity: 0 - transform: translateX(2000px) + transform: translate3d(2000px, 0, 0) diff --git a/lib/rider/animate/bounceOutUp.styl b/lib/rider/animate/bounceOutUp.styl index f5616e0..1b4d12d 100644 --- a/lib/rider/animate/bounceOutUp.styl +++ b/lib/rider/animate/bounceOutUp.styl @@ -1,9 +1,9 @@ @keyframes bounceOutUp - 0% - transform: translateY(0) 20% + transform: translate3d(0, -10px, 0) + 40%, 45% opacity: 1 - transform: translateY(20px) + transform: translate3d(0, 20px, 0) 100% opacity: 0 - transform: translateY(-2000px) + transform: translate3d(0, -2000px, 0) diff --git a/lib/rider/animate/fadeInDown.styl b/lib/rider/animate/fadeInDown.styl index c33a8a3..11199da 100644 --- a/lib/rider/animate/fadeInDown.styl +++ b/lib/rider/animate/fadeInDown.styl @@ -1,7 +1,7 @@ @keyframes fadeInDown 0% opacity: 0 - transform: translateY(-20px) + transform: translate3d(0, -100%, 0) 100% opacity: 1 - transform: translateY(0) + transform: none diff --git a/lib/rider/animate/fadeInDownBig.styl b/lib/rider/animate/fadeInDownBig.styl new file mode 100644 index 0000000..97fb173 --- /dev/null +++ b/lib/rider/animate/fadeInDownBig.styl @@ -0,0 +1,7 @@ +@keyframes fadeInDownBig + 0% + opacity: 0 + transform: translate3d(0, -2000px, 0) + 100% + opacity: 1 + transform: none diff --git a/lib/rider/animate/fadeInLeft.styl b/lib/rider/animate/fadeInLeft.styl index 34fd2be..fd8c4e2 100644 --- a/lib/rider/animate/fadeInLeft.styl +++ b/lib/rider/animate/fadeInLeft.styl @@ -1,7 +1,7 @@ @keyframes fadeInLeft 0% opacity: 0 - transform: translateX(-20px) + transform: translate3d(-100%, 0, 0) 100% opacity: 1 - transform: translateX(0) + transform: none diff --git a/lib/rider/animate/fadeInLeftBig.styl b/lib/rider/animate/fadeInLeftBig.styl new file mode 100644 index 0000000..b106a62 --- /dev/null +++ b/lib/rider/animate/fadeInLeftBig.styl @@ -0,0 +1,7 @@ +@keyframes fadeInLeftBig + 0% + opacity: 0 + transform: translate3d(-2000px, 0, 0) + 100% + opacity: 1 + transform: none diff --git a/lib/rider/animate/fadeInRight.styl b/lib/rider/animate/fadeInRight.styl index 9ab65bf..e40a546 100644 --- a/lib/rider/animate/fadeInRight.styl +++ b/lib/rider/animate/fadeInRight.styl @@ -1,7 +1,7 @@ @keyframes fadeInRight 0% opacity: 0 - transform: translateX(20px) + transform: translate3d(100%, 0, 0) 100% opacity: 1 - transform: translateX(0) + transform: none diff --git a/lib/rider/animate/fadeInRightBig.styl b/lib/rider/animate/fadeInRightBig.styl new file mode 100644 index 0000000..243af09 --- /dev/null +++ b/lib/rider/animate/fadeInRightBig.styl @@ -0,0 +1,7 @@ +@keyframes fadeInRightBig + 0% + opacity: 0 + transform: translate3d(2000px, 0, 0) + 100% + opacity: 1 + transform: none diff --git a/lib/rider/animate/fadeInUp.styl b/lib/rider/animate/fadeInUp.styl index 9b499b5..ad4f1fe 100644 --- a/lib/rider/animate/fadeInUp.styl +++ b/lib/rider/animate/fadeInUp.styl @@ -1,7 +1,7 @@ @keyframes fadeInUp 0% opacity: 0 - transform: translateY(20px) + transform: translate3d(0, 100%, 0) 100% opacity: 1 - transform: translateY(0) + transform: none diff --git a/lib/rider/animate/fadeInUpBig.styl b/lib/rider/animate/fadeInUpBig.styl new file mode 100644 index 0000000..fd19b18 --- /dev/null +++ b/lib/rider/animate/fadeInUpBig.styl @@ -0,0 +1,7 @@ +@keyframes fadeInUpBig + 0% + opacity: 0 + transform: translate3d(0, 2000px, 0) + 100% + opacity: 1 + transform: none diff --git a/lib/rider/animate/fadeOutDown.styl b/lib/rider/animate/fadeOutDown.styl index 0ed0fe2..dacaf81 100644 --- a/lib/rider/animate/fadeOutDown.styl +++ b/lib/rider/animate/fadeOutDown.styl @@ -1,7 +1,6 @@ @keyframes fadeOutDown 0% opacity: 1 - transform: translateY(0) 100% opacity: 0 - transform: translateY(20px) + transform: translate3d(0, 100%, 0) diff --git a/lib/rider/animate/fadeOutDownBig.styl b/lib/rider/animate/fadeOutDownBig.styl new file mode 100644 index 0000000..633442b --- /dev/null +++ b/lib/rider/animate/fadeOutDownBig.styl @@ -0,0 +1,6 @@ +@keyframes fadeOutDownBig + 0% + opacity: 1 + 100% + opacity: 0 + transform: translate3d(0, 2000px, 0) diff --git a/lib/rider/animate/fadeOutLeft.styl b/lib/rider/animate/fadeOutLeft.styl index d28777a..cd26172 100644 --- a/lib/rider/animate/fadeOutLeft.styl +++ b/lib/rider/animate/fadeOutLeft.styl @@ -1,7 +1,6 @@ @keyframes fadeOutLeft 0% opacity: 1 - transform: translateX(0) 100% opacity: 0 - transform: translateX(-20px) + transform: translate3d(-100%, 0, 0) diff --git a/lib/rider/animate/fadeOutLeftBig.styl b/lib/rider/animate/fadeOutLeftBig.styl new file mode 100644 index 0000000..ab6e2c6 --- /dev/null +++ b/lib/rider/animate/fadeOutLeftBig.styl @@ -0,0 +1,6 @@ +@keyframes fadeOutLeftBig + 0% + opacity: 1 + 100% + opacity: 0 + transform: translate3d(-2000px, 0, 0) diff --git a/lib/rider/animate/fadeOutRight.styl b/lib/rider/animate/fadeOutRight.styl index aae83ae..3175872 100644 --- a/lib/rider/animate/fadeOutRight.styl +++ b/lib/rider/animate/fadeOutRight.styl @@ -1,7 +1,6 @@ @keyframes fadeOutRight 0% opacity: 1 - transform: translateX(0) 100% opacity: 0 - transform: translateX(20px) + transform: translate3d(100%, 0, 0) diff --git a/lib/rider/animate/fadeOutRightBig.styl b/lib/rider/animate/fadeOutRightBig.styl new file mode 100644 index 0000000..32b8563 --- /dev/null +++ b/lib/rider/animate/fadeOutRightBig.styl @@ -0,0 +1,6 @@ +@keyframes fadeOutRightBig + 0% + opacity: 1 + 100% + opacity: 0 + transform: translate3d(2000px, 0, 0) diff --git a/lib/rider/animate/fadeOutUp.styl b/lib/rider/animate/fadeOutUp.styl index 33c9664..7840b89 100644 --- a/lib/rider/animate/fadeOutUp.styl +++ b/lib/rider/animate/fadeOutUp.styl @@ -1,7 +1,6 @@ @keyframes fadeOutUp 0% opacity: 1 - transform: translateY(0) 100% opacity: 0 - transform: translateY(-20px) + transform: translate3d(0, -100%, 0) diff --git a/lib/rider/animate/fadeOutUpBig.styl b/lib/rider/animate/fadeOutUpBig.styl new file mode 100644 index 0000000..c8bc82b --- /dev/null +++ b/lib/rider/animate/fadeOutUpBig.styl @@ -0,0 +1,6 @@ +@keyframes fadeOutUpBig + 0% + opacity: 1 + 100% + opacity: 0 + transform: translate3d(0, -2000px, 0) diff --git a/lib/rider/animate/flip.styl b/lib/rider/animate/flip.styl index 329b74c..56f4c52 100644 --- a/lib/rider/animate/flip.styl +++ b/lib/rider/animate/flip.styl @@ -1,16 +1,16 @@ @keyframes flip 0% - transform: perspective(400px) translateZ(0) rotateY(0) scale(1) + transform: perspective(400px) rotate3d(0, 1, 0, -360deg) animation-timing-function: ease-out 40% - transform: perspective(400px) translateZ(150px) rotateY(170deg) scale(1) + transform: perspective(400px) translate3d(0, 0, 150px) rotate3d(0, 1, 0, -190deg) animation-timing-function: ease-out 50% - transform: perspective(400px) translateZ(150px) rotateY(190deg) scale(1) + transform: perspective(400px) translate3d(0, 0, 150px) rotate3d(0, 1, 0, -170deg) animation-timing-function: ease-in 80% - transform: perspective(400px) translateZ(0) rotateY(360deg) scale(.95) + transform: perspective(400px) scale3d(.95, .95, .95) animation-timing-function: ease-in 100% - transform: perspective(400px) translateZ(0) rotateY(360deg) scale(1) + transform: perspective(400px) animation-timing-function: ease-in diff --git a/lib/rider/animate/flipInX.styl b/lib/rider/animate/flipInX.styl index c9c2cc4..4a825a4 100644 --- a/lib/rider/animate/flipInX.styl +++ b/lib/rider/animate/flipInX.styl @@ -1,11 +1,15 @@ @keyframes flipInX 0% - transform: perspective(400px) rotateX(90deg) + transform: perspective(400px) rotate3d(1, 0, 0, 90deg) + transition-timing-function: ease-in opacity: 0 40% - transform: perspective(400px) rotateX(-10deg) - 70% - transform: perspective(400px) rotateX(10deg) - 100% - transform: perspective(400px) rotateX(0deg) + transform: perspective(400px) rotate3d(1, 0, 0, -20deg) + transition-timing-function: ease-in + 60% + transform: perspective(400px) rotate3d(1, 0, 0, 10deg) opacity: 1 + 80% + transform: perspective(400px) rotate3d(1, 0, 0, -5deg) + 100% + transform: perspective(400px) diff --git a/lib/rider/animate/flipInY.styl b/lib/rider/animate/flipInY.styl index 31e16f6..68ae219 100644 --- a/lib/rider/animate/flipInY.styl +++ b/lib/rider/animate/flipInY.styl @@ -1,11 +1,15 @@ @keyframes flipInY 0% - transform: perspective(400px) rotateY(90deg) + transform: perspective(400px) rotate3d(0, 1, 0, 90deg) + transition-timing-function: ease-in opacity: 0 40% - transform: perspective(400px) rotateY(-10deg) - 70% - transform: perspective(400px) rotateY(10deg) - 100% - transform: perspective(400px) rotateY(0deg) + transform: perspective(400px) rotate3d(0, 1, 0, -20deg) + transition-timing-function: ease-in + 60% + transform: perspective(400px) rotate3d(0, 1, 0, 10deg) opacity: 1 + 80% + transform: perspective(400px) rotate3d(0, 1, 0, -5deg) + 100% + transform: perspective(400px) diff --git a/lib/rider/animate/flipOutX.styl b/lib/rider/animate/flipOutX.styl index 1fbbd2b..43db172 100644 --- a/lib/rider/animate/flipOutX.styl +++ b/lib/rider/animate/flipOutX.styl @@ -1,7 +1,9 @@ @keyframes flipOutX 0% - transform: perspective(400px) rotateX(0deg) + transform: perspective(400px) + 30% + transform: perspective(400px) rotate3d(1, 0, 0, -20deg) opacity: 1 100% - transform: perspective(400px) rotateX(90deg) + transform: perspective(400px) rotate3d(1, 0, 0, 90deg) opacity: 0 diff --git a/lib/rider/animate/flipOutY.styl b/lib/rider/animate/flipOutY.styl index 229d924..5379c27 100644 --- a/lib/rider/animate/flipOutY.styl +++ b/lib/rider/animate/flipOutY.styl @@ -1,7 +1,9 @@ @keyframes flipOutY 0% - transform: perspective(400px) rotateY(0deg) + transform: perspective(400px) + 30% + transform: perspective(400px) rotate3d(0, 1, 0, -15deg) opacity: 1 100% - transform: perspective(400px) rotateY(90deg) + transform: perspective(400px) rotate3d(0, 1, 0, 90deg) opacity: 0 diff --git a/lib/rider/animate/hinge.styl b/lib/rider/animate/hinge.styl index 288d18e..260a316 100644 --- a/lib/rider/animate/hinge.styl +++ b/lib/rider/animate/hinge.styl @@ -1,21 +1,16 @@ @keyframes hinge 0% - transform: rotate(0) transform-origin: top left animation-timing-function: ease-in-out 20%, 60% - transform: rotate(80deg) + transform: rotate3d(0, 0, 1, 80deg) transform-origin: top left animation-timing-function: ease-in-out - 40% - transform: rotate(60deg) + 40%, 80% + transform: rotate3d(0, 0, 1, 60deg) transform-origin: top left animation-timing-function: ease-in-out - 80% - transform: rotate(60deg) translateY(0) opacity: 1 - transform-origin: top left - animation-timing-function: ease-in-out 100% - transform: translateY(700px) + transform: translate3d(0, 700px, 0) opacity: 0 diff --git a/lib/rider/animate/lightSpeedIn.styl b/lib/rider/animate/lightSpeedIn.styl index 7401a67..f530d07 100644 --- a/lib/rider/animate/lightSpeedIn.styl +++ b/lib/rider/animate/lightSpeedIn.styl @@ -1,13 +1,13 @@ @keyframes lightSpeedIn 0% - transform: translateX(100%) skewX(-30deg) + transform: translate3d(100%, 0, 0) skewX(-30deg) opacity: 0 60% - transform: translateX(-20%) skewX(30deg) + transform: skewX(20deg) opacity: 1 80% - transform: translateX(0%) skewX(-15deg) + transform: skewX(-5deg) opacity: 1 100% - transform: translateX(0%) skewX(0deg) + transform: none opacity: 1 diff --git a/lib/rider/animate/lightSpeedOut.styl b/lib/rider/animate/lightSpeedOut.styl index badc263..dfeb77f 100644 --- a/lib/rider/animate/lightSpeedOut.styl +++ b/lib/rider/animate/lightSpeedOut.styl @@ -1,7 +1,6 @@ @keyframes lightSpeedOut 0% - transform: translateX(0%) skewX(0deg) opacity: 1 100% - transform: translateX(100%) skewX(-30deg) + transform: translate3d(100%, 0, 0) skewX(30deg) opacity: 0 diff --git a/lib/rider/animate/pulse.styl b/lib/rider/animate/pulse.styl index b1f3ae7..40f7fb0 100644 --- a/lib/rider/animate/pulse.styl +++ b/lib/rider/animate/pulse.styl @@ -2,8 +2,8 @@ @keyframes pulse 0% - transform: scale(1) + transform: scale3d(1, 1, 1) 50% - transform: scale(1.1) + transform: scale3d(1.05, 1.05, 1.05) 100% - transform: scale(1) + transform: scale3d(1, 1, 1) diff --git a/lib/rider/animate/rollIn.styl b/lib/rider/animate/rollIn.styl index b4cea9c..ff8c24d 100644 --- a/lib/rider/animate/rollIn.styl +++ b/lib/rider/animate/rollIn.styl @@ -3,7 +3,7 @@ @keyframes rollIn 0% opacity: 0 - transform: translateX(-100%) rotate(-120deg) + transform: translate3d(-100%, 0, 0) rotate3d(0, 0, 1, -120deg) 100% opacity: 1 - transform: translateX(0px) rotate(0deg) + transform: none diff --git a/lib/rider/animate/rollOut.styl b/lib/rider/animate/rollOut.styl index 14f396d..a3fddd3 100644 --- a/lib/rider/animate/rollOut.styl +++ b/lib/rider/animate/rollOut.styl @@ -3,7 +3,6 @@ @keyframes rollOut 0% opacity: 1 - transform: translateX(0px) rotate(0deg) 100% opacity: 0 - transform: translateX(100%) rotate(120deg) + transform: translate3d(100%, 0, 0) rotate3d(0, 0, 1, 120deg) diff --git a/lib/rider/animate/rotateIn.styl b/lib/rider/animate/rotateIn.styl index 4212fbc..42bf3c5 100644 --- a/lib/rider/animate/rotateIn.styl +++ b/lib/rider/animate/rotateIn.styl @@ -1,9 +1,9 @@ @keyframes rotateIn 0% - transform-origin: center center - transform: rotate(-200deg) + transform-origin: center + transform: rotate3d(0, 0, 1, -200deg) opacity: 0 100% - transform-origin: center center - transform: rotate(0) + transform-origin: center + transform: none opacity: 1 diff --git a/lib/rider/animate/rotateInDownLeft.styl b/lib/rider/animate/rotateInDownLeft.styl index 4c61174..f8aec83 100644 --- a/lib/rider/animate/rotateInDownLeft.styl +++ b/lib/rider/animate/rotateInDownLeft.styl @@ -1,9 +1,9 @@ @keyframes rotateInDownLeft 0% transform-origin: left bottom - transform: rotate(-90deg) + transform: rotate3d(0, 0, 1, -45deg) opacity: 0 100% transform-origin: left bottom - transform: rotate(0) + transform: none opacity: 1 diff --git a/lib/rider/animate/rotateInDownRight.styl b/lib/rider/animate/rotateInDownRight.styl index 2100eb8..d1fdd46 100644 --- a/lib/rider/animate/rotateInDownRight.styl +++ b/lib/rider/animate/rotateInDownRight.styl @@ -1,9 +1,9 @@ @keyframes rotateInDownRight 0% transform-origin: right bottom - transform: rotate(90deg) + transform: rotate3d(0, 0, 1, 45deg) opacity: 0 100% transform-origin: right bottom - transform: rotate(0) + transform: none opacity: 1 diff --git a/lib/rider/animate/rotateInUpLeft.styl b/lib/rider/animate/rotateInUpLeft.styl index e804ada..834b6a2 100644 --- a/lib/rider/animate/rotateInUpLeft.styl +++ b/lib/rider/animate/rotateInUpLeft.styl @@ -1,9 +1,9 @@ @keyframes rotateInUpLeft 0% transform-origin: left bottom - transform: rotate(90deg) + transform: rotate3d(0, 0, 1, 45deg) opacity: 0 100% transform-origin: left bottom - transform: rotate(0) + transform: none opacity: 1 diff --git a/lib/rider/animate/rotateInUpRight.styl b/lib/rider/animate/rotateInUpRight.styl index 3ad672d..b6cdea6 100644 --- a/lib/rider/animate/rotateInUpRight.styl +++ b/lib/rider/animate/rotateInUpRight.styl @@ -1,9 +1,9 @@ @keyframes rotateInUpRight 0% transform-origin: right bottom - transform: rotate(-90deg) + transform: rotate3d(0, 0, 1, -90deg) opacity: 0 100% transform-origin: right bottom - transform: rotate(0) + transform: none opacity: 1 diff --git a/lib/rider/animate/rotateOut.styl b/lib/rider/animate/rotateOut.styl index 922a7a3..abeb091 100644 --- a/lib/rider/animate/rotateOut.styl +++ b/lib/rider/animate/rotateOut.styl @@ -1,9 +1,8 @@ @keyframes rotateOut 0% - transform-origin: center center - transform: rotate(0) + transform-origin: center opacity: 1 100% - transform-origin: center center - transform: rotate(200deg) + transform-origin: center + transform: rotate3d(0, 0, 1, 200deg) opacity: 0 diff --git a/lib/rider/animate/rotateOutDownLeft.styl b/lib/rider/animate/rotateOutDownLeft.styl index eeaef83..0ae385d 100644 --- a/lib/rider/animate/rotateOutDownLeft.styl +++ b/lib/rider/animate/rotateOutDownLeft.styl @@ -1,9 +1,8 @@ @keyframes rotateOutDownLeft 0% transform-origin: left bottom - transform: rotate(0) opacity: 1 100% transform-origin: left bottom - transform: rotate(90deg) + transform: rotate3d(0, 0, 1, 45deg) opacity: 0 diff --git a/lib/rider/animate/rotateOutDownRight.styl b/lib/rider/animate/rotateOutDownRight.styl index edeb79c..63428d1 100644 --- a/lib/rider/animate/rotateOutDownRight.styl +++ b/lib/rider/animate/rotateOutDownRight.styl @@ -1,9 +1,8 @@ @keyframes rotateOutDownRight 0% transform-origin: right bottom - transform: rotate(0) opacity: 1 100% transform-origin: right bottom - transform: rotate(-90deg) + transform: rotate3d(0, 0, 1, -45deg) opacity: 0 diff --git a/lib/rider/animate/rotateOutUpLeft.styl b/lib/rider/animate/rotateOutUpLeft.styl index 665d9e0..0cee4d5 100644 --- a/lib/rider/animate/rotateOutUpLeft.styl +++ b/lib/rider/animate/rotateOutUpLeft.styl @@ -1,9 +1,8 @@ @keyframes rotateOutUpLeft 0% transform-origin: left bottom - transform: rotate(0) opacity: 1 100% transform-origin: left bottom - transform: rotate(-90deg) + transform: rotate3d(0, 0, 1, -45deg) opacity: 0 diff --git a/lib/rider/animate/rotateOutUpRight.styl b/lib/rider/animate/rotateOutUpRight.styl index 19463cb..fd642e6 100644 --- a/lib/rider/animate/rotateOutUpRight.styl +++ b/lib/rider/animate/rotateOutUpRight.styl @@ -1,9 +1,8 @@ @keyframes rotateOutUpRight 0% transform-origin: right bottom - transform: rotate(0) opacity: 1 100% transform-origin: right bottom - transform: rotate(90deg) + transform: rotate3d(0, 0, 1, 90deg) opacity: 0 diff --git a/lib/rider/animate/rubberBand.styl b/lib/rider/animate/rubberBand.styl index fa755f2..488b516 100644 --- a/lib/rider/animate/rubberBand.styl +++ b/lib/rider/animate/rubberBand.styl @@ -1,11 +1,15 @@ @keyframes rubberBand 0% - transform: scale(1) + transform: scale3d(1, 1, 1) 30% - transform: scaleX(1.25) scaleY(0.75) + transform: scale3d(1.25, 0.75, 1) 40% - transform: scaleX(0.75) scaleY(1.25) - 60% - transform: scaleX(1.15) scaleY(0.85) + transform: scale3d(0.75, 1.25, 1) + 50% + transform: scale3d(1.15, 0.85, 1) + 65% + transform: scale3d(.95, 1.05, 1) + 75% + transform: scale3d(1.05, .95, 1) 100% - transform: scale(1) + transform: scale3d(1, 1, 1) diff --git a/lib/rider/animate/shake.styl b/lib/rider/animate/shake.styl index a273a4d..aded40a 100644 --- a/lib/rider/animate/shake.styl +++ b/lib/rider/animate/shake.styl @@ -1,7 +1,7 @@ @keyframes shake 0%, 100% - transform: translateX(0) + transform: translate3d(0, 0, 0) 10%, 30%, 50%, 70%, 90% - transform: translateX(-10px) + transform: translate3d(-10px, 0, 0) 20%, 40%, 60%, 80% - transform: translateX(10px) + transform: translate3d(10px, 0, 0) diff --git a/lib/rider/animate/slideInDown.styl b/lib/rider/animate/slideInDown.styl index 155f058..ba4d24f 100644 --- a/lib/rider/animate/slideInDown.styl +++ b/lib/rider/animate/slideInDown.styl @@ -1,6 +1,6 @@ @keyframes slideInDown 0% - opacity: 0 - transform: translateY(-2000px) + transform: translate3d(0, -100%, 0) + visibility: visible 100% - transform: translateY(0) + transform: translate3d(0, 0, 0) diff --git a/lib/rider/animate/slideInLeft.styl b/lib/rider/animate/slideInLeft.styl index e6032a1..7db494a 100644 --- a/lib/rider/animate/slideInLeft.styl +++ b/lib/rider/animate/slideInLeft.styl @@ -1,6 +1,6 @@ @keyframes slideInLeft 0% - opacity: 0 - transform: translateX(-2000px) + transform: translate3d(-100%, 0, 0) + visibility: visible 100% - transform: translateX(0) + transform: translate3d(0, 0, 0) diff --git a/lib/rider/animate/slideInRight.styl b/lib/rider/animate/slideInRight.styl index 09a0970..1afeb49 100644 --- a/lib/rider/animate/slideInRight.styl +++ b/lib/rider/animate/slideInRight.styl @@ -1,6 +1,6 @@ @keyframes slideInRight 0% - opacity: 0 - transform: translateX(2000px) + transform: translate3d(100%, 0, 0) + visibility: visible 100% - transform: translateX(0) + transform: translate3d(0, 0, 0) diff --git a/lib/rider/animate/slideInUp.styl b/lib/rider/animate/slideInUp.styl index 9cf80f8..688abe7 100644 --- a/lib/rider/animate/slideInUp.styl +++ b/lib/rider/animate/slideInUp.styl @@ -1,7 +1,6 @@ @keyframes slideInUp 0% - opacity: 0 - transform: translateY(2000px) + transform: translate3d(0, 100%, 0) + visibility: visible 100% - opacity: 1 - transform: translateX(0) + transform: translate3d(0, 0, 0) diff --git a/lib/rider/animate/slideOutDown.styl b/lib/rider/animate/slideOutDown.styl index f2e09eb..527f0d4 100644 --- a/lib/rider/animate/slideOutDown.styl +++ b/lib/rider/animate/slideOutDown.styl @@ -1,6 +1,6 @@ @keyframes slideOutDown 0% - transform: translateX(0) + transform: translate3d(0, 0, 0) 100% - opacity: 0 - transform: translateY(2000px) + visibility: hidden + transform: translate3d(0, 100%, 0) diff --git a/lib/rider/animate/slideOutLeft.styl b/lib/rider/animate/slideOutLeft.styl index d9072dd..aebb13f 100644 --- a/lib/rider/animate/slideOutLeft.styl +++ b/lib/rider/animate/slideOutLeft.styl @@ -1,6 +1,6 @@ @keyframes slideOutLeft 0% - transform: translateX(0) + transform: translate3d(0, 0, 0) 100% - opacity: 0 - transform: translateX(-2000px) + visibility: hidden + transform: translate3d(-100%, 0, 0) diff --git a/lib/rider/animate/slideOutRight.styl b/lib/rider/animate/slideOutRight.styl index 4f7dcfc..263edc4 100644 --- a/lib/rider/animate/slideOutRight.styl +++ b/lib/rider/animate/slideOutRight.styl @@ -1,6 +1,6 @@ @keyframes slideOutRight 0% - transform: translateX(0) + transform: translate3d(0, 0, 0) 100% - opacity: 0 - transform: translateX(2000px) + visibility: hidden + transform: translate3d(100%, 0, 0) diff --git a/lib/rider/animate/slideOutUp.styl b/lib/rider/animate/slideOutUp.styl index f117291..10372ab 100644 --- a/lib/rider/animate/slideOutUp.styl +++ b/lib/rider/animate/slideOutUp.styl @@ -1,6 +1,6 @@ @keyframes slideOutUp 0% - transform: translateY(0) + transform: translate3d(0, 0, 0) 100% - opacity: 0 - transform: translateY(-2000px) + visibility: hidden + transform: translate3d(0, -100%, 0) diff --git a/lib/rider/animate/swing.styl b/lib/rider/animate/swing.styl index 612b96e..d23bea4 100644 --- a/lib/rider/animate/swing.styl +++ b/lib/rider/animate/swing.styl @@ -1,11 +1,11 @@ @keyframes swing 20% - transform: rotate(15deg) + transform: rotate3d(0, 0, 1, 15deg) 40% - transform: rotate(-10deg) + transform: rotate3d(0, 0, 1, -10deg) 60% - transform: rotate(5deg) + transform: rotate3d(0, 0, 1, 5deg) 80% - transform: rotate(-5deg) + transform: rotate3d(0, 0, 1, -5deg) 100% - transform: rotate(0deg) + transform: rotate3d(0, 0, 1, 0deg) diff --git a/lib/rider/animate/tada.styl b/lib/rider/animate/tada.styl index b36b7a2..74e3da1 100644 --- a/lib/rider/animate/tada.styl +++ b/lib/rider/animate/tada.styl @@ -1,11 +1,11 @@ @keyframes tada 0% - transform: scale(1) + transform: scale3d(1, 1, 1) 10%, 20% - transform: scale(0.9) rotate(-3deg) + transform: scale3d(.9, .9, .9) rotate3d(0, 0, 1, -3deg) 30%, 50%, 70%, 90% - transform: scale(1.1) rotate(3deg) + transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, 3deg) 40%, 60%, 80% - transform: scale(1.1) rotate(-3deg) + transform: scale3d(1.1, 1.1, 1.1) rotate3d(0, 0, 1, -3deg) 100% - transform: scale(1) rotate(0) + transform: scale3d(1, 1, 1) diff --git a/lib/rider/animate/wobble.styl b/lib/rider/animate/wobble.styl index 360e30a..aed042d 100644 --- a/lib/rider/animate/wobble.styl +++ b/lib/rider/animate/wobble.styl @@ -2,16 +2,16 @@ @keyframes wobble 0% - transform: translateX(0%) + transform: none 15% - transform: translateX(-25%) rotate(-5deg) + transform: translate3d(-25%, 0, 0) rotate3d(0, 0, 1, -5deg) 30% - transform: translateX(20%) rotate(3deg) + transform: translate3d(20%, 0, 0) rotate3d(0, 0, 1, 3deg) 45% - transform: translateX(-15%) rotate(-3deg) + transform: translate3d(-15%, 0, 0) rotate3d(0, 0, 1, -3deg) 60% - transform: translateX(10%) rotate(2deg) + transform: translate3d(10%, 0, 0) rotate3d(0, 0, 1, 2deg) 75% - transform: translateX(-5%) rotate(-1deg) + transform: translate3d(-5%, 0, 0) rotate3d(0, 0, 1, -1deg) 100% - transform: translateX(0%) + transform: none diff --git a/lib/rider/animate/zoomIn.styl b/lib/rider/animate/zoomIn.styl new file mode 100644 index 0000000..baaf051 --- /dev/null +++ b/lib/rider/animate/zoomIn.styl @@ -0,0 +1,7 @@ +@keyframes zoomIn + 0% + opacity: 0 + transform: scale3d(.3, .3, .3) + + 50% + opacity: 1 diff --git a/lib/rider/animate/zoomInDown.styl b/lib/rider/animate/zoomInDown.styl new file mode 100644 index 0000000..4f3adc0 --- /dev/null +++ b/lib/rider/animate/zoomInDown.styl @@ -0,0 +1,9 @@ +@keyframes zoomInDown + 0% + opacity: 0 + transform: scale3d(.1, .1, .1) translate3d(0, -1000px, 0) + animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190) + 60% + opacity: 1 + transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0) + animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1) diff --git a/lib/rider/animate/zoomInLeft.styl b/lib/rider/animate/zoomInLeft.styl new file mode 100644 index 0000000..69162f8 --- /dev/null +++ b/lib/rider/animate/zoomInLeft.styl @@ -0,0 +1,9 @@ +@keyframes zoomInLeft + 0% + opacity: 0 + transform: scale3d(.1, .1, .1) translate3d(-1000px, 0, 0) + animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190) + 60% + opacity: 1 + transform: scale3d(.475, .475, .475) translate3d(10px, 0, 0) + animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1) diff --git a/lib/rider/animate/zoomInRight.styl b/lib/rider/animate/zoomInRight.styl new file mode 100644 index 0000000..20a0c5e --- /dev/null +++ b/lib/rider/animate/zoomInRight.styl @@ -0,0 +1,9 @@ +@keyframes zoomInRight + 0% + opacity: 0 + transform: scale3d(.1, .1, .1) translate3d(1000px, 0, 0) + animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190) + 60% + opacity: 1 + transform: scale3d(.475, .475, .475) translate3d(-10px, 0, 0) + animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1) diff --git a/lib/rider/animate/zoomInUp.styl b/lib/rider/animate/zoomInUp.styl new file mode 100644 index 0000000..02092e9 --- /dev/null +++ b/lib/rider/animate/zoomInUp.styl @@ -0,0 +1,9 @@ +@keyframes zoomInUp + 0% + opacity: 0 + transform: scale3d(.1, .1, .1) translate3d(0, 1000px, 0) + animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190) + 60% + opacity: 1 + transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0) + animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1) diff --git a/lib/rider/animate/zoomOut.styl b/lib/rider/animate/zoomOut.styl new file mode 100644 index 0000000..8319576 --- /dev/null +++ b/lib/rider/animate/zoomOut.styl @@ -0,0 +1,8 @@ +@keyframes zoomOut + 0% + opacity: 1 + 50% + opacity: 0 + transform: scale3d(.3, .3, .3) + 100% + opacity: 0 diff --git a/lib/rider/animate/zoomOutDown.styl b/lib/rider/animate/zoomOutDown.styl new file mode 100644 index 0000000..110f1aa --- /dev/null +++ b/lib/rider/animate/zoomOutDown.styl @@ -0,0 +1,10 @@ +@keyframes zoomOutDown + 40% + opacity: 1 + transform: scale3d(.475, .475, .475) translate3d(0, -60px, 0) + animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190) + 100% + opacity: 0 + transform: scale3d(.1, .1, .1) translate3d(0, 2000px, 0) + transform-origin: center bottom + animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1) diff --git a/lib/rider/animate/zoomOutLeft.styl b/lib/rider/animate/zoomOutLeft.styl new file mode 100644 index 0000000..0047bf8 --- /dev/null +++ b/lib/rider/animate/zoomOutLeft.styl @@ -0,0 +1,8 @@ +@keyframes zoomOutLeft + 40% + opacity: 1 + transform: scale3d(.475, .475, .475) translate3d(42px, 0, 0) + 100% + opacity: 0 + transform: scale(.1) translate3d(-2000px, 0, 0) + transform-origin: left center diff --git a/lib/rider/animate/zoomOutRight.styl b/lib/rider/animate/zoomOutRight.styl new file mode 100644 index 0000000..a11e76e --- /dev/null +++ b/lib/rider/animate/zoomOutRight.styl @@ -0,0 +1,8 @@ +@keyframes zoomOutRight + 40% + opacity: 1 + transform: scale3d(.475, .475, .475) translate3d(-42px, 0, 0) + 100% + opacity: 0 + transform: scale(.1) translate3d(2000px, 0, 0) + transform-origin: right center diff --git a/lib/rider/animate/zoomOutUp.styl b/lib/rider/animate/zoomOutUp.styl new file mode 100644 index 0000000..9030bbf --- /dev/null +++ b/lib/rider/animate/zoomOutUp.styl @@ -0,0 +1,10 @@ +@keyframes zoomOutUp + 40% + opacity: 1 + transform: scale3d(.475, .475, .475) translate3d(0, 60px, 0) + animation-timing-function: cubic-bezier(0.550, 0.055, 0.675, 0.190) + 100% + opacity: 0 + transform: scale3d(.1, .1, .1) translate3d(0, -2000px, 0) + transform-origin: center bottom + animation-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1) diff --git a/lib/rider/breakpoint.styl b/lib/rider/breakpoint.styl index d9b8427..d8dbd82 100644 --- a/lib/rider/breakpoint.styl +++ b/lib/rider/breakpoint.styl @@ -5,125 +5,58 @@ @require 'setting' -breakpoint() - // exception handling - if length(arguments) < 1 - error('breakpoint requires arguments.') - return +breakpoint($min-value, $max-value) + // 异常处理 unless mixin in ('block' 'root') - error('breakpoint must be the block/root when you use it.') + error('+breakpoint() 需要以 block mixin 的方式使用') + // media query 数组 $mq-array = () - $retina-required = false - // dirty patch - if length(arguments) == 2 && typeof(arguments[0]) == 'unit' && typeof(arguments[1]) == 'unit' - $args = (null arguments) - else - $args = arguments + if unit($min-value) == '' + $min-value = ($-breakpoint-slice[$min-value - 1] + 1 || 0) unless $min-value == 0 - // loops - for $arg in $args - $arg-type = typeof($arg) - - if $arg-type == 'unit' && length($arg) == 2 - - $min-value = $arg[0] - $max-value = $arg[1] - - if unit($min-value) == '' - $min-value = ($-breakpoint-slice[$min-value - 1] + 1 || 0) unless $min-value == 0 - - if unit($max-value) == '' - if $max-value < length($-breakpoint-slice) - $max-value = $-breakpoint-slice[$max-value] - else - // 0 means larger than largest slice - $max-value = 0 - - if $min-value > 1 - push($mq-array, '(min-width: %s)' % $min-value) - - if $max-value > 1 - push($mq-array, '(max-width: %s)' % $max-value) - - else if $arg-type == 'string' && $arg in ('portrait' 'landscape') - // orientation - push($mq-array, '(orientation: %s)' % unquote($arg)) + if unit($max-value) == '' + if $max-value < length($-breakpoint-slice) + $max-value = $-breakpoint-slice[$max-value] + else + // 最大值为 0 时,代表大于最大的切片的值 + $max-value = 0 - else if $arg-type == 'string' && $arg in ('all' 'screen' 'print' 'tv' 'braille' 'embossed' 'handheld' 'projection' 'speech' 'tty') - // @see http://goo.gl/a3twta - unshift($mq-array, $arg) + if $min-value > 1 + push($mq-array, '(min-width: %s)' % $min-value) - else if $arg == 'retina' - // retina - $retina-required = true - - else - warn('the argument "' + $arg + '" is unknown, please remove it.') unless $arg == null + if $max-value > 1 + push($mq-array, '(max-width: %s)' % $max-value) // join queries $mq-string = join(' and ', $mq-array) - // hack it until autoprefixer supported - // "," higher priority than "and" - if $retina-required == true - // @see http://goo.gl/eHTUo6 - // @see http://bjango.com/articles/min-device-pixel-ratio/ - $mq-retina-array = ('(-webkit-min-device-pixel-ratio: 1.3)' '(min-resolution: 125dpi)') - - if $mq-string - $mq-string = '%s and %s, %s and %s' % (unquote($mq-string) unquote($mq-retina-array[0]) unquote($mq-string) unquote($mq-retina-array[1])) - else - $mq-string = join(', ', $mq-retina-array) - unless $mq-string - error('breakpoint is invalid, please check the arguments.') + error('breakpoint() 无法生成出合法的 media query,请检查参数是否正确') @media $mq-string {block} below($value) - $values = (0 $value) - if mixin in ('block' 'root') - +breakpoint($values) - {block} - else - return $values + +breakpoint(0, $value) + {block} above($value) - $values = $value, length($-breakpoint-slice) - if mixin in ('block' 'root') - +breakpoint($values) - {block} - else - return $values + +breakpoint($value, length($-breakpoint-slice)) + {block} at($value) if unit($value) != '' - error('$value must be a breakpoint slice.') - $values = ($value $value) - if mixin in ('block' 'root') - +breakpoint($values) - {block} - else - return $values + error('$value 必须为 breakpoint 的切片') + +breakpoint($value, $value) + {block} between($from-value, $to-value) - $values = ($from-value $to-value) - if mixin in ('block' 'root') - +breakpoint($values) - {block} - else - return $values - - -retina() - if mixin in ('block' 'root') - +breakpoint('retina') - {block} + +breakpoint($from-value, $to-value) + {block} diff --git a/lib/rider/clockhand.styl b/lib/rider/clockhand.styl index 7669025..ef525f1 100644 --- a/lib/rider/clockhand.styl +++ b/lib/rider/clockhand.styl @@ -1,5 +1,5 @@ // clockhand -// +// // @author firede(firede@firede.us) // @desc shorthand properties support, based on `clockhand-stylus` // @see https://github.com/jasonkuhrt/clockhand-stylus diff --git a/lib/rider/easing.styl b/lib/rider/easing.styl index d1d177e..e2460be 100644 --- a/lib/rider/easing.styl +++ b/lib/rider/easing.styl @@ -1,7 +1,7 @@ -// easing -// +// 缓动函数 +// // @author firede(firede@firede.us) -// @desc more easing functions by cubic-bezier +// @desc 通过 `cubic-bezier` 定义的更多缓动函数 // @see http://easings.net @@ -47,11 +47,11 @@ easing($type = 'ease') return cubic-bezier(0.175, 0.885, 0.320, 1.275) if $type == 'out-back' return cubic-bezier(0.680, -0.550, 0.265, 1.550) if $type == 'in-out-back' - // others + // 兼容默认缓动函数 if $type == 'ease' return unquote('ease') else if $type in ('in' 'out' 'in-out') return unquote('ease-' + $type) else - error('easing function is not supported.') + error('不支持 `' + $type + '` 缓动函数') diff --git a/lib/rider/image.styl b/lib/rider/image.styl index 140a77f..9113539 100644 --- a/lib/rider/image.styl +++ b/lib/rider/image.styl @@ -1,42 +1,86 @@ -// image -// +// 图片 +// // @author firede(firede@firede.us) -// @desc image helpers @require 'setting' +@require 'retina' @require 'typography' -// set background image -bg($path, $width = auto, $height = auto, $dppx = $-image-dppx) - warn('$path should be a string.') if typeof($path) != 'string' - background: url($path) no-repeat +// 设置背景图片 +// 自动查找并设置为 retina 设备准备的高清图片 +bg($src, $width = null, $height = null) - if $width in (cover contain) and $height == auto - $height = null - else if $width == auto && $height == auto - $img-size = image-size($path, 0) - if $img-size[0] != 0 - $width = ($img-size[0] / $dppx) - $height = ($img-size[1] / $dppx) - else - $width = null - $height = null - warn('$width and $height get failed, the values has been set to `auto`.') + if not file-exists($src) + error('$src 必须为本地已存在的图片路径:' + $src) + + // 获取图片尺寸 + $img-size = image-size($src) + $width = $img-size[0] if $width == null + $height = $img-size[1] if $height == null - if $width != null || $height != null - background-size: $width $height + background-image: url($src) + background-size: $width $height + background-repeat: no-repeat + for $dppx, $index in $-image-dppx-range + // 忽略 dppx 为 1 的情况 + if $dppx != 1 + $computed-src = get-retina-src($src, $dppx, $-image-dppx-separator) + if file-exists($computed-src) + // 质量优先模式 + if $-image-dppx-quality-first && $dppx > 1.5 + $computed-dppx = $dppx - 0.5 + else + $computed-dppx = $dppx -// image replace -// hide text and set background image -ir($path, $x = 0, $y = 0, $width = auto, $height = auto, $dppx = $-image-dppx) - bg($path, $width, $height, $dppx) + +retina($computed-dppx) + background-image: url($computed-src) - if $x != 0 && $y == 0 - $y = null - if $x != 0 - background-position: $x $y +// 图片替换 +// 隐藏文字并设置背景图片,可指定背景图片坐标 +ir($src, $x = null, $y = null, $width = null, $height = null) hide-text() + + background-position-x: $x if $x != null && $y == null + background-position-y: $y if $x == null && $y != null + if $x != null && $y != null + if $x == $y + background-position: $x + else + background-position: $x $y + + bg($src, $width, $height) + + +// 使用若干 dppx 倍数的图片 +// 若换算后的图片尺寸不为整数,则舍弃小数部分 +bg-dppx($dppx, $src, $width = null, $height = null) + + if unit($dppx) != '' + error('$dppx 的值必须是一个代表倍数的数字') + + if not file-exists($src) + error('$src 必须为本地已存在的图片路径:' + $src) + + // 获取图片尺寸 + $img-size = image-size($src) + $width = floor($img-size[0] / $dppx) if $width == null + $height = floor($img-size[1] / $dppx) if $height == null + + background-image: url($src) + background-size: $width $height + background-repeat: no-repeat + + +// 使用 2dppx 的图片作为背景 +bg2x($src, $width = null, $height = null) + bg-dppx(2, $src, $width, $height) + + +// 使用 3dppx 的图片作为背景 +bg3x($src, $width = null, $height = null) + bg-dppx(3, $src, $width, $height) + diff --git a/lib/rider/index.styl b/lib/rider/index.styl index 2a2e493..b1de183 100644 --- a/lib/rider/index.styl +++ b/lib/rider/index.styl @@ -1,5 +1,5 @@ // rider -// +// // @author firede(firede@firede.us) @require 'setting' @@ -12,3 +12,5 @@ @require 'breakpoint' @require 'animate' @require 'initialize' +@require 'normalize' +@require 'retina' diff --git a/lib/rider/initialize.styl b/lib/rider/initialize.styl index e4df9b9..b290df9 100644 --- a/lib/rider/initialize.styl +++ b/lib/rider/initialize.styl @@ -1,4 +1,4 @@ -// initialize +// 样式初始化 // // @author firede(firede@firede.us) @@ -152,9 +152,6 @@ initialize() -webkit-text-size-adjust: 100% -ms-text-size-adjust: 100% - if $-prevent-user-select == true - user-select: none - // tap highlight color if $-prevent-tap-highlight == true a, diff --git a/lib/rider/normalize.styl b/lib/rider/normalize.styl new file mode 100644 index 0000000..20a4af1 --- /dev/null +++ b/lib/rider/normalize.styl @@ -0,0 +1,361 @@ +// 样式归一化 +// +// @author firede(firede@firede.us) +// @desc ported from normalize.css v3.0.3, MIT License +// @see http://github.com/necolas/normalize.css + + +normalize() + + // 1. Set default font family. + // 2. Prevent iOS and IE text size adjust after device orientation change, + // without disabling user zoom. + + html + font-size: unit($-base-font-size / 16 * 100, '%') + font-family: $-base-font-family // 1 + + if $-prevent-text-size-adjust == true // 2 + -ms-text-size-adjust: 100% + -webkit-text-size-adjust: 100% + + + // tap highlight color + if $-prevent-tap-highlight == true + a, + nav + -webkit-tap-highlight-color: rgba(0, 0, 0, 0) + -webkit-tap-highlight-color: transparent // for some Android + + // Remove default margin. + + body + margin: 0 + + + // HTML5 display definitions + + + // Correct `block` display not defined for any HTML5 element in IE 8/9. + // Correct `block` display not defined for `details` or `summary` in IE 10/11 + // and Firefox. + // Correct `block` display not defined for `main` in IE 11. + + article, + aside, + details, + figcaption, + figure, + footer, + header, + hgroup, + main, + menu, + nav, + section, + summary + display: block + + + // 1. Correct `inline-block` display not defined in IE 8/9. + // 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. + + audio, + canvas, + progress, + video + display: inline-block // 1 + vertical-align: baseline // 2 + + + // Prevent modern browsers from displaying `audio` without controls. + // Remove excess height in iOS 5 devices. + + audio:not([controls]) + display: none + height: 0 + + + // Address `[hidden]` styling not present in IE 8/9/10. + // Hide the `template` element in IE 8/9/10/11, Safari, and Firefox < 22. + + [hidden], + template + display: none + + + // Links + + + // Remove the gray background color from active links in IE 10. + + a + background-color: transparent + + + // Improve readability of focused elements when they are also in an + // active/hover state. + + a:active, + a:hover + outline: 0 + + + // Text-level semantics + + + // Address styling not present in IE 8/9/10/11, Safari, and Chrome. + + abbr[title] + border-bottom: 1px dotted + + + // Address style set to `bolder` in Firefox 4+, Safari, and Chrome. + + b, + strong + font-weight: bold + + + // Address styling not present in Safari and Chrome. + + dfn + font-style: italic + + + // Address variable `h1` font-size and margin within `section` and `article` + // contexts in Firefox 4+, Safari, and Chrome. + + h1 + font-size: 2em + margin: 0.67em 0 + + + // Address styling not present in IE 8/9. + + mark + background: #ff0 + color: #000 + + + // Address inconsistent and variable font size in all browsers. + + small + font-size: 80% + + + // Prevent `sub` and `sup` affecting `line-height` in all browsers. + + sub, + sup + font-size: 75% + line-height: 0 + position: relative + vertical-align: baseline + + sup + top: -0.5em + + sub + bottom: -0.25em + + + // Embedded content + + + // Remove border when inside `a` element in IE 8/9/10. + + img + border: 0 + + + // Correct overflow not hidden in IE 9/10/11. + + svg:not(:root) + overflow: hidden + + + // Grouping content + + + // Address margin not present in IE 8/9 and Safari. + + figure + margin: 1em 40px + + + // Address differences between Firefox and other browsers. + + hr + box-sizing: content-box + height: 0 + + + // Contain overflow in all browsers. + + pre + overflow: auto + + + // Address odd `em`-unit font size rendering in all browsers. + + code, + kbd, + pre, + samp + font-family: $-code-font-family + font-size: 1em + + + // Forms + + + // Known limitation: by default, Chrome and Safari on OS X allow very limited + // styling of `select`, unless a `border` property is set. + + // 1. Correct color not being inherited. + // Known issue: affects color of disabled elements. + // 2. Correct font properties not being inherited. + // 3. Address margins set differently in Firefox 4+, Safari, and Chrome. + + button, + input, + optgroup, + select, + textarea + color: inherit + font: inherit + margin: 0 + + + // Address `overflow` set to `hidden` in IE 8/9/10/11. + + button + overflow: visible + + + // Address inconsistent `text-transform` inheritance for `button` and `select`. + // All other form control elements do not inherit `text-transform` values. + // Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera. + // Correct `select` style inheritance in Firefox. + + button, + select + text-transform: none + + + // 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` + // and `video` controls. + // 2. Correct inability to style clickable `input` types in iOS. + // 3. Improve usability and consistency of cursor style between image-type + // `input` and others. + + button, + html input[type="button"], // 1 + input[type="reset"], + input[type="submit"] + -webkit-appearance: button // 2 + cursor: pointer // 3 + + + // Re-set default cursor for disabled elements. + + button[disabled], + html input[disabled] + cursor: default + + + // Remove inner padding and border in Firefox 4+. + + button::-moz-focus-inner, + input::-moz-focus-inner + border: 0 + padding: 0 + + + // Address Firefox 4+ setting `line-height` on `input` using `!important` in + // the UA stylesheet. + + input + line-height: normal + + + // It's recommended that you don't attempt to style these elements. + // Firefox's implementation doesn't respect box-sizing, padding, or width. + // + // 1. Address box sizing set to `content-box` in IE 8/9/10. + // 2. Remove excess padding in IE 8/9/10. + + input[type="checkbox"], + input[type="radio"] + box-sizing: border-box // 1 + padding: 0 // 2 + + + // Fix the cursor style for Chrome's increment/decrement buttons. For certain + // `font-size` values of the `input`, it causes the cursor style of the + // decrement button to change from `default` to `text`. + + input[type="number"]::-webkit-inner-spin-button, + input[type="number"]::-webkit-outer-spin-button + height: auto + + + // 1. Address `appearance` set to `searchfield` in Safari and Chrome. + // 2. Address `box-sizing` set to `border-box` in Safari and Chrome. + + input[type="search"] + -webkit-appearance: textfield // 1 + box-sizing: content-box // 2 + + + // Remove inner padding and search cancel button in Safari and Chrome on OS X. + // Safari (but not Chrome) clips the cancel button when the search input has + // padding (and `textfield` appearance). + + input[type="search"]::-webkit-search-cancel-button, + input[type="search"]::-webkit-search-decoration + -webkit-appearance: none + + + // Define consistent border, margin, and padding. + + fieldset + border: 1px solid #c0c0c0 + margin: 0 2px + padding: 0.35em 0.625em 0.75em + + + // 1. Correct `color` not being inherited in IE 8/9/10/11. + // 2. Remove padding so people aren't caught out if they zero out fieldsets. + + legend + border: 0 // 1 + padding: 0 // 2 + + + // Remove default vertical scrollbar in IE 8/9/10/11. + + textarea + overflow: auto + + + // Don't inherit the `font-weight` (applied by a rule above). + // NOTE: the default cannot safely be changed in Chrome and Safari on OS X. + + optgroup + font-weight: bold + + + // Tables + + + // Remove most spacing between table cells. + + table + border-collapse: collapse + border-spacing: 0 + + td, + th + padding: 0 diff --git a/lib/rider/retina.styl b/lib/rider/retina.styl new file mode 100644 index 0000000..792bc6a --- /dev/null +++ b/lib/rider/retina.styl @@ -0,0 +1,10 @@ +// Retina 支持 +// +// @author firede(firede@firede.us) + +// 限定 retina 模式的 block mixin +// 不区分 dppx 具体倍数时,取 1.5dppx 作为一般意义上的 retina 设备 +retina($dppx = 1.5) + $mq-string = '(min-resolution: %sdppx), (min-resolution: %sdpi)' % ($dppx ($dppx * 96)) + @media $mq-string + {block} diff --git a/lib/rider/setting.styl b/lib/rider/setting.styl index efd6c78..a439e1c 100644 --- a/lib/rider/setting.styl +++ b/lib/rider/setting.styl @@ -1,31 +1,43 @@ -// setting +// 配置 // // @author firede(firede@firede.us) -// @desc default settings, you can overriding it by yourself. +// @desc 默认配置,如需修改,建议在调用之前覆盖 +// 如修改默认字号,可设置:$-base-font-size = 14px -// off stylus compatibility settings (ex: keyframes), autoprefixer do it. +// 关闭 Stylus 修复前缀的兼容性功能,此任务交给 Autoprefixer vendors = official -// the unit using `px` value(100% == 16px) +// 基础字体大小 +// 默认单位为 px,默认值 16px 即为 100% $-base-font-size ?= 16px +// 基础字体族群 // @see http://iosfonts.com -$-base-font-family ?= 'Helvetica Neue', sans-serif +$-base-font-family ?= 'Helvetica Neue', Arial, sans-serif +$-code-font-family ?= Menlo, Consolas, monospace -// usually use `true` in hybrid app -$-prevent-user-select ?= false - -// prevent iOS text size adjust after orientation change +// 阻止 iOS 在翻转屏幕后调整字体大小 $-prevent-text-size-adjust ?= true -// prevent tap highlight color +// 消除 tap highlight 颜色 $-prevent-tap-highlight ?= true -// default image dppx (dots per px unit) -$-image-dppx ?= 2 +// 图片的retina版本探测范围 +// 顺序按从小到大排列 +$-image-dppx-range ?= (2 3) + +// 图片dppx分隔符 +$-image-dppx-separator ?= '@' -// breakpoint slice -// default value: 0 400px 600px 800px 1050px -// slice number: <- 1 | 2 | 3 | 4 | 5 -> +// 图片质量优先模式 +// 启用时将为低 0.5dppx 以内的设备,使用质量更高的图片 +$-image-dppx-quality-first ?= false + +// breakpoint 的切片分段 +// 默认值: 0 400px 600px 800px 1050px +// 片段: <- 1 | 2 | 3 | 4 | 5 -> $-breakpoint-slice ?= 0 400px 600px 800px 1050px + +// 单位转换精度,小数点后保留的位数 +$-unit-precision ?= 5 diff --git a/lib/rider/shape.styl b/lib/rider/shape.styl index 2d01563..48e8d75 100644 --- a/lib/rider/shape.styl +++ b/lib/rider/shape.styl @@ -1,10 +1,10 @@ -// shape -// -// @author firede(firede@firede.us) +// 形状 +// +// @author firede(firede@firede.us) -// set width and height quickly -// default unit is `px` +// 快速设置宽度与高度 +// 默认单位为 `px` size($values...) if length($values) == 1 $values-unit = unit($values) == '' ? 'px' : unit($values) @@ -19,7 +19,7 @@ size($values...) height: unit($values[1], $height-unit) -// triangle +// 三角形 triangle($direction = top, $size = 10px, $color = #333) size: 0 @@ -40,3 +40,18 @@ triangle($direction = top, $size = 10px, $color = #333) border-bottom: $size solid transparent border-left: $size solid $color + +// 圆形 +circle($values...) + if length($values) == 1 + $values-unit = unit($values) == '' ? 'px' : unit($values) + + border-radius: unit($values, $values-unit) + size: $values + else + $horizontal-unit = unit($values[0]) == '' ? 'px' : unit($values[0]) + $vertical-unit = unit($values[1]) == '' ? 'px' : unit($values[1]) + + border-radius: unit($values[0], $horizontal-unit) \/ unit($values[1], $vertical-unit) + size: $values[0] $values[1] + diff --git a/lib/rider/typography.styl b/lib/rider/typography.styl index 6725934..bfcf3e6 100644 --- a/lib/rider/typography.styl +++ b/lib/rider/typography.styl @@ -1,9 +1,9 @@ -// typography +// 排版 // -// @author firede(firede@firede.us) +// @author firede(firede@firede.us) -// hide text +// 隐藏文字 // @see http://goo.gl/EglZN hide-text() color: transparent @@ -11,8 +11,8 @@ hide-text() text-shadow: none -// ellipsis -// support multi line (webkit only) +// 省略 +// 多行截断并省略,仅在 webkit 下支持 ellipsis($line = 1) overflow: hidden text-overflow: ellipsis @@ -25,7 +25,7 @@ ellipsis($line = 1) -webkit-box-orient: vertical -// clearfix +// 清除浮动 // @see http://h5bp.com/q clearfix() &:after, @@ -36,16 +36,54 @@ clearfix() clear: both -// font face -// iOS/Android used ttf, Mobile IE 10 used woff. -font-face($font-family, $font-path, $version-suffix = '') - $version-suffix = '?' + $version-suffix if $version-suffix != '' - $ttf-path = $font-path + '.ttf' + $version-suffix - $woff-path = $font-path + '.woff' + $version-suffix +// 字体 +// 根据存在的字体类型,自动生成配置 +font-face($font-family, $font-path, $font-weight = normal, $font-style = normal) + + if is-url($font-path) + error('$font-path 只支持本地路径,请直接用 @font-face 写远程路径') + + // 字体类型与对应的format,顺序排列 + $font-formats = { + 'eot': 'embedded-opentype', + 'woff': 'woff', + 'woff2': 'woff2', + 'ttf': 'truetype', + 'svg': 'svg' + } + + $usable-types = () + $src-array = () + $font-files = {} + + // 取出本地可用的字体 + for $type in keys($font-formats) + $font-files[$type] = $font-path + '.' + $type + + if file-exists($font-files[$type]) + push($usable-types, $type) + + // 无任何可用字体则报错 + if length($usable-types) == 0 + error('没有找到 `' + $font-family + '` 的本地字体文件'); + + // 合并字体src + for $type in $usable-types + if $type == 'eot' + $src-url = $font-files[$type] + '?#iefix' + else if $type == 'svg' + $src-url = $font-files[$type] + '#' + $font-family + else + $src-url = $font-files[$type] + $src-str = s('%s format(%s)', url($src-url), $font-formats[$type]) + push($src-array, $src-str) + + $str = join(', ', $src-array) @font-face font-family: $font-family - src: url($woff-path) format('woff'), url($ttf-path) format('truetype') - font-weight: normal - font-style: normal - + if 'eot' in $usable-types + src: url($font-files['eot']) + src: unquote($str) + font-weight: $font-weight + font-style: $font-style diff --git a/lib/rider/unit.styl b/lib/rider/unit.styl index 3231c12..ae2dbe8 100644 --- a/lib/rider/unit.styl +++ b/lib/rider/unit.styl @@ -1,33 +1,36 @@ -// unit -// +// 单位 +// // @author firede(firede@firede.us) -// @desc unit conversion functions +// @desc 单位转换函数 @require 'setting' -// convert to rem unit -// default unit is `px` +// 转换至 rem 单位 +// $value 接收 `px` 单位的值,`px` 可省略 rem($value) if unit($value) == 'px' || unit($value) == '' - $value = round($value / $-base-font-size, 3) + $value = round($value / $-base-font-size, $-unit-precision) unit($value, 'rem') -// convert to em unit +// 转换至 em 单位 +// $value 接收 `px`, `rem` 单位的值,省略单位默认为 `px` +// $upper-value 作为相对单位,需指定上级元素字体大小 em($value, $upper-value = $-base-font-size) if unit($value) == 'px' || unit($value) == '' - $value = round($value / px($upper-value), 3) + $value = round($value / px($upper-value), $-unit-precision) else if unit($value) == 'rem' - $value = round(px($value) / px($upper-value), 3) + $value = round(px($value) / px($upper-value), $-unit-precision) unit($value, 'em') -// convert to px unit +// 转换至 px 单位 +// $value 接收 `rem` 单位的值 px($value) if unit($value) == 'rem' - $value = round($value * $-base-font-size, 3) + $value = round($value * $-base-font-size, $-unit-precision) unit($value, 'px') diff --git a/package.json b/package.json index 4837430..4384d68 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,25 @@ { "name": "rider", - "version": "0.4.4", - "description": "Rider is a CSS library to focus on Mobile Web, build on top of Stylus.", + "version": "2.0.0", + "description": "Rider 是一个基于 Stylus 与后处理器、无侵入风格的 CSS 样式工具库", "maintainers": [ - { "name": "Firede", "email": "firede@firede.us" } + { + "name": "Firede", + "email": "firede@firede.us" + } ], + "dependencies": { + "stylus": "*" + }, "devDependencies": { - "autoprefixer-core": "~3.1.2", - "stylus": "~0.49.3", - "express": "~4.10.1", - "ejs": "~1.0.0", - "mocha": "~1.21.5", - "should": "~4.0.4" + "autoprefixer-core": "~5.1.11", + "connect": "~3.3.5", + "mocha": "~2.2.4", + "serve-static": "^1.9.2" }, "scripts": { - "test": "mocha" + "test": "mocha", + "demo": "node ./demo" }, "main": "./lib/rider.js", "license": "MIT", diff --git a/test/cases/animate.css b/test/cases/animate.css index 19ebb5c..876c61f 100644 --- a/test/cases/animate.css +++ b/test/cases/animate.css @@ -10,22 +10,30 @@ animation-name: bounce; animation-duration: 1s; animation-fill-mode: both; + transform-origin: center bottom; } @keyframes bounce { - 0%, 20%, 50%, 80%, 100% { - transform: translateY(0); + 0%, 20%, 53%, 80%, 100% { + transition-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1); + transform: translate3d(0, 0, 0); } - 40% { - transform: translateY(-30px); + 40%, 43% { + transition-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06); + transform: translate3d(0, -30px, 0); } - 60% { - transform: translateY(-15px); + 70% { + transition-timing-function: cubic-bezier(0.755, 0.05, 0.855, 0.06); + transform: translate3d(0, -15px, 0); + } + 90% { + transform: translate3d(0, -4px, 0); } } .test-2 { animation-name: bounce; animation-duration: 1s; animation-fill-mode: both; + transform-origin: center bottom; } .test-3 { animation-name: bounceIn; @@ -33,20 +41,29 @@ animation-fill-mode: both; } @keyframes bounceIn { + 0%, 20%, 40%, 60%, 80%, 100% { + transition-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1); + } 0% { opacity: 0; - transform: scale(0.3); + transform: scale3d(0.3, 0.3, 0.3); } - 50% { + 20% { + transform: scale3d(1.1, 1.1, 1.1); + } + 40% { + transform: scale3d(0.9, 0.9, 0.9); + } + 60% { opacity: 1; - transform: scale(1.05); + transform: scale3d(1.03, 1.03, 1.03); } - 70% { - transform: scale(0.9); + 80% { + transform: scale3d(0.97, 0.97, 0.97); } 100% { opacity: 1; - transform: scale(1); + transform: scale3d(1, 1, 1); } } .test-4 { diff --git a/test/cases/breakpoint.css b/test/cases/breakpoint.css index 7ea9ecf..b0b6134 100644 --- a/test/cases/breakpoint.css +++ b/test/cases/breakpoint.css @@ -1,38 +1,3 @@ -@media (-webkit-min-device-pixel-ratio: 1.3), (min-resolution: 125dpi) { - .test-1 { - foo: bar; - } -} -@media (-webkit-min-device-pixel-ratio: 1.3), (min-resolution: 125dpi) { - .test-2 { - foo: bar; - } -} -@media screen { - .test-3 { - foo: bar; - } -} -@media screen and (orientation: portrait) { - .test-4 { - foo: bar; - } -} -@media screen and (orientation: portrait) { - .test-5 { - foo: bar; - } -} -@media screen and (orientation: portrait) and (min-width: 401px) and (max-width: 800px) { - .test-6 { - foo: bar; - } -} -@media (orientation: portrait) { - .test-7 { - foo: bar; - } -} @media (min-width: 401px) and (max-width: 800px) { .test-8 { foo: bar; @@ -58,26 +23,6 @@ foo: bar; } } -@media all and (min-width: 601px) and (max-width: 800px) { - .test-13 { - foo: bar; - } -} -@media print and (max-width: 800px) { - .test-14 { - foo: bar; - } -} -@media screen and (min-width: 601px) { - .test-15 { - foo: bar; - } -} -@media screen and (min-width: 601px) and (max-width: 1050px) { - .test-16 { - foo: bar; - } -} @media (min-width: 601px) and (max-width: 900px) { .test-17 { foo: bar; @@ -93,11 +38,6 @@ foo: bar; } } -@media (min-width: 601px) and (max-width: 800px) and (-webkit-min-device-pixel-ratio: 1.3), (min-width: 601px) and (max-width: 800px) and (min-resolution: 125dpi) { - .test-20 { - foo: bar; - } -} @media (max-width: 400px) { .test-21 { display: block; diff --git a/test/cases/breakpoint.styl b/test/cases/breakpoint.styl index 32f8eb6..3ea9a59 100644 --- a/test/cases/breakpoint.styl +++ b/test/cases/breakpoint.styl @@ -1,44 +1,11 @@ -// retina mixin -.test-1 - +retina() - foo: bar - -// retina root -+retina() - .test-2 - foo: bar - -// 1 argument -+breakpoint('screen') - .test-3 - foo: bar - -// 2 arguments without comma -+breakpoint('screen' 'portrait') - .test-4 - foo: bar - -// 2 arguments with comma -+breakpoint('screen', 'portrait') - .test-5 - foo: bar - -// 3 arguments with min-width/max-width -+breakpoint('screen', 'portrait', (2 3)) - .test-6 - foo: bar - -// with unknown argument should be ignored -+breakpoint('abc', 'portrait') - .test-7 - foo: bar - +// between mixin +between(2, 3) .test-8 foo: bar -+between(0, 4) - .test-9 +// between root +.test-9 + +between(0, 4) foo: bar +at(4) @@ -53,23 +20,6 @@ .test-12 foo: bar -// combination -+breakpoint('all' at(3)) - .test-13 - foo: bar - -+breakpoint('print', below(3)) - .test-14 - foo: bar - -+breakpoint('screen', above(3)) - .test-15 - foo: bar - -+breakpoint('screen', between(3, 4)) - .test-16 - foo: bar - // breakpoint with px/em/rem unit +breakpoint(3, 900px) .test-17 @@ -83,10 +33,6 @@ .test-19 foo: bar -+breakpoint('retina', at(3)) - .test-20 - foo: bar - +at(1) .test-21 display: block diff --git a/demo/public/font/rider-icon.ttf b/test/cases/font/rider-icon.ttf similarity index 100% rename from demo/public/font/rider-icon.ttf rename to test/cases/font/rider-icon.ttf diff --git a/demo/public/font/rider-icon.woff b/test/cases/font/rider-icon.woff similarity index 100% rename from demo/public/font/rider-icon.woff rename to test/cases/font/rider-icon.woff diff --git a/test/cases/image.css b/test/cases/image.css index 751a03a..d72b838 100644 --- a/test/cases/image.css +++ b/test/cases/image.css @@ -1,101 +1,153 @@ -.bg-external-link-1 { - background: url("http://www.baidu.com/img/bdlogo.gif") no-repeat; -} -.bg-external-link-2 { - background: url("http://www.baidu.com/img/bdlogo.gif") no-repeat; - background-size: 100px auto; -} -.bg-external-link-3 { - background: url("http://www.baidu.com/img/bdlogo.gif") no-repeat; - background-size: 100px 50px; -} -.bg-local-image-1 { - background: url("img/logo.png") no-repeat; - background-size: 75px 44px; -} -.bg-local-image-2 { - background: url("img/logo.png") no-repeat; - background-size: 100px auto; -} -.bg-local-image-3 { - background: url("img/logo.png") no-repeat; - background-size: 100px 50px; -} -.bg-local-image-4 { - background: url("img/logo.png") no-repeat; +.bg-1 { + background-image: url("img/logo.png"); background-size: 150px 88px; -} -.bg-local-image-5 { - background: url("img/logo.png") no-repeat; - background-size: contain; -} -.bg-local-image-not-exist { - background: url("img/not-exist.png") no-repeat; -} -.ir-external-link-1 { - background: url("http://www.baidu.com/img/bdlogo.gif") no-repeat; + background-repeat: no-repeat; +} +.bg-2 { + background-image: url("img/rider.png"); + background-size: 136px 136px; + background-repeat: no-repeat; +} +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .bg-2 { + background-image: url("img/rider@2x.png"); + } +} +.bg-3 { + background-image: url("img/rider.png"); + background-size: 20px 30px; + background-repeat: no-repeat; +} +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .bg-3 { + background-image: url("img/rider@2x.png"); + } +} +.bg-4 { + background-image: url("img/rider.png"); + background-size: 20px 136px; + background-repeat: no-repeat; +} +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .bg-4 { + background-image: url("img/rider@2x.png"); + } +} +.ir-1 { color: transparent; font: 0/0 a; text-shadow: none; + background-image: url("img/rider.png"); + background-size: 136px 136px; + background-repeat: no-repeat; } -.ir-local-image-1 { - background: url("img/logo.png") no-repeat; - background-size: 75px 44px; - color: transparent; - font: 0/0 a; - text-shadow: none; +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .ir-1 { + background-image: url("img/rider@2x.png"); + } } -.ir-local-image-2 { - background: url("img/logo.png") no-repeat; - background-size: 75px 44px; - background-position: -10px; +.ir-2 { color: transparent; font: 0/0 a; text-shadow: none; -} -.ir-local-image-3 { - background: url("img/logo.png") no-repeat; - background-size: 75px 44px; background-position: -10px -20px; - color: transparent; - font: 0/0 a; - text-shadow: none; + background-image: url("img/rider.png"); + background-size: 136px 136px; + background-repeat: no-repeat; } -.ir-local-image-4 { - background: url("img/logo.png") no-repeat; - background-size: 75px 44px; - background-position: center; - color: transparent; - font: 0/0 a; - text-shadow: none; +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .ir-2 { + background-image: url("img/rider@2x.png"); + } } -.ir-local-image-5 { - background: url("img/logo.png") no-repeat; - background-size: 100px auto; - background-position: -10px -20px; +.ir-3 { color: transparent; font: 0/0 a; text-shadow: none; + background-position-y: -20px; + background-image: url("img/rider.png"); + background-size: 136px 136px; + background-repeat: no-repeat; } -.ir-local-image-6 { - background: url("img/logo.png") no-repeat; - background-size: 100px 50px; - background-position: -10px -20px; +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .ir-3 { + background-image: url("img/rider@2x.png"); + } +} +.ir-4 { color: transparent; font: 0/0 a; text-shadow: none; + background-position-x: -30px; + background-image: url("img/rider.png"); + background-size: 136px 136px; + background-repeat: no-repeat; } -.ir-local-image-7 { - background: url("img/logo.png") no-repeat; - background-size: 150px 88px; - background-position: -10px -20px; +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .ir-4 { + background-image: url("img/rider@2x.png"); + } +} +.ir-5 { color: transparent; font: 0/0 a; text-shadow: none; + background-position: 0 -30px; + background-image: url("img/rider.png"); + background-size: 100px 200px; + background-repeat: no-repeat; } -.ir-local-image-not-exist { - background: url("img/not-exist.png") no-repeat; +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .ir-5 { + background-image: url("img/rider@2x.png"); + } +} +.ir-6 { color: transparent; font: 0/0 a; text-shadow: none; + background-position: 0; + background-image: url("img/rider.png"); + background-size: 100px 200px; + background-repeat: no-repeat; +} +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .ir-6 { + background-image: url("img/rider@2x.png"); + } +} +.bg2x-1 { + background-image: url("img/logo.png"); + background-size: 75px 44px; + background-repeat: no-repeat; +} +.bg2x-2 { + background-image: url("img/logo.png"); + background-size: 10px 44px; + background-repeat: no-repeat; +} +.bg2x-3 { + background-image: url("img/logo.png"); + background-size: 10px 5px; + background-repeat: no-repeat; +} +.bg2x-4 { + background-image: url("img/rider@2x.png"); + background-size: 136px 136px; + background-repeat: no-repeat; +} +.bg3x-1 { + background-image: url("img/logo.png"); + background-size: 50px 29px; + background-repeat: no-repeat; +} +.bg-dppx-1 { + background-image: url("img/logo.png"); + background-size: 75px 44px; + background-repeat: no-repeat; +} +.bg-dppx-2 { + background-image: url("img/logo.png"); + background-size: 37px 22px; + background-repeat: no-repeat; } diff --git a/test/cases/image.styl b/test/cases/image.styl index c08d477..b4e9943 100644 --- a/test/cases/image.styl +++ b/test/cases/image.styl @@ -1,52 +1,38 @@ -// bg($path, $width = auto, $height = auto, $dppx = $-image-dppx) - -// external link -.bg-external-link-1 - bg: 'http://www.baidu.com/img/bdlogo.gif' -.bg-external-link-2 - bg: 'http://www.baidu.com/img/bdlogo.gif' 100px -.bg-external-link-3 - bg: 'http://www.baidu.com/img/bdlogo.gif' 100px 50px - -// local image -.bg-local-image-1 +.bg-1 bg: 'img/logo.png' -.bg-local-image-2 - bg: 'img/logo.png' 100px -.bg-local-image-3 - bg: 'img/logo.png' 100px 50px -.bg-local-image-4 - bg: 'img/logo.png' auto auto 1 -.bg-local-image-5 - bg: 'img/logo.png' contain - -// local image does not exist -.bg-local-image-not-exist - bg: 'img/not-exist.png' - - -// ir($path, $x = 0, $y = 0, $width = auto, $height = auto, $dppx = $-image-dppx) - -// external link -.ir-external-link-1 - ir: 'http://www.baidu.com/img/bdlogo.gif' - -// local image -.ir-local-image-1 - ir: 'img/logo.png' -.ir-local-image-2 - ir: 'img/logo.png' -10px -.ir-local-image-3 - ir: 'img/logo.png' -10px -20px -.ir-local-image-4 - ir: 'img/logo.png' center -.ir-local-image-5 - ir: 'img/logo.png' -10px -20px 100px -.ir-local-image-6 - ir: 'img/logo.png' -10px -20px 100px 50px -.ir-local-image-7 - ir: 'img/logo.png' -10px -20px auto auto 1 - -// local image does not exist -.ir-local-image-not-exist - ir 'img/not-exist.png' +.bg-2 + bg: 'img/rider.png' +.bg-3 + bg: 'img/rider.png', 20px, 30px +.bg-4 + bg: 'img/rider.png', 20px + +.ir-1 + ir: 'img/rider.png' +.ir-2 + ir: 'img/rider.png', -10px, -20px +.ir-3 + ir: 'img/rider.png', null, -20px +.ir-4 + ir: 'img/rider.png', -30px +.ir-5 + ir: 'img/rider.png', 0, -30px, 100px, 200px +.ir-6 + ir: 'img/rider.png', 0, 0, 100px, 200px + +.bg2x-1 + bg2x: 'img/logo.png' +.bg2x-2 + bg2x: 'img/logo.png', 10px +.bg2x-3 + bg2x: 'img/logo.png', 10px, 5px +.bg2x-4 + bg2x: 'img/rider@2x.png' + +.bg3x-1 + bg3x: 'img/logo.png' + +.bg-dppx-1 + bg-dppx: 2 'img/logo.png' +.bg-dppx-2 + bg-dppx: 4 'img/logo.png' diff --git a/test/cases/img/rider.png b/test/cases/img/rider.png new file mode 100644 index 0000000..70542fb Binary files /dev/null and b/test/cases/img/rider.png differ diff --git a/test/cases/img/rider@2x.png b/test/cases/img/rider@2x.png new file mode 100644 index 0000000..8edf64e Binary files /dev/null and b/test/cases/img/rider@2x.png differ diff --git a/test/cases/retina.css b/test/cases/retina.css new file mode 100644 index 0000000..1b02d8f --- /dev/null +++ b/test/cases/retina.css @@ -0,0 +1,15 @@ +@media (min-resolution: 2dppx), (min-resolution: 192dpi) { + .retina-1 { + foo: bar; + } +} +@media (min-resolution: 1.5dppx), (min-resolution: 144dpi) { + .retina-2 { + foo: baz; + } +} +@media (min-resolution: 1.5dppx) and (min-width: 601px) and (max-width: 800px), (min-resolution: 144dpi) and (min-width: 601px) and (max-width: 800px) { + .retina-with-breakpoint { + foo: bar; + } +} diff --git a/test/cases/retina.styl b/test/cases/retina.styl new file mode 100644 index 0000000..120e3ea --- /dev/null +++ b/test/cases/retina.styl @@ -0,0 +1,12 @@ ++retina(2) + .retina-1 + foo: bar + +.retina-2 + +retina() + foo: baz + ++retina() + +at(3) + .retina-with-breakpoint + foo: bar diff --git a/test/cases/shape.css b/test/cases/shape.css index bb2e05c..c3f7def 100644 --- a/test/cases/shape.css +++ b/test/cases/shape.css @@ -56,4 +56,19 @@ border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-left: 5px solid #369; -} \ No newline at end of file +} +.test-circle-1 { + border-radius: 20px; + width: 20px; + height: 20px; +} +.test-circle-2 { + border-radius: 20px/40px; + width: 20px; + height: 40px; +} +.test-circle-3 { + border-radius: 5rem/3rem; + width: 5rem; + height: 3rem; +} diff --git a/test/cases/shape.styl b/test/cases/shape.styl index 5024bb8..4be77ce 100644 --- a/test/cases/shape.styl +++ b/test/cases/shape.styl @@ -33,3 +33,11 @@ triangle: left 5px #369 .test-triangle-5 triangle: right 5px #369 + +// circle +.test-circle-1 + circle: 20px +.test-circle-2 + circle: 20px 40px +.test-circle-3 + circle: 5rem 3rem diff --git a/test/cases/typography.css b/test/cases/typography.css index 1d40964..952b135 100644 --- a/test/cases/typography.css +++ b/test/cases/typography.css @@ -31,12 +31,6 @@ @font-face { font-family: 'rider-icon'; src: url("font/rider-icon.woff") format('woff'), url("font/rider-icon.ttf") format('truetype'); - font-weight: normal; - font-style: normal; -} -@font-face { - font-family: 'rider-icon'; - src: url("font/rider-icon.woff?88") format('woff'), url("font/rider-icon.ttf?88") format('truetype'); - font-weight: normal; + font-weight: 700; font-style: normal; } diff --git a/test/cases/typography.styl b/test/cases/typography.styl index a8bb216..85bb80c 100644 --- a/test/cases/typography.styl +++ b/test/cases/typography.styl @@ -14,10 +14,5 @@ .test-clearfix clearfix() -// font-face($font-family, $font-path, $version-suffix = '') - -// no suffix -font-face('rider-icon', 'font/rider-icon') - -// with suffix -font-face('rider-icon', 'font/rider-icon', '88') \ No newline at end of file +// font-face: found +font-face('rider-icon', 'font/rider-icon', 700) diff --git a/test/cases/unit.css b/test/cases/unit.css index 80bc7ca..14f1ca1 100644 --- a/test/cases/unit.css +++ b/test/cases/unit.css @@ -29,3 +29,12 @@ foo: 16px; foo: 8px; } +.test-decimal-places-default { + foo: 0.34375rem; +} +.test-decimal-places-custom { + foo: 0.344rem; +} +.test-change-font-size { + foo: 1.5rem; +} diff --git a/test/cases/unit.styl b/test/cases/unit.styl index c7ba37c..708c308 100644 --- a/test/cases/unit.styl +++ b/test/cases/unit.styl @@ -34,4 +34,17 @@ foo: px(1rem) foo: px(0.5rem) -// @todo: need test case when default font size is changed. +.test-decimal-places-default + foo: rem(5.5) + +// change default precision +$-unit-precision = 3 + +.test-decimal-places-custom + foo: rem(5.5) + +// change default font size +$-base-font-size = 10px + +.test-change-font-size + foo: rem(15) diff --git a/test/mocha.opts b/test/mocha.opts index 4d7bcbf..9b43d8b 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,2 +1,3 @@ --reporter spec --check-leaks +--inline-diffs diff --git a/test/test.js b/test/test.js index 0624938..3e9e834 100644 --- a/test/test.js +++ b/test/test.js @@ -1,6 +1,5 @@ /** - * rider test - * + * @file rider test * @author firede(firede@firede.us) */ @@ -8,7 +7,7 @@ var stylus = require('stylus'); var fs = require('fs'); var path = require('path'); var rider = require('../lib/rider'); -var should = require('should'); +var assert = require('assert'); var casesPath = path.join(__dirname, './cases'); @@ -25,7 +24,7 @@ describe('rider test', function () { var name = test.replace(/[-.]/g, ' '); it(name, function () { - var stylPath = path.join(__dirname, 'cases', test +'.styl'); + var stylPath = path.join(__dirname, 'cases', test + '.styl'); var cssPath = path.join(__dirname, 'cases', test + '.css'); var styl = fs.readFileSync(stylPath, 'utf8').replace(/\r/g, ''); var css = fs.readFileSync(cssPath, 'utf8').replace(/\r/g, '').trim(); @@ -36,8 +35,10 @@ describe('rider test', function () { .use(rider()); style.render(function (err, actual) { - if (err) throw err; - actual.trim().should.equal(css); + if (err) { + throw err; + } + assert.equal(actual.trim(), css); }); }); });