Skip to content

Commit bdbe496

Browse files
committed
v1 from rework-font-variant
0 parents  commit bdbe496

File tree

13 files changed

+417
-0
lines changed

13 files changed

+417
-0
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
indent_style = space
10+
indent_size = 2
11+
12+
[*.md]
13+
trim_trailing_whitespace = false
14+
15+
[Makefile]
16+
indent_style = tab

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
test/fixtures/*.actual.css

.jscsrc

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"excludeFiles": [
3+
"node_modules/**"
4+
],
5+
"fileExtensions": [
6+
".js"
7+
],
8+
"requireCurlyBraces": [
9+
"if",
10+
"else",
11+
"for",
12+
"while",
13+
"do",
14+
"try",
15+
"catch"
16+
],
17+
"requireSpaceAfterKeywords": [
18+
"if",
19+
"else",
20+
"for",
21+
"while",
22+
"do",
23+
"switch",
24+
"return",
25+
"try",
26+
"catch"
27+
],
28+
"requireSpaceBeforeBlockStatements": true,
29+
"requireParenthesesAroundIIFE": true,
30+
"requireSpacesInConditionalExpression": {
31+
"afterTest": true,
32+
"beforeConsequent": true,
33+
"afterConsequent": true,
34+
"beforeAlternate": true
35+
},
36+
"requireSpacesInFunctionExpression": {
37+
"beforeOpeningCurlyBrace": true
38+
},
39+
"disallowSpacesInFunctionExpression": {
40+
"beforeOpeningRoundBrace": true
41+
},
42+
"disallowMultipleVarDecl": true,
43+
"requireBlocksOnNewline": 1,
44+
"disallowPaddingNewlinesInBlocks": true,
45+
"disallowEmptyBlocks": true,
46+
"disallowSpacesInsideObjectBrackets": true,
47+
"disallowSpacesInsideArrayBrackets": true,
48+
"disallowSpacesInsideParentheses": true,
49+
"disallowQuotedKeysInObjects": "allButReserved",
50+
"disallowSpaceAfterObjectKeys": true,
51+
"requireCommaBeforeLineBreak": true,
52+
"requireOperatorBeforeLineBreak": [
53+
"?",
54+
"+",
55+
"-",
56+
"/",
57+
"*",
58+
"=",
59+
"==",
60+
"===",
61+
"!=",
62+
"!==",
63+
">",
64+
">=",
65+
"<",
66+
"<="
67+
],
68+
"disallowSpaceAfterPrefixUnaryOperators": [
69+
"++",
70+
"--",
71+
"+",
72+
"-",
73+
"~",
74+
"!"
75+
],
76+
"disallowSpaceBeforePostfixUnaryOperators": [
77+
"++",
78+
"--"
79+
],
80+
"requireSpaceBeforeBinaryOperators": [
81+
"+",
82+
"-",
83+
"/",
84+
"*",
85+
"=",
86+
"==",
87+
"===",
88+
"!=",
89+
"!=="
90+
],
91+
"requireSpaceAfterBinaryOperators": [
92+
"+",
93+
"-",
94+
"/",
95+
"*",
96+
"=",
97+
"==",
98+
"===",
99+
"!=",
100+
"!=="
101+
],
102+
"disallowImplicitTypeConversion": [
103+
"numeric",
104+
"boolean",
105+
"binary",
106+
"string"
107+
],
108+
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
109+
"disallowKeywords": [
110+
"with"
111+
],
112+
"disallowMultipleLineStrings": true,
113+
"validateQuoteMarks": "\"",
114+
"validateIndentation": 2,
115+
"disallowMixedSpacesAndTabs": true,
116+
"disallowTrailingWhitespace": true,
117+
"requireKeywordsOnNewLine": [
118+
"else"
119+
],
120+
"requireLineFeedAtFileEnd": true,
121+
"requireCapitalizedConstructors": true,
122+
"safeContextKeyword": "that",
123+
"requireDotNotation": true,
124+
"validateJSDoc": {
125+
"checkParamNames": true,
126+
"checkRedundantParams": true,
127+
"requireParamTypes": true
128+
},
129+
"requireSpaceAfterLineComment": true
130+
}

.jshintrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"newcap": false,
3+
"undef": true,
4+
"unused": true,
5+
"asi": true,
6+
"esnext": true,
7+
"node": true,
8+
"browser": true
9+
}

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: node_js

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 1.0.0 - 2014-10-09
2+
3+
First release based on [rework-font-variant](https://github.com/ianstormtaylor/rework-font-variant) v1.0.1

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 Maxime Thirouin & Ian Storm Taylor
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# postcss-font-variant [![Build Status](https://travis-ci.org/postcss/postcss-font-variant.png)](https://travis-ci.org/postcss/postcss-font-variant)
2+
3+
> [PostCSS](https://github.com/postcss/postcss) plugin to transform [W3C CSS font variant](http://dev.w3.org/csswg/css-fonts/#propdef-font-variant) properties to more compatible CSS (font-feature-settings).
4+
5+
## Installation
6+
7+
```console
8+
$ npm install postcss-font-variant
9+
```
10+
11+
## Usage
12+
13+
```js
14+
// dependencies
15+
var postcss = require("postcss")
16+
var fontVariant = require("postcss-font-variant")
17+
18+
// css to be processed
19+
var css = fs.readFileSync("input.css", "utf8")
20+
21+
// process css using postcss-font-variant
22+
var out = postcss()
23+
.use(fontVariant())
24+
.process(css)
25+
.css
26+
```
27+
28+
Using this `input.css`:
29+
30+
```css
31+
h2 {
32+
font-variant-caps: small-caps;
33+
}
34+
35+
table {
36+
font-variant-numeric: lining-nums;
37+
}
38+
```
39+
40+
you will get:
41+
42+
```css
43+
h2 {
44+
font-feature-settings: "c2sc";
45+
font-variant-caps: small-caps;
46+
}
47+
48+
table {
49+
font-feature-settings: "lnum";
50+
font-variant-numeric: lining-nums;
51+
}
52+
53+
```
54+
55+
Checkout [tests](test) for more examples.
56+
57+
---
58+
59+
## Contributing
60+
61+
Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.
62+
63+
$ git clone https://github.com/postcss/postcss-font-variant.git
64+
$ git checkout -b patch-1
65+
$ npm install
66+
$ npm test
67+
68+
## [Changelog](CHANGELOG.md)
69+
70+
## [License](LICENSE)

index.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* font variant convertion map
3+
*
4+
* @type {Object}
5+
*/
6+
var fontVariantProperties = {
7+
"font-variant-ligatures": {
8+
"common-ligatures": "\"liga\", \"clig\"",
9+
"no-common-ligatures": "\"liga\", \"clig off\"",
10+
"discretionary-ligatures": "\"dlig\"",
11+
"no-discretionary-ligatures": "\"dlig\" off",
12+
"historical-ligatures": "\"hlig\"",
13+
"no-historical-ligatures": "\"hlig\" off",
14+
contextual: "\"calt\"",
15+
"no-contextual": "\"calt\" off"
16+
},
17+
18+
"font-variant-position": {
19+
sub: "\"subs\"",
20+
"super": "\"sups\""
21+
},
22+
23+
"font-variant-caps": {
24+
"small-caps": "\"c2sc\"",
25+
"all-small-caps": "\"smcp\", \"c2sc\"",
26+
"petite-caps": "\"pcap\"",
27+
"all-petite-caps": "\"pcap\", \"c2pc\"",
28+
unicase: "\"unic\"",
29+
"titling-caps": "\"titl\""
30+
},
31+
32+
"font-variant-numeric": {
33+
"lining-nums": "\"lnum\"",
34+
"oldstyle-nums": "\"onum\"",
35+
"proportional-nums": "\"pnum\"",
36+
"tabular-nums": "\"tnum\"",
37+
"diagonal-fractions": "\"frac\"",
38+
"stacked-fractions": "\"afrc\"",
39+
ordinal: "\"ordn\"",
40+
"slashed-zero": "\"zero\""
41+
},
42+
43+
"font-variant": {
44+
normal: "normal",
45+
inherit: "inherit"
46+
}
47+
}
48+
49+
// The `font-variant` property is a shorthand for all the others.
50+
for (var prop in fontVariantProperties) {
51+
var keys = fontVariantProperties[prop]
52+
for (var key in keys) {
53+
fontVariantProperties["font-variant"][key] = keys[key]
54+
}
55+
}
56+
57+
/**
58+
* Expose the font-variant plugin.
59+
*/
60+
module.exports = function postcssFontVariant() {
61+
return function(styles) {
62+
// read custom media queries
63+
styles.eachDecl(function(decl) {
64+
if (!fontVariantProperties[decl.prop]) {
65+
return null
66+
}
67+
68+
var newValue = decl.value
69+
if (decl.prop === "font-variant") {
70+
newValue = decl.value.split(/\s+/g).map(function(val) {
71+
return fontVariantProperties["font-variant"][val]
72+
}).join(", ")
73+
}
74+
else if (fontVariantProperties[decl.prop][decl.value]) {
75+
newValue = fontVariantProperties[decl.prop][decl.value]
76+
}
77+
78+
var newDecl = decl.clone()
79+
newDecl.prop = "font-feature-settings"
80+
newDecl.value = newValue
81+
decl.parent.insertBefore(decl, newDecl)
82+
})
83+
}
84+
}

package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "postcss-font-variant",
3+
"version": "0.0.0",
4+
"description": "PostCSS plugin to transform W3C font-variant properties to more compatible CSS (font-feature-settings)",
5+
"keywords": [
6+
"css",
7+
"postcss",
8+
"postcss-plugins",
9+
"font",
10+
"variant",
11+
"font-variant"
12+
],
13+
"author": "Maxime Thirouin",
14+
"license": "MIT",
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/postcss/postcss-font-variant.git"
18+
},
19+
"files": [
20+
"CHANGELOG.md",
21+
"LICENSE",
22+
"index.js"
23+
],
24+
"dependencies": {},
25+
"devDependencies": {
26+
"jscs": "^1.6.2",
27+
"jshint": "^2.5.6",
28+
"postcss": "^2.2.5",
29+
"tape": "^3.0.0"
30+
},
31+
"scripts": {
32+
"lint": "jscs *.js **/*.js && jshint . --exclude-path .gitignore",
33+
"test": "npm run lint && tape test"
34+
}
35+
}

test/fixtures/font-variant.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
selector {
2+
font-variant-numeric: tabular-nums;
3+
font-variant-caps: all-small-caps;
4+
font-variant: normal;
5+
font-variant: inherit;
6+
font-variant: all-small-caps oldstyle-nums;
7+
font-variant-position: normal;
8+
}

0 commit comments

Comments
 (0)