Comparing version 0.0.3 to 0.0.4
@@ -55,6 +55,2 @@ var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0["default"]:_0}(); | ||
var first = sel[0]; | ||
//没有选择器直接属性或伪类为省略* | ||
if(first.type() != Token.SELECTOR) { | ||
sel.unshift(new Token(Token.SELECTOR, '*')); | ||
} | ||
var _p = 0; | ||
@@ -68,4 +64,4 @@ var now = res; | ||
case Token.SELECTOR: | ||
if(t.prev() && t.prev().type() == Token.SELECTOR) { | ||
var prev = t.prev(); | ||
var prev = t.prev(); | ||
if(prev && prev.type() == Token.SELECTOR) { | ||
var list = [s]; | ||
@@ -75,5 +71,5 @@ do { | ||
list.push(s); | ||
prev = prev.next(); | ||
i++; | ||
_p += priority(prev, s); | ||
prev = prev.prev(); | ||
i--; | ||
} | ||
@@ -99,7 +95,7 @@ while(prev && prev.type() == Token.SELECTOR); | ||
//省略* | ||
if(prev.type() != Token.SELECTOR) { | ||
if(!prev || prev.type() != Token.SELECTOR) { | ||
now['*'] = now['*'] || {}; | ||
now = now['*']; | ||
} | ||
else { | ||
else if(prev) { | ||
s = prev.content(); | ||
@@ -153,13 +149,6 @@ now[s] = now[s] || {}; | ||
var prev = t.prev(); | ||
//省略* | ||
if(prev.type() != Token.SELECTOR) { | ||
now['*'] = now['*'] || {}; | ||
now = now['*']; | ||
} | ||
else { | ||
s = prev.content(); | ||
now[s] = now[s] || {}; | ||
now = now[s]; | ||
_p += priority(prev, s); | ||
} | ||
s = prev.content(); | ||
now[s] = now[s] || {}; | ||
now = now[s]; | ||
_p += priority(prev, s); | ||
break; | ||
@@ -171,3 +160,3 @@ case ']': | ||
//可能有多个属性 | ||
while(prev.content() == ']') { | ||
while(prev && prev.content() == ']') { | ||
i--; | ||
@@ -192,3 +181,3 @@ item = []; | ||
//省略* | ||
if(prev.type() != Token.SELECTOR) { | ||
if(!prev || prev.type() != Token.SELECTOR) { | ||
now['*'] = now['*'] || {}; | ||
@@ -195,0 +184,0 @@ now = now['*']; |
@@ -37,22 +37,3 @@ function quickSort(arr, begin, end, compare) { | ||
} | ||
function getM(arr, a, b) { | ||
var max = min = arr[a]; | ||
var i = j = a; | ||
for(; a < b; a++) { | ||
if(arr[a] > max) { | ||
max = arr[a]; | ||
i = a; | ||
} | ||
else if(arr[a] < min) { | ||
min = arr[a]; | ||
j = a; | ||
} | ||
} | ||
return { | ||
max: max, | ||
min: min, | ||
i: i, | ||
j: j | ||
}; | ||
} | ||
module.exports = function(arr, compare) { | ||
@@ -65,29 +46,4 @@ if(!Array.isArray(arr)) { | ||
} | ||
//优化尽可能选取中间值,5等分取每组最大最小值,然后10个数取中值,保证最坏情况首次分割值也在2/5~3/5 | ||
if(!compare && arr.length > 9) { | ||
var n = Math.floor(arr.length / 5); | ||
var split = []; | ||
var index = []; | ||
for(var i = 0; i < 4; i++) { | ||
var m = getM(arr, i * n, (i + 1) * n); | ||
split.push(m.max); | ||
split.push(m.min); | ||
index.push(m.i); | ||
index.push(m.j); | ||
} | ||
m = getM(arr, 4 * n, arr.length); | ||
split.push(m.max); | ||
split.push(m.min); | ||
index.push(m.i); | ||
index.push(m.j); | ||
quickSort(split, 0, split.length); | ||
for(var i = 0; i < index.length; i++) { | ||
if(arr[index[i]] == split[4]) { | ||
swap(arr, 0, index[i]); | ||
break; | ||
} | ||
} | ||
} | ||
quickSort(arr, 0, arr.length - 1, compare); | ||
return arr; | ||
}; |
@@ -1,8 +0,1 @@ | ||
if(typeof define === 'function' && (define.amd || define.cmd)) { | ||
define(function(require, exports, module) { | ||
module.exports = require('./web/jaw').default; | ||
}); | ||
} | ||
else { | ||
module.exports = require('./build/jaw').default; | ||
} | ||
module.exports = require('./build/jaw')['default']; |
{ | ||
"name": "jaw", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Parasitize CSS to JSX", | ||
@@ -34,3 +34,3 @@ "maintainers": [ | ||
"es6-shim": "*", | ||
"homunculus": "~0.9.6" | ||
"homunculus": "~0.9.8" | ||
}, | ||
@@ -47,3 +47,4 @@ "devDependencies": { | ||
"through2": "^0.6.1", | ||
"jsdc": "^0.6.3" | ||
"jsdc": "^0.6.5", | ||
"spm": "~3.6.0" | ||
}, | ||
@@ -54,3 +55,15 @@ "main": "./index", | ||
}, | ||
"spm": { | ||
"main": "./index.js", | ||
"output": [ | ||
"./index.js" | ||
], | ||
"build": { | ||
"global": { | ||
"homunculus": "homunculus" | ||
} | ||
}, | ||
"buildArgs": "--standalone" | ||
}, | ||
"readmeFilename": "README.md" | ||
} |
@@ -5,2 +5,7 @@ # Parasitize CSS into JSX for migi | ||
[![NPM version](https://badge.fury.io/js/jaw.png)](https://npmjs.org/package/jaw) | ||
[![Build Status](https://travis-ci.org/migijs/jaw.svg?branch=master)](https://travis-ci.org/migijs/jaw) | ||
[![Coverage Status](https://coveralls.io/repos/migijs/jaw/badge.png)](https://coveralls.io/r/migijs/jaw) | ||
[![Dependency Status](https://david-dm.org/migijs/jaw.png)](https://david-dm.org/migijs/jaw) | ||
## INSTALL | ||
@@ -17,4 +22,4 @@ ``` | ||
## API | ||
* parse(code:String):Object 传入要解析的css代码,返回格式化好的json对象 | ||
* tokens():Array<Token> 返回css的token列表 | ||
* parse(code:String):JSON 传入要解析的css代码,返回格式化好的json对象 | ||
* tokens():Array\<Token> 返回css的token列表 | ||
* ast():Object 返回css的语法树 | ||
@@ -21,0 +26,0 @@ |
@@ -55,6 +55,2 @@ import homunculus from 'homunculus'; | ||
var first = sel[0]; | ||
//没有选择器直接属性或伪类为省略* | ||
if(first.type() != Token.SELECTOR) { | ||
sel.unshift(new Token(Token.SELECTOR, '*')); | ||
} | ||
var _p = 0; | ||
@@ -68,4 +64,4 @@ var now = res; | ||
case Token.SELECTOR: | ||
if(t.prev() && t.prev().type() == Token.SELECTOR) { | ||
var prev = t.prev(); | ||
var prev = t.prev(); | ||
if(prev && prev.type() == Token.SELECTOR) { | ||
var list = [s]; | ||
@@ -75,5 +71,5 @@ do { | ||
list.push(s); | ||
prev = prev.next(); | ||
i++; | ||
_p += priority(prev, s); | ||
prev = prev.prev(); | ||
i--; | ||
} | ||
@@ -99,7 +95,7 @@ while(prev && prev.type() == Token.SELECTOR); | ||
//省略* | ||
if(prev.type() != Token.SELECTOR) { | ||
if(!prev || prev.type() != Token.SELECTOR) { | ||
now['*'] = now['*'] || {}; | ||
now = now['*']; | ||
} | ||
else { | ||
else if(prev) { | ||
s = prev.content(); | ||
@@ -153,13 +149,6 @@ now[s] = now[s] || {}; | ||
var prev = t.prev(); | ||
//省略* | ||
if(prev.type() != Token.SELECTOR) { | ||
now['*'] = now['*'] || {}; | ||
now = now['*']; | ||
} | ||
else { | ||
s = prev.content(); | ||
now[s] = now[s] || {}; | ||
now = now[s]; | ||
_p += priority(prev, s); | ||
} | ||
s = prev.content(); | ||
now[s] = now[s] || {}; | ||
now = now[s]; | ||
_p += priority(prev, s); | ||
break; | ||
@@ -171,3 +160,3 @@ case ']': | ||
//可能有多个属性 | ||
while(prev.content() == ']') { | ||
while(prev && prev.content() == ']') { | ||
i--; | ||
@@ -192,3 +181,3 @@ item = []; | ||
//省略* | ||
if(prev.type() != Token.SELECTOR) { | ||
if(!prev || prev.type() != Token.SELECTOR) { | ||
now['*'] = now['*'] || {}; | ||
@@ -195,0 +184,0 @@ now = now['*']; |
@@ -37,22 +37,3 @@ function quickSort(arr, begin, end, compare) { | ||
} | ||
function getM(arr, a, b) { | ||
var max = min = arr[a]; | ||
var i = j = a; | ||
for(; a < b; a++) { | ||
if(arr[a] > max) { | ||
max = arr[a]; | ||
i = a; | ||
} | ||
else if(arr[a] < min) { | ||
min = arr[a]; | ||
j = a; | ||
} | ||
} | ||
return { | ||
max: max, | ||
min: min, | ||
i: i, | ||
j: j | ||
}; | ||
} | ||
module.exports = function(arr, compare) { | ||
@@ -65,29 +46,4 @@ if(!Array.isArray(arr)) { | ||
} | ||
//优化尽可能选取中间值,5等分取每组最大最小值,然后10个数取中值,保证最坏情况首次分割值也在2/5~3/5 | ||
if(!compare && arr.length > 9) { | ||
var n = Math.floor(arr.length / 5); | ||
var split = []; | ||
var index = []; | ||
for(var i = 0; i < 4; i++) { | ||
var m = getM(arr, i * n, (i + 1) * n); | ||
split.push(m.max); | ||
split.push(m.min); | ||
index.push(m.i); | ||
index.push(m.j); | ||
} | ||
m = getM(arr, 4 * n, arr.length); | ||
split.push(m.max); | ||
split.push(m.min); | ||
index.push(m.i); | ||
index.push(m.j); | ||
quickSort(split, 0, split.length); | ||
for(var i = 0; i < index.length; i++) { | ||
if(arr[index[i]] == split[4]) { | ||
swap(arr, 0, index[i]); | ||
break; | ||
} | ||
} | ||
} | ||
quickSort(arr, 0, arr.length - 1, compare); | ||
return arr; | ||
}; |
@@ -55,6 +55,2 @@ define(function(require, exports, module){var homunculus=function(){var _0=require('homunculus');return _0.hasOwnProperty("homunculus")?_0.homunculus:_0.hasOwnProperty("default")?_0["default"]:_0}(); | ||
var first = sel[0]; | ||
//没有选择器直接属性或伪类为省略* | ||
if(first.type() != Token.SELECTOR) { | ||
sel.unshift(new Token(Token.SELECTOR, '*')); | ||
} | ||
var _p = 0; | ||
@@ -68,4 +64,4 @@ var now = res; | ||
case Token.SELECTOR: | ||
if(t.prev() && t.prev().type() == Token.SELECTOR) { | ||
var prev = t.prev(); | ||
var prev = t.prev(); | ||
if(prev && prev.type() == Token.SELECTOR) { | ||
var list = [s]; | ||
@@ -75,5 +71,5 @@ do { | ||
list.push(s); | ||
prev = prev.next(); | ||
i++; | ||
_p += priority(prev, s); | ||
prev = prev.prev(); | ||
i--; | ||
} | ||
@@ -99,7 +95,7 @@ while(prev && prev.type() == Token.SELECTOR); | ||
//省略* | ||
if(prev.type() != Token.SELECTOR) { | ||
if(!prev || prev.type() != Token.SELECTOR) { | ||
now['*'] = now['*'] || {}; | ||
now = now['*']; | ||
} | ||
else { | ||
else if(prev) { | ||
s = prev.content(); | ||
@@ -153,13 +149,6 @@ now[s] = now[s] || {}; | ||
var prev = t.prev(); | ||
//省略* | ||
if(prev.type() != Token.SELECTOR) { | ||
now['*'] = now['*'] || {}; | ||
now = now['*']; | ||
} | ||
else { | ||
s = prev.content(); | ||
now[s] = now[s] || {}; | ||
now = now[s]; | ||
_p += priority(prev, s); | ||
} | ||
s = prev.content(); | ||
now[s] = now[s] || {}; | ||
now = now[s]; | ||
_p += priority(prev, s); | ||
break; | ||
@@ -171,3 +160,3 @@ case ']': | ||
//可能有多个属性 | ||
while(prev.content() == ']') { | ||
while(prev && prev.content() == ']') { | ||
i--; | ||
@@ -192,3 +181,3 @@ item = []; | ||
//省略* | ||
if(prev.type() != Token.SELECTOR) { | ||
if(!prev || prev.type() != Token.SELECTOR) { | ||
now['*'] = now['*'] || {}; | ||
@@ -195,0 +184,0 @@ now = now['*']; |
@@ -37,22 +37,3 @@ define(function(require, exports, module){function quickSort(arr, begin, end, compare) { | ||
} | ||
function getM(arr, a, b) { | ||
var max = min = arr[a]; | ||
var i = j = a; | ||
for(; a < b; a++) { | ||
if(arr[a] > max) { | ||
max = arr[a]; | ||
i = a; | ||
} | ||
else if(arr[a] < min) { | ||
min = arr[a]; | ||
j = a; | ||
} | ||
} | ||
return { | ||
max: max, | ||
min: min, | ||
i: i, | ||
j: j | ||
}; | ||
} | ||
module.exports = function(arr, compare) { | ||
@@ -65,29 +46,4 @@ if(!Array.isArray(arr)) { | ||
} | ||
//优化尽可能选取中间值,5等分取每组最大最小值,然后10个数取中值,保证最坏情况首次分割值也在2/5~3/5 | ||
if(!compare && arr.length > 9) { | ||
var n = Math.floor(arr.length / 5); | ||
var split = []; | ||
var index = []; | ||
for(var i = 0; i < 4; i++) { | ||
var m = getM(arr, i * n, (i + 1) * n); | ||
split.push(m.max); | ||
split.push(m.min); | ||
index.push(m.i); | ||
index.push(m.j); | ||
} | ||
m = getM(arr, 4 * n, arr.length); | ||
split.push(m.max); | ||
split.push(m.min); | ||
index.push(m.i); | ||
index.push(m.j); | ||
quickSort(split, 0, split.length); | ||
for(var i = 0; i < index.length; i++) { | ||
if(arr[index[i]] == split[4]) { | ||
swap(arr, 0, index[i]); | ||
break; | ||
} | ||
} | ||
} | ||
quickSort(arr, 0, arr.length - 1, compare); | ||
return arr; | ||
};}); |
Sorry, the diff of this file is not supported yet
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
142691
32
32
11
1113
Updatedhomunculus@~0.9.8