Skip to content

Commit

Permalink
v1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
thysultan committed Feb 13, 2017
1 parent b52679d commit b85da03
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 115 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.2 (February 13, 2016)

- patch `@font-face {}`

## 1.1.1 (February 11, 2016)

- prefix `cursor: grab|grabbing|zoom-in|zoom-out;`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ stylis is a feature-rich css preprocessor


```html
<script src=https://unpkg.com/stylis@1.1.1/stylis.min.js></script>
<script src=https://unpkg.com/stylis@1.1.2/stylis.min.js></script>
```

#### npm
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
processed = processed.replace(/^.*;$/gm, format.tabs);
processed = processed.replace(/\}\n\n\}/g, '}\n}');
processed = processed.replace(/(.*@.*\{)([^\0]+\})(\n\})/g, format.block);
processed = processed.replace(/['"`].*['"`]/g, format.string);
processed = processed.replace(/['"`].*?['"`]/g, format.string);

output.innerHTML = processed;
}
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
</div>
</div>
</div>
<script src="https://unpkg.com/stylis@1.1.1/stylis.min.js"></script>

<script src="https://unpkg.com/stylis@1.1.2/stylis.min.js"></script>
<script src="assets/editor.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "stylis",
"main": "stylis.js",
"description": "stylis is a feature-rich css preprocessor",
"version": "1.1.1",
"version": "1.1.2",
"homepage": "https://github.com/thysultan/stylis.js",
"license": "MIT",
"author": {
Expand Down
221 changes: 119 additions & 102 deletions stylis.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@
var sel;

// variables
var variables;
var vars;
var varlen;

// mixins
var mixins;
Expand Down Expand Up @@ -172,8 +173,8 @@

// comments
var comment = 0;
var blockComment = 0;
var lineComment = 0;
var comblck = 0;
var comline = 0;

if (use) {
temp = middleware(0, styles, line, column, prefix);
Expand Down Expand Up @@ -249,103 +250,106 @@
flat = '';
}

// @keyframe/@global, `k` or @global, `g` character
if (second === 107 || second === 103) {
// k, @keyframes
if (second === 107) {
blob = buff.substring(1, 11) + animns + buff.substring(11);
buff = '@' + webkit + blob;
type = 1;
}
// g, @global
else {
buff = '';
}
}
// @media/@mixin `m` character
else if (second === 109) {
// @mixin
if (compact === true && third === 105) {
// first match create mixin store
if (mixins === void 0) {
mixins = {};
// ;
if (code !== 59) {
// @keyframe/@global, `k` or @global, `g` character
if (second === 107 || second === 103) {
// k, @keyframes
if (second === 107) {
blob = buff.substring(1, 11) + animns + buff.substring(11);
buff = '@' + webkit + blob;
type = 1;
}
// g, @global
else {
buff = '';
}
}
// @media/@mixin `m` character
else if (second === 109) {
// @mixin
if (compact === true && third === 105) {
// first match create mixin store
if (mixins === void 0) {
mixins = {};
}

// retrieve mixin identifier
blob = (mixin = buff.substring(7, buff.indexOf('{')) + ' ').trim();
// retrieve mixin identifier
blob = (mixin = buff.substring(7, buff.indexOf('{')) + ' ').trim();

// cache current mixin name
mixin = mixin.substring(0, mixin.indexOf(' ')).trim();
// cache current mixin name
mixin = mixin.substring(0, mixin.indexOf(' ')).trim();

// append mixin identifier
mixins[mixin] = {key: blob.trim(), body: ''};
// append mixin identifier
mixins[mixin] = {key: blob.trim(), body: ''};

type = 3;
buff = '';
blob = '';
}
// @media
else if (third === 101) {
// nested
if (depth !== 0) {
// discard first character {
caret++;

media = '';
inner = '';
selectors = prev.split(',');

// keep track of opening `{` and `}` occurrences
closed = 1;
type = 3;
buff = '';
blob = '';
}
// @media
else if (third === 101) {
// nested
if (depth !== 0) {
// discard first character {
caret++;

media = '';
inner = '';
selectors = prev.split(',');

// keep track of opening `{` and `}` occurrences
closed = 1;

// travel to the end of the block
while (caret < eof) {
char = styles.charCodeAt(caret);

// {, }, nested blocks may have nested blocks
if (char === 123) {
closed++;
}
else if (char === 125) {
closed--;
}

// travel to the end of the block
while (caret < eof) {
char = styles.charCodeAt(caret);
// break when the nested block has ended
if (closed === 0) {
break;
}

// {, }, nested blocks may have nested blocks
if (char === 123) {
closed++;
}
else if (char === 125) {
closed--;
// build content of nested block
inner += styles.charAt(caret++);
}

// break when the nested block has ended
if (closed === 0) {
break;
for (var i = 0, length = selectors.length; i < length; i++) {
selector = selectors[i];

// build media block
media += stylis(
// remove { on last selector
(i === length - 1 ? selector.substring(0, selector.length - 1) : selector).trim(),
inner,
animations,
compact,
middleware
);
}

// build content of nested block
inner += styles.charAt(caret++);
media = buff + media + '}';
buff = '';
type = 4;
}

for (var i = 0, length = selectors.length; i < length; i++) {
selector = selectors[i];

// build media block
media += stylis(
// remove { on last selector
(i === length - 1 ? selector.substring(0, selector.length - 1) : selector).trim(),
inner,
animations,
compact,
middleware
);
// top-level
else {
type = 2;
}

media = buff + media + '}';
buff = '';
type = 4;
}
// top-level
// unknown
else {
type = 2;
type = 6;
}
}
// unknown
else {
type = 6;
}
}

// @include/@import `i` character
Expand Down Expand Up @@ -420,21 +424,33 @@
}
}
}
// flag special, i.e @keyframes, @global
else if (type !== 4) {
// flag special, i.e @keyframes, @global, @font-face ...
else if (type !== 4 && code !== 59) {
// k, g, m
if (second !== 107 && second !== 103 && second !== 109) {
type = 5;
}

close = -1;
special++;
}
}
// ;, ~, ~ variables
else if (compact === true && code === 59 && first === 126 && second === 126 && (colon = buff.indexOf(':')) !== -1) {
// ~, ~, ; variables
else if (
compact === true &&
first === 126 &&
second === 126 &&
code === 59 &&
(colon = buff.indexOf(':')) !== -1
) {
// first match create variables store
if (variables === void 0) {
variables = [];
if (varlen === void 0) {
vars = [];
varlen = 0;
}

// push key value pair
variables[variables.length] = [buff.substring(0, colon), buff.substring(colon + 1, buff.length - 1).trim()];
vars[varlen++] = [buff.substring(0, colon), buff.substring(colon + 1, buff.length - 1).trim()];

// reset buffer
buff = '';
Expand Down Expand Up @@ -691,10 +707,11 @@
while (caret < eof) {
char = styles.charCodeAt(caret);

// {, }, nested blocks may have nested blocks
// {, nested blocks may have nested blocks
if (char === 123) {
closed++;
}
// },
else if (char === 125) {
closed--;
}
Expand Down Expand Up @@ -967,7 +984,7 @@
// add blck buffer to output
if (code === 125 && (type === 0 || type === 4)) {
// append if the block is not empty {}
if (blck.charCodeAt(blck.length-2) !== 123) {
if (blck.charCodeAt(blck.length - 2) !== 123) {
// middleware, block context
if (use && blck.length !== 0) {
temp = middleware(3, blck, line, column, prefix);
Expand Down Expand Up @@ -1007,8 +1024,8 @@
else {
// \r, \n, new lines
if (code === 13 || code === 10) {
if (lineComment === 1) {
comment = lineComment = 0;
if (comline === 1) {
comment = comline = 0;
buff = buff.substring(0, buff.indexOf('//'));
}

Expand Down Expand Up @@ -1052,12 +1069,12 @@
case 47: {
if (strings === 0 && func === 0) {
// /, begin line comment
if (blockComment === 0 && styles.charCodeAt(caret - 1) === 47) {
comment = lineComment = 1;
if (comblck === 0 && styles.charCodeAt(caret - 1) === 47) {
comment = comline = 1;
}
// *, end block comment
else if (styles.charCodeAt(caret - 1) === 42) {
comment = blockComment = 0;
comment = comblck = 0;
buff = buff.substring(0, buff.indexOf('/*'));
}
}
Expand All @@ -1066,10 +1083,10 @@
}
// * character
case 42: {
if (strings === 0 && func === 0 && lineComment === 0 && blockComment === 0) {
if (strings === 0 && func === 0 && comline === 0 && comblck === 0) {
// /, begin block comment
if (styles.charCodeAt(caret - 1) === 47) {
comment = blockComment = 1;
comment = comblck = 1;
}
}

Expand Down Expand Up @@ -1105,10 +1122,10 @@
}

// has variables
if (compact && variables !== void 0) {
if (compact && vars !== void 0) {
// replace all variables
for (var i = 0, length = variables.length; i < length; i++) {
output = output.replace(new RegExp('var\\('+variables[i][0]+'\\)', 'g'), variables[i][1]);
for (var i = 0; i < varlen; i++) {
output = output.replace(new RegExp('var\\(' + vars[i][0]+'\\)', 'g'), vars[i][1]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion stylis.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit b85da03

Please sign in to comment.