Comparing version 4.0.0 to 4.0.1
@@ -1,9 +0,28 @@ | ||
var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("default")?_0["default"]:_0}(); | ||
var serialize=function(){var _1=require('./serialize');return _1.hasOwnProperty("default")?_1["default"]:_1}(); | ||
'use strict'; | ||
var Token = homunculus.getClass('token', 'css'); | ||
var Node = homunculus.getClass('node', 'css'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _homunculus = require('homunculus'); | ||
var _homunculus2 = _interopRequireDefault(_homunculus); | ||
var _serialize = require('./serialize'); | ||
var _serialize2 = _interopRequireDefault(_serialize); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Token = _homunculus2.default.getClass('token', 'css'); | ||
var Node = _homunculus2.default.getClass('node', 'css'); | ||
var Jaw = function () { | ||
function Jaw() { | ||
_classCallCheck(this, Jaw); | ||
this.parser = null; | ||
@@ -13,16 +32,26 @@ this.node = null; | ||
Jaw.prototype.parse = function(code, option) { | ||
if(option===void 0)option={};this.parser = homunculus.getParser('css'); | ||
this.node = this.parser.parse(code); | ||
return serialize(this.node, option); | ||
} | ||
_createClass(Jaw, [{ | ||
key: 'parse', | ||
value: function parse(code) { | ||
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
Jaw.prototype.tokens = function() { | ||
return this.ast ? this.parser.lexer.tokens() : null; | ||
} | ||
Jaw.prototype.ast = function() { | ||
return this.node; | ||
} | ||
this.parser = _homunculus2.default.getParser('css'); | ||
this.node = this.parser.parse(code); | ||
return (0, _serialize2.default)(this.node, option); | ||
} | ||
}, { | ||
key: 'tokens', | ||
value: function tokens() { | ||
return this.ast ? this.parser.lexer.tokens() : null; | ||
} | ||
}, { | ||
key: 'ast', | ||
value: function ast() { | ||
return this.node; | ||
} | ||
}]); | ||
return Jaw; | ||
}(); | ||
exports["default"]=new Jaw(); | ||
exports.default = new Jaw(); |
@@ -1,5 +0,21 @@ | ||
var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("default")?_0["default"]:_0}(); | ||
'use strict'; | ||
var Token = homunculus.getClass('token', 'jsx'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = function (node, excludeLine) { | ||
res = ''; | ||
recursion(node, excludeLine); | ||
return res; | ||
}; | ||
var _homunculus = require('homunculus'); | ||
var _homunculus2 = _interopRequireDefault(_homunculus); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Token = _homunculus2.default.getClass('token', 'jsx'); | ||
var S = {}; | ||
@@ -12,13 +28,13 @@ S[Token.LINE] = S[Token.COMMENT] = S[Token.BLANK] = true; | ||
function recursion(node, excludeLine) { | ||
if(node.isToken()) { | ||
if (node.isToken()) { | ||
var token = node.token(); | ||
if(!token.isVirtual()) { | ||
if (!token.isVirtual()) { | ||
res += token.content(); | ||
while(token.next()) { | ||
while (token.next()) { | ||
token = token.next(); | ||
if(token.isVirtual() || !S.hasOwnProperty(token.type())) { | ||
if (token.isVirtual() || !S.hasOwnProperty(token.type())) { | ||
break; | ||
} | ||
var s = token.content(); | ||
if(!excludeLine || s != '\n') { | ||
if (!excludeLine || s != '\n') { | ||
res += token.content(); | ||
@@ -28,14 +44,7 @@ } | ||
} | ||
} | ||
else { | ||
node.leaves().forEach(function(leaf) { | ||
} else { | ||
node.leaves().forEach(function (leaf) { | ||
recursion(leaf, excludeLine); | ||
}); | ||
} | ||
} | ||
exports["default"]=function(node, excludeLine) { | ||
res = ''; | ||
recursion(node, excludeLine); | ||
return res; | ||
} |
@@ -1,8 +0,24 @@ | ||
var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("default")?_0["default"]:_0}(); | ||
var join=function(){var _1=require('./join');return _1.hasOwnProperty("default")?_1["default"]:_1}(); | ||
var sort=function(){var _2=require('./sort');return _2.hasOwnProperty("default")?_2["default"]:_2}(); | ||
'use strict'; | ||
var Token = homunculus.getClass('token', 'css'); | ||
var Node = homunculus.getClass('node', 'css'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _homunculus = require('homunculus'); | ||
var _homunculus2 = _interopRequireDefault(_homunculus); | ||
var _join = require('./join'); | ||
var _join2 = _interopRequireDefault(_join); | ||
var _sort = require('./sort'); | ||
var _sort2 = _interopRequireDefault(_sort); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Token = _homunculus2.default.getClass('token', 'css'); | ||
var Node = _homunculus2.default.getClass('node', 'css'); | ||
var idx; | ||
@@ -15,7 +31,6 @@ | ||
}; | ||
node.leaves().forEach(function(leaf, i) { | ||
if(leaf.name() == Node.STYLESET) { | ||
node.leaves().forEach(function (leaf, i) { | ||
if (leaf.name() == Node.STYLESET) { | ||
styleset(leaf, option.noMedia ? res : res.default, option); | ||
} | ||
else if(leaf.name() == Node.MEDIA) { | ||
} else if (leaf.name() == Node.MEDIA) { | ||
res.media = res.media || []; | ||
@@ -25,4 +40,4 @@ var item = {}; | ||
var qlist = leaf.leaf(1); | ||
qlist.leaves().forEach(function(leaf) { | ||
if(leaf.name() == Node.MEDIAQUERY) { | ||
qlist.leaves().forEach(function (leaf) { | ||
if (leaf.name() == Node.MEDIAQUERY) { | ||
query(leaf, item); | ||
@@ -34,5 +49,5 @@ } | ||
var leaves = block.leaves(); | ||
if(leaves.length > 2) { | ||
if (leaves.length > 2) { | ||
var style = {}; | ||
for(var i = 1, len = leaves.length - 1; i < len; i++) { | ||
for (var i = 1, len = leaves.length - 1; i < len; i++) { | ||
styleset(leaves[i], style, option); | ||
@@ -42,3 +57,3 @@ } | ||
} | ||
if(item.style) { | ||
if (item.style) { | ||
res.media.push(item); | ||
@@ -54,12 +69,12 @@ } | ||
var query = []; | ||
leaves.forEach(function(leaf) { | ||
if(leaf.name() == Node.EXPR) { | ||
leaves.forEach(function (leaf) { | ||
if (leaf.name() == Node.EXPR) { | ||
var expr = []; | ||
leaf.leaves().forEach(function(item) { | ||
if(item.name() == Node.KEY || item.name() == Node.VALUE) { | ||
expr.push(join(item, true)); | ||
leaf.leaves().forEach(function (item) { | ||
if (item.name() == Node.KEY || item.name() == Node.VALUE) { | ||
expr.push((0, _join2.default)(item, true)); | ||
} | ||
}); | ||
//可能只有key或者k/v都有,以String/Array格式区分 | ||
if(expr.length) { | ||
if (expr.length) { | ||
query.push(expr.length > 1 ? expr : expr[0]); | ||
@@ -77,3 +92,3 @@ } | ||
var i = idx++; | ||
sels.forEach(function(sel) { | ||
sels.forEach(function (sel) { | ||
record(sel, i, styles, res, option); | ||
@@ -84,4 +99,4 @@ }); | ||
var res = []; | ||
node.leaves().forEach(function(leaf) { | ||
if(leaf.name() == Node.SELECTOR) { | ||
node.leaves().forEach(function (leaf) { | ||
if (leaf.name() == Node.SELECTOR) { | ||
res.push(selector(leaf)); | ||
@@ -93,3 +108,3 @@ } | ||
function selector(node) { | ||
return node.leaves().map(function(leaf) { | ||
return node.leaves().map(function (leaf) { | ||
return leaf.token(); | ||
@@ -100,4 +115,4 @@ }); | ||
var res = []; | ||
node.leaves().forEach(function(leaf) { | ||
if(leaf.name() == Node.STYLE) { | ||
node.leaves().forEach(function (leaf) { | ||
if (leaf.name() == Node.STYLE) { | ||
res.push(style(leaf)); | ||
@@ -109,3 +124,3 @@ } | ||
function style(node) { | ||
var s = join(node, true).trim(); | ||
var s = (0, _join2.default)(node, true).trim(); | ||
s = s.replace(/;$/, ''); | ||
@@ -117,3 +132,3 @@ return s; | ||
var _p = [0, 0, 0]; | ||
for(var i = sel.length - 1; i >= 0; i--) { | ||
for (var i = sel.length - 1; i >= 0; i--) { | ||
var temp = { | ||
@@ -127,3 +142,3 @@ s: [], | ||
priority(t, s, _p); | ||
switch(t.type()) { | ||
switch (t.type()) { | ||
case Token.SELECTOR: | ||
@@ -134,6 +149,6 @@ temp.s.push(s); | ||
var s2 = s.replace(/^:+/, ''); | ||
if(sel[i].content() == '(') { | ||
if (sel[i].content() == '(') { | ||
s2 += '('; | ||
for(var j = i + 1; j < sel.length; j++) { | ||
if(sel[j].content() == ')') { | ||
for (var j = i + 1; j < sel.length; j++) { | ||
if (sel[j].content() == ')') { | ||
s2 += ')'; | ||
@@ -148,3 +163,3 @@ break; | ||
case Token.SIGN: | ||
switch(s) { | ||
switch (s) { | ||
case ']': | ||
@@ -154,5 +169,5 @@ var item = []; | ||
t = t.prev(); | ||
while(t) { | ||
while (t) { | ||
s = t.content(); | ||
if(s == '[') { | ||
if (s == '[') { | ||
break; | ||
@@ -181,5 +196,5 @@ } | ||
t = t.prev(); | ||
while(t) { | ||
while (t) { | ||
s = t.content(); | ||
if(s == '(') { | ||
if (s == '(') { | ||
break; | ||
@@ -195,6 +210,6 @@ } | ||
t = t.prev(); | ||
while(t && !isSplit(t)) { | ||
while (t && !isSplit(t)) { | ||
s = t.content(); | ||
priority(t, s, _p); | ||
switch(t.type()) { | ||
switch (t.type()) { | ||
case Token.SELECTOR: | ||
@@ -205,6 +220,6 @@ temp.s.push(s); | ||
var s2 = s.replace(/^:+/, ''); | ||
if(sel[i].content() == '(') { | ||
if (sel[i].content() == '(') { | ||
s2 += '('; | ||
for(var j = i + 1; j < sel.length; j++) { | ||
if(sel[j].content() == ')') { | ||
for (var j = i + 1; j < sel.length; j++) { | ||
if (sel[j].content() == ')') { | ||
s2 += ')'; | ||
@@ -219,3 +234,3 @@ break; | ||
case Token.SIGN: | ||
switch(s) { | ||
switch (s) { | ||
case ']': | ||
@@ -225,5 +240,5 @@ var item = []; | ||
t = t.prev(); | ||
while(t) { | ||
while (t) { | ||
s = t.content(); | ||
if(s == '[') { | ||
if (s == '[') { | ||
break; | ||
@@ -252,5 +267,5 @@ } | ||
t = t.prev(); | ||
while(t) { | ||
while (t) { | ||
s = t.content(); | ||
if(s == '(') { | ||
if (s == '(') { | ||
break; | ||
@@ -270,12 +285,11 @@ } | ||
} | ||
if(option.noValue) { | ||
if (option.noValue) { | ||
res._v = true; | ||
} | ||
else { | ||
} else { | ||
res._v = res._v || []; | ||
styles.forEach(function(style) { | ||
styles.forEach(function (style) { | ||
res._v.push([idx, style]); | ||
}); | ||
} | ||
if(!option.noPriority) { | ||
if (!option.noPriority) { | ||
res._p = _p; | ||
@@ -286,11 +300,9 @@ } | ||
function priority(token, s, p) { | ||
switch(token.type()) { | ||
switch (token.type()) { | ||
case Token.SELECTOR: | ||
if(s.charAt(0) == '#') { | ||
if (s.charAt(0) == '#') { | ||
p[0]++; | ||
} | ||
else if(s.charAt(0) == '.') { | ||
} else if (s.charAt(0) == '.') { | ||
p[1]++; | ||
} | ||
else { | ||
} else { | ||
p[2]++; | ||
@@ -303,3 +315,3 @@ } | ||
case Token.SIGN: | ||
if(s == ']') { | ||
if (s == ']') { | ||
p[1]++; | ||
@@ -312,9 +324,9 @@ } | ||
function isSplit(token) { | ||
if(token.type() == Token.BLANK) { | ||
if (token.type() == Token.BLANK) { | ||
return true; | ||
} | ||
if(token.type() == Token.LINE) { | ||
if (token.type() == Token.LINE) { | ||
return true; | ||
} | ||
if(token.type() == Token.SIGN) { | ||
if (token.type() == Token.SIGN) { | ||
return ['>', '+', '~', '{', '}', ','].indexOf(token.content()) > -1; | ||
@@ -326,7 +338,7 @@ } | ||
function save(temp, res) { | ||
if(!temp.s.length) { | ||
if (!temp.s.length) { | ||
temp.s.push('*'); | ||
} | ||
//selector按name/class/id排序 | ||
sort(temp.s, function(a, b) { | ||
(0, _sort2.default)(temp.s, function (a, b) { | ||
return a != '*' && a < b || b == '*'; | ||
@@ -336,12 +348,10 @@ }); | ||
//*开头有几种组合,记录之 | ||
if(star) { | ||
if (star) { | ||
res['_*'] = true; | ||
if(temp.s.length > 1) { | ||
if(temp.s.length > 2) { | ||
if (temp.s.length > 1) { | ||
if (temp.s.length > 2) { | ||
res['_*.#'] = true; | ||
} | ||
else if(temp.s[1][0] == '.') { | ||
} else if (temp.s[1][0] == '.') { | ||
res['_*.'] = true; | ||
} | ||
else { | ||
} else { | ||
res['_*#'] = true; | ||
@@ -355,9 +365,9 @@ } | ||
//伪类 | ||
if(temp.p.length) { | ||
if (temp.p.length) { | ||
res['_:'] = res['_:'] || []; | ||
var pseudos = res['_:']; | ||
var pseudo = []; | ||
temp.p.forEach(function(item) { | ||
temp.p.forEach(function (item) { | ||
//防止多次重复 | ||
if(pseudo.indexOf(item) == -1) { | ||
if (pseudo.indexOf(item) == -1) { | ||
pseudo.push(item); | ||
@@ -367,8 +377,8 @@ } | ||
//排序后比对,可能重复,合并之如a:hover{...}a:hover{...}会生成2个hover数组 | ||
sort(pseudo, function(a, b) { | ||
(0, _sort2.default)(pseudo, function (a, b) { | ||
return a < b; | ||
}); | ||
var isExist = -1; | ||
for(var j = 0, len = pseudos.length; j < len; j++) { | ||
if(pseudos[j][0].join(',') == pseudo.join(',')) { | ||
for (var j = 0, len = pseudos.length; j < len; j++) { | ||
if (pseudos[j][0].join(',') == pseudo.join(',')) { | ||
isExist = j; | ||
@@ -378,6 +388,5 @@ break; | ||
} | ||
if(isExist > -1) { | ||
if (isExist > -1) { | ||
res = pseudos[isExist][1]; | ||
} | ||
else { | ||
} else { | ||
var arr = []; | ||
@@ -391,3 +400,3 @@ arr.push(pseudo); | ||
//属性 | ||
if(temp.a.length) { | ||
if (temp.a.length) { | ||
res['_['] = res['_['] || []; | ||
@@ -397,8 +406,8 @@ var attrs = res['_[']; | ||
//去重并排序 | ||
sort(temp.a, function(a, b) { | ||
(0, _sort2.default)(temp.a, function (a, b) { | ||
return a.s < b.s; | ||
}); | ||
var hash = {}; | ||
temp.a.forEach(function(item) { | ||
if(!hash.hasOwnProperty(item.s)) { | ||
temp.a.forEach(function (item) { | ||
if (!hash.hasOwnProperty(item.s)) { | ||
attr.push(item.v); | ||
@@ -409,11 +418,11 @@ } | ||
var join = ''; | ||
join += attr.map(function(item) { | ||
join += attr.map(function (item) { | ||
return item.join(''); | ||
}); | ||
for(var j = 0, len = attrs.length; j < len; j++) { | ||
for (var j = 0, len = attrs.length; j < len; j++) { | ||
var s1 = ''; | ||
s1 += attrs[j][0].map(function(item) { | ||
s1 += attrs[j][0].map(function (item) { | ||
return item.join(''); | ||
}); | ||
if(s1 == join) { | ||
if (s1 == join) { | ||
isExist = j; | ||
@@ -423,6 +432,5 @@ break; | ||
} | ||
if(isExist > -1) { | ||
if (isExist > -1) { | ||
res = attrs[isExist][1]; | ||
} | ||
else { | ||
} else { | ||
var arr = []; | ||
@@ -438,2 +446,2 @@ arr.push(attr); | ||
exports["default"]=parse; | ||
exports.default = parse; |
@@ -0,11 +1,16 @@ | ||
'use strict'; | ||
function quickSort(arr, begin, end, compare) { | ||
if(begin >= end) { | ||
if (begin >= end) { | ||
return; | ||
} | ||
var i = begin, j = end, p = i, n = arr[p], seq = true; | ||
outer: | ||
while(i < j) { | ||
if(seq) { | ||
for(; i < j; j--) { | ||
if((compare && compare.call(arr, n, arr[j])) || (!compare && n > arr[j])) { | ||
var i = begin, | ||
j = end, | ||
p = i, | ||
n = arr[p], | ||
seq = true; | ||
outer: while (i < j) { | ||
if (seq) { | ||
for (; i < j; j--) { | ||
if (compare && compare.call(arr, n, arr[j]) || !compare && n > arr[j]) { | ||
swap(arr, p, j); | ||
@@ -17,6 +22,5 @@ p = j; | ||
} | ||
} | ||
else { | ||
for(; i < j; i++) { | ||
if((compare && compare.call(arr, arr[i], n)) || (!compare && n < arr[i])) { | ||
} else { | ||
for (; i < j; i++) { | ||
if (compare && compare.call(arr, arr[i], n) || !compare && n < arr[i]) { | ||
swap(arr, p, i); | ||
@@ -39,7 +43,7 @@ p = i; | ||
module.exports = function(arr, compare) { | ||
if(!Array.isArray(arr)) { | ||
module.exports = function (arr, compare) { | ||
if (!Array.isArray(arr)) { | ||
throw new Error('quick sort need an array'); | ||
} | ||
if(arr.length < 2) { | ||
if (arr.length < 2) { | ||
return arr; | ||
@@ -46,0 +50,0 @@ } |
{ | ||
"name": "jaw", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Parasitize CSS to JSX for migi", | ||
@@ -37,2 +37,4 @@ "maintainers": [ | ||
"devDependencies": { | ||
"babel-core": "^6.26.3", | ||
"babel-preset-es2015": "^6.24.1", | ||
"blanket": "^1.1.6", | ||
@@ -42,8 +44,7 @@ "coveralls": "^2.11.2", | ||
"gulp": "^3.9.0", | ||
"gulp-clean": "^0.3.1", | ||
"gulp-rimraf": "^0.2.2", | ||
"gulp-util": "^3.0.1", | ||
"mocha": "^2.2.4", | ||
"mocha-lcov-reporter": "^0.0.2", | ||
"through2": "^2.0.0", | ||
"jsdc": "^0.6.9" | ||
"through2": "^2.0.0" | ||
}, | ||
@@ -50,0 +51,0 @@ "main": "./index", |
@@ -1,9 +0,28 @@ | ||
define(function(require, exports, module){var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("default")?_0["default"]:_0}(); | ||
var serialize=function(){var _1=require('./serialize');return _1.hasOwnProperty("default")?_1["default"]:_1}(); | ||
define(function(require, exports, module){'use strict'; | ||
var Token = homunculus.getClass('token', 'css'); | ||
var Node = homunculus.getClass('node', 'css'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _homunculus = require('homunculus'); | ||
var _homunculus2 = _interopRequireDefault(_homunculus); | ||
var _serialize = require('./serialize'); | ||
var _serialize2 = _interopRequireDefault(_serialize); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var Token = _homunculus2.default.getClass('token', 'css'); | ||
var Node = _homunculus2.default.getClass('node', 'css'); | ||
var Jaw = function () { | ||
function Jaw() { | ||
_classCallCheck(this, Jaw); | ||
this.parser = null; | ||
@@ -13,16 +32,26 @@ this.node = null; | ||
Jaw.prototype.parse = function(code, option) { | ||
if(option===void 0)option={};this.parser = homunculus.getParser('css'); | ||
this.node = this.parser.parse(code); | ||
return serialize(this.node, option); | ||
} | ||
_createClass(Jaw, [{ | ||
key: 'parse', | ||
value: function parse(code) { | ||
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
Jaw.prototype.tokens = function() { | ||
return this.ast ? this.parser.lexer.tokens() : null; | ||
} | ||
Jaw.prototype.ast = function() { | ||
return this.node; | ||
} | ||
this.parser = _homunculus2.default.getParser('css'); | ||
this.node = this.parser.parse(code); | ||
return (0, _serialize2.default)(this.node, option); | ||
} | ||
}, { | ||
key: 'tokens', | ||
value: function tokens() { | ||
return this.ast ? this.parser.lexer.tokens() : null; | ||
} | ||
}, { | ||
key: 'ast', | ||
value: function ast() { | ||
return this.node; | ||
} | ||
}]); | ||
return Jaw; | ||
}(); | ||
exports["default"]=new Jaw();}); | ||
exports.default = new Jaw();}); |
@@ -1,5 +0,21 @@ | ||
define(function(require, exports, module){var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("default")?_0["default"]:_0}(); | ||
define(function(require, exports, module){'use strict'; | ||
var Token = homunculus.getClass('token', 'jsx'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = function (node, excludeLine) { | ||
res = ''; | ||
recursion(node, excludeLine); | ||
return res; | ||
}; | ||
var _homunculus = require('homunculus'); | ||
var _homunculus2 = _interopRequireDefault(_homunculus); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Token = _homunculus2.default.getClass('token', 'jsx'); | ||
var S = {}; | ||
@@ -12,13 +28,13 @@ S[Token.LINE] = S[Token.COMMENT] = S[Token.BLANK] = true; | ||
function recursion(node, excludeLine) { | ||
if(node.isToken()) { | ||
if (node.isToken()) { | ||
var token = node.token(); | ||
if(!token.isVirtual()) { | ||
if (!token.isVirtual()) { | ||
res += token.content(); | ||
while(token.next()) { | ||
while (token.next()) { | ||
token = token.next(); | ||
if(token.isVirtual() || !S.hasOwnProperty(token.type())) { | ||
if (token.isVirtual() || !S.hasOwnProperty(token.type())) { | ||
break; | ||
} | ||
var s = token.content(); | ||
if(!excludeLine || s != '\n') { | ||
if (!excludeLine || s != '\n') { | ||
res += token.content(); | ||
@@ -28,14 +44,7 @@ } | ||
} | ||
} | ||
else { | ||
node.leaves().forEach(function(leaf) { | ||
} else { | ||
node.leaves().forEach(function (leaf) { | ||
recursion(leaf, excludeLine); | ||
}); | ||
} | ||
} | ||
exports["default"]=function(node, excludeLine) { | ||
res = ''; | ||
recursion(node, excludeLine); | ||
return res; | ||
}}); |
@@ -1,8 +0,24 @@ | ||
define(function(require, exports, module){var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("default")?_0["default"]:_0}(); | ||
var join=function(){var _1=require('./join');return _1.hasOwnProperty("default")?_1["default"]:_1}(); | ||
var sort=function(){var _2=require('./sort');return _2.hasOwnProperty("default")?_2["default"]:_2}(); | ||
define(function(require, exports, module){'use strict'; | ||
var Token = homunculus.getClass('token', 'css'); | ||
var Node = homunculus.getClass('node', 'css'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _homunculus = require('homunculus'); | ||
var _homunculus2 = _interopRequireDefault(_homunculus); | ||
var _join = require('./join'); | ||
var _join2 = _interopRequireDefault(_join); | ||
var _sort = require('./sort'); | ||
var _sort2 = _interopRequireDefault(_sort); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Token = _homunculus2.default.getClass('token', 'css'); | ||
var Node = _homunculus2.default.getClass('node', 'css'); | ||
var idx; | ||
@@ -15,7 +31,6 @@ | ||
}; | ||
node.leaves().forEach(function(leaf, i) { | ||
if(leaf.name() == Node.STYLESET) { | ||
node.leaves().forEach(function (leaf, i) { | ||
if (leaf.name() == Node.STYLESET) { | ||
styleset(leaf, option.noMedia ? res : res.default, option); | ||
} | ||
else if(leaf.name() == Node.MEDIA) { | ||
} else if (leaf.name() == Node.MEDIA) { | ||
res.media = res.media || []; | ||
@@ -25,4 +40,4 @@ var item = {}; | ||
var qlist = leaf.leaf(1); | ||
qlist.leaves().forEach(function(leaf) { | ||
if(leaf.name() == Node.MEDIAQUERY) { | ||
qlist.leaves().forEach(function (leaf) { | ||
if (leaf.name() == Node.MEDIAQUERY) { | ||
query(leaf, item); | ||
@@ -34,5 +49,5 @@ } | ||
var leaves = block.leaves(); | ||
if(leaves.length > 2) { | ||
if (leaves.length > 2) { | ||
var style = {}; | ||
for(var i = 1, len = leaves.length - 1; i < len; i++) { | ||
for (var i = 1, len = leaves.length - 1; i < len; i++) { | ||
styleset(leaves[i], style, option); | ||
@@ -42,3 +57,3 @@ } | ||
} | ||
if(item.style) { | ||
if (item.style) { | ||
res.media.push(item); | ||
@@ -54,12 +69,12 @@ } | ||
var query = []; | ||
leaves.forEach(function(leaf) { | ||
if(leaf.name() == Node.EXPR) { | ||
leaves.forEach(function (leaf) { | ||
if (leaf.name() == Node.EXPR) { | ||
var expr = []; | ||
leaf.leaves().forEach(function(item) { | ||
if(item.name() == Node.KEY || item.name() == Node.VALUE) { | ||
expr.push(join(item, true)); | ||
leaf.leaves().forEach(function (item) { | ||
if (item.name() == Node.KEY || item.name() == Node.VALUE) { | ||
expr.push((0, _join2.default)(item, true)); | ||
} | ||
}); | ||
//可能只有key或者k/v都有,以String/Array格式区分 | ||
if(expr.length) { | ||
if (expr.length) { | ||
query.push(expr.length > 1 ? expr : expr[0]); | ||
@@ -77,3 +92,3 @@ } | ||
var i = idx++; | ||
sels.forEach(function(sel) { | ||
sels.forEach(function (sel) { | ||
record(sel, i, styles, res, option); | ||
@@ -84,4 +99,4 @@ }); | ||
var res = []; | ||
node.leaves().forEach(function(leaf) { | ||
if(leaf.name() == Node.SELECTOR) { | ||
node.leaves().forEach(function (leaf) { | ||
if (leaf.name() == Node.SELECTOR) { | ||
res.push(selector(leaf)); | ||
@@ -93,3 +108,3 @@ } | ||
function selector(node) { | ||
return node.leaves().map(function(leaf) { | ||
return node.leaves().map(function (leaf) { | ||
return leaf.token(); | ||
@@ -100,4 +115,4 @@ }); | ||
var res = []; | ||
node.leaves().forEach(function(leaf) { | ||
if(leaf.name() == Node.STYLE) { | ||
node.leaves().forEach(function (leaf) { | ||
if (leaf.name() == Node.STYLE) { | ||
res.push(style(leaf)); | ||
@@ -109,3 +124,3 @@ } | ||
function style(node) { | ||
var s = join(node, true).trim(); | ||
var s = (0, _join2.default)(node, true).trim(); | ||
s = s.replace(/;$/, ''); | ||
@@ -117,3 +132,3 @@ return s; | ||
var _p = [0, 0, 0]; | ||
for(var i = sel.length - 1; i >= 0; i--) { | ||
for (var i = sel.length - 1; i >= 0; i--) { | ||
var temp = { | ||
@@ -127,3 +142,3 @@ s: [], | ||
priority(t, s, _p); | ||
switch(t.type()) { | ||
switch (t.type()) { | ||
case Token.SELECTOR: | ||
@@ -134,6 +149,6 @@ temp.s.push(s); | ||
var s2 = s.replace(/^:+/, ''); | ||
if(sel[i].content() == '(') { | ||
if (sel[i].content() == '(') { | ||
s2 += '('; | ||
for(var j = i + 1; j < sel.length; j++) { | ||
if(sel[j].content() == ')') { | ||
for (var j = i + 1; j < sel.length; j++) { | ||
if (sel[j].content() == ')') { | ||
s2 += ')'; | ||
@@ -148,3 +163,3 @@ break; | ||
case Token.SIGN: | ||
switch(s) { | ||
switch (s) { | ||
case ']': | ||
@@ -154,5 +169,5 @@ var item = []; | ||
t = t.prev(); | ||
while(t) { | ||
while (t) { | ||
s = t.content(); | ||
if(s == '[') { | ||
if (s == '[') { | ||
break; | ||
@@ -181,5 +196,5 @@ } | ||
t = t.prev(); | ||
while(t) { | ||
while (t) { | ||
s = t.content(); | ||
if(s == '(') { | ||
if (s == '(') { | ||
break; | ||
@@ -195,6 +210,6 @@ } | ||
t = t.prev(); | ||
while(t && !isSplit(t)) { | ||
while (t && !isSplit(t)) { | ||
s = t.content(); | ||
priority(t, s, _p); | ||
switch(t.type()) { | ||
switch (t.type()) { | ||
case Token.SELECTOR: | ||
@@ -205,6 +220,6 @@ temp.s.push(s); | ||
var s2 = s.replace(/^:+/, ''); | ||
if(sel[i].content() == '(') { | ||
if (sel[i].content() == '(') { | ||
s2 += '('; | ||
for(var j = i + 1; j < sel.length; j++) { | ||
if(sel[j].content() == ')') { | ||
for (var j = i + 1; j < sel.length; j++) { | ||
if (sel[j].content() == ')') { | ||
s2 += ')'; | ||
@@ -219,3 +234,3 @@ break; | ||
case Token.SIGN: | ||
switch(s) { | ||
switch (s) { | ||
case ']': | ||
@@ -225,5 +240,5 @@ var item = []; | ||
t = t.prev(); | ||
while(t) { | ||
while (t) { | ||
s = t.content(); | ||
if(s == '[') { | ||
if (s == '[') { | ||
break; | ||
@@ -252,5 +267,5 @@ } | ||
t = t.prev(); | ||
while(t) { | ||
while (t) { | ||
s = t.content(); | ||
if(s == '(') { | ||
if (s == '(') { | ||
break; | ||
@@ -270,12 +285,11 @@ } | ||
} | ||
if(option.noValue) { | ||
if (option.noValue) { | ||
res._v = true; | ||
} | ||
else { | ||
} else { | ||
res._v = res._v || []; | ||
styles.forEach(function(style) { | ||
styles.forEach(function (style) { | ||
res._v.push([idx, style]); | ||
}); | ||
} | ||
if(!option.noPriority) { | ||
if (!option.noPriority) { | ||
res._p = _p; | ||
@@ -286,11 +300,9 @@ } | ||
function priority(token, s, p) { | ||
switch(token.type()) { | ||
switch (token.type()) { | ||
case Token.SELECTOR: | ||
if(s.charAt(0) == '#') { | ||
if (s.charAt(0) == '#') { | ||
p[0]++; | ||
} | ||
else if(s.charAt(0) == '.') { | ||
} else if (s.charAt(0) == '.') { | ||
p[1]++; | ||
} | ||
else { | ||
} else { | ||
p[2]++; | ||
@@ -303,3 +315,3 @@ } | ||
case Token.SIGN: | ||
if(s == ']') { | ||
if (s == ']') { | ||
p[1]++; | ||
@@ -312,9 +324,9 @@ } | ||
function isSplit(token) { | ||
if(token.type() == Token.BLANK) { | ||
if (token.type() == Token.BLANK) { | ||
return true; | ||
} | ||
if(token.type() == Token.LINE) { | ||
if (token.type() == Token.LINE) { | ||
return true; | ||
} | ||
if(token.type() == Token.SIGN) { | ||
if (token.type() == Token.SIGN) { | ||
return ['>', '+', '~', '{', '}', ','].indexOf(token.content()) > -1; | ||
@@ -326,7 +338,7 @@ } | ||
function save(temp, res) { | ||
if(!temp.s.length) { | ||
if (!temp.s.length) { | ||
temp.s.push('*'); | ||
} | ||
//selector按name/class/id排序 | ||
sort(temp.s, function(a, b) { | ||
(0, _sort2.default)(temp.s, function (a, b) { | ||
return a != '*' && a < b || b == '*'; | ||
@@ -336,12 +348,10 @@ }); | ||
//*开头有几种组合,记录之 | ||
if(star) { | ||
if (star) { | ||
res['_*'] = true; | ||
if(temp.s.length > 1) { | ||
if(temp.s.length > 2) { | ||
if (temp.s.length > 1) { | ||
if (temp.s.length > 2) { | ||
res['_*.#'] = true; | ||
} | ||
else if(temp.s[1][0] == '.') { | ||
} else if (temp.s[1][0] == '.') { | ||
res['_*.'] = true; | ||
} | ||
else { | ||
} else { | ||
res['_*#'] = true; | ||
@@ -355,9 +365,9 @@ } | ||
//伪类 | ||
if(temp.p.length) { | ||
if (temp.p.length) { | ||
res['_:'] = res['_:'] || []; | ||
var pseudos = res['_:']; | ||
var pseudo = []; | ||
temp.p.forEach(function(item) { | ||
temp.p.forEach(function (item) { | ||
//防止多次重复 | ||
if(pseudo.indexOf(item) == -1) { | ||
if (pseudo.indexOf(item) == -1) { | ||
pseudo.push(item); | ||
@@ -367,8 +377,8 @@ } | ||
//排序后比对,可能重复,合并之如a:hover{...}a:hover{...}会生成2个hover数组 | ||
sort(pseudo, function(a, b) { | ||
(0, _sort2.default)(pseudo, function (a, b) { | ||
return a < b; | ||
}); | ||
var isExist = -1; | ||
for(var j = 0, len = pseudos.length; j < len; j++) { | ||
if(pseudos[j][0].join(',') == pseudo.join(',')) { | ||
for (var j = 0, len = pseudos.length; j < len; j++) { | ||
if (pseudos[j][0].join(',') == pseudo.join(',')) { | ||
isExist = j; | ||
@@ -378,6 +388,5 @@ break; | ||
} | ||
if(isExist > -1) { | ||
if (isExist > -1) { | ||
res = pseudos[isExist][1]; | ||
} | ||
else { | ||
} else { | ||
var arr = []; | ||
@@ -391,3 +400,3 @@ arr.push(pseudo); | ||
//属性 | ||
if(temp.a.length) { | ||
if (temp.a.length) { | ||
res['_['] = res['_['] || []; | ||
@@ -397,8 +406,8 @@ var attrs = res['_[']; | ||
//去重并排序 | ||
sort(temp.a, function(a, b) { | ||
(0, _sort2.default)(temp.a, function (a, b) { | ||
return a.s < b.s; | ||
}); | ||
var hash = {}; | ||
temp.a.forEach(function(item) { | ||
if(!hash.hasOwnProperty(item.s)) { | ||
temp.a.forEach(function (item) { | ||
if (!hash.hasOwnProperty(item.s)) { | ||
attr.push(item.v); | ||
@@ -409,11 +418,11 @@ } | ||
var join = ''; | ||
join += attr.map(function(item) { | ||
join += attr.map(function (item) { | ||
return item.join(''); | ||
}); | ||
for(var j = 0, len = attrs.length; j < len; j++) { | ||
for (var j = 0, len = attrs.length; j < len; j++) { | ||
var s1 = ''; | ||
s1 += attrs[j][0].map(function(item) { | ||
s1 += attrs[j][0].map(function (item) { | ||
return item.join(''); | ||
}); | ||
if(s1 == join) { | ||
if (s1 == join) { | ||
isExist = j; | ||
@@ -423,6 +432,5 @@ break; | ||
} | ||
if(isExist > -1) { | ||
if (isExist > -1) { | ||
res = attrs[isExist][1]; | ||
} | ||
else { | ||
} else { | ||
var arr = []; | ||
@@ -438,2 +446,2 @@ arr.push(attr); | ||
exports["default"]=parse;}); | ||
exports.default = parse;}); |
@@ -1,11 +0,16 @@ | ||
define(function(require, exports, module){function quickSort(arr, begin, end, compare) { | ||
if(begin >= end) { | ||
define(function(require, exports, module){'use strict'; | ||
function quickSort(arr, begin, end, compare) { | ||
if (begin >= end) { | ||
return; | ||
} | ||
var i = begin, j = end, p = i, n = arr[p], seq = true; | ||
outer: | ||
while(i < j) { | ||
if(seq) { | ||
for(; i < j; j--) { | ||
if((compare && compare.call(arr, n, arr[j])) || (!compare && n > arr[j])) { | ||
var i = begin, | ||
j = end, | ||
p = i, | ||
n = arr[p], | ||
seq = true; | ||
outer: while (i < j) { | ||
if (seq) { | ||
for (; i < j; j--) { | ||
if (compare && compare.call(arr, n, arr[j]) || !compare && n > arr[j]) { | ||
swap(arr, p, j); | ||
@@ -17,6 +22,5 @@ p = j; | ||
} | ||
} | ||
else { | ||
for(; i < j; i++) { | ||
if((compare && compare.call(arr, arr[i], n)) || (!compare && n < arr[i])) { | ||
} else { | ||
for (; i < j; i++) { | ||
if (compare && compare.call(arr, arr[i], n) || !compare && n < arr[i]) { | ||
swap(arr, p, i); | ||
@@ -39,7 +43,7 @@ p = i; | ||
module.exports = function(arr, compare) { | ||
if(!Array.isArray(arr)) { | ||
module.exports = function (arr, compare) { | ||
if (!Array.isArray(arr)) { | ||
throw new Error('quick sort need an array'); | ||
} | ||
if(arr.length < 2) { | ||
if (arr.length < 2) { | ||
return arr; | ||
@@ -46,0 +50,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109965
1528
11