Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

more-css

Package Overview
Dependencies
Maintainers
2
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

more-css - npm Package Compare versions

Comparing version 0.7.2 to 0.7.3

tests/file/i.css

157

build/CalArea.js

@@ -23,3 +23,3 @@ var ImpactChild=function(){var _0=require('./ImpactChild');return _0.hasOwnProperty("ImpactChild")?_0.ImpactChild:_0.hasOwnProperty("default")?_0.default:_0}();

//连续的1中可以出现0,因为无样式即不冲突可合并,但在真正合并时要考虑不能合并没有样式的选择器
//如此不会出现单个的1,连续的1表示此样式至少有2个相同的选择器里可合并
//如此不会出现单个的1和0,头和尾一定是1,连续的1表示此样式至少有2个相同的选择器里可合并
//计算最大面积时可按矩阵中组成1的最多的矩形计算

@@ -65,2 +65,3 @@ //并忽略掉横坐标:意为横向相隔可忽略

self.record(arr, i, j, k - 1);
// self.record2(arr, i, j, k - 1);
j = k + 1;

@@ -79,4 +80,3 @@ }

var self = this;
var add = [];
//冒泡组成若干个矩阵,将其存入临时数组,先横向增量扩充原有矩阵,再保存自身
//冒泡组成若干个矩阵,进行横向增量扩充原有矩阵
for(var i = start; i < end; i++) {

@@ -89,23 +89,17 @@ if(arr[i] == 1) {

var key = temp.join(',');
var o = {
xs: [col],
ys: temp.concat([]),
key: key,
area: temp.length
};
if(self.areaMap.hasOwnProperty(key)) {
self.areaMap[key].forEach(function(item) {
var n = {
xs: item.xs.concat(col),
ys: item.ys,
area: item.area + item.ys.length
};
self.area.push(n);
self.areaMap[key].push(n);
});
var exist = self.areaMap[key];
exist.xs.push(col);
exist.area += temp.length;
}
add.push(o);
//hash保存加快速度,增量扩充已有的矩阵时直接以边为key
self.areaMap[key] = self.areaMap[key] || [];
self.areaMap[key].push(o);
else {
var o = {
xs: [col],
ys: temp.concat([]),
key: key,
area: temp.length
};
self.area.push(o);
self.areaMap[key] = o;
}
}

@@ -115,3 +109,2 @@ }

}
self.area = self.area.concat(add);
}

@@ -124,23 +117,9 @@ CalArea.prototype.getMax = function() {

var res = this.area.pop();
var has = false;
outer:
for(var i = 0, len = res.xs.length; i < len; i++) {
var x = res.xs[i];
for(var j = 0, len2 = res.ys.length; j < len2; j++) {
var y = res.ys[j];
if(self.history.hasOwnProperty([x + ',' + y])) {
has = true;
break outer;
}
}
}
if(has) {
continue;
}
//获取最大面积后要检查合并后是否体积变小
var reduce = 0;
var increase = 0;
var val = '';
var temp = 0;
var count = 0;
res.xs.forEach(function(x, i) {
val += self.keys[x];
reduce += self.keys[x].length;
if(i < res.xs.length - 1) {

@@ -150,2 +129,3 @@ val += ';';

});
reduce *= res.ys.length;
var sel = '';

@@ -158,24 +138,23 @@ var len = res.ys.length;

}
var count = 0;
self.list[y].styles.forEach(function(style) {
if(!style.ignore) {
count++;
}
});
//注意当被提取的样式所属的选择器不止一个样式时,会多省略1个分号
if(self.list[y].styles.length > 1) {
temp++;
if(count > 1) {
reduce++;
}
//否则会省略整个选择器
else {
temp += self.list[y].s2s.length + 2;
reduce += self.list[y].s2s.length + 2;
}
count++;
});
increase = sel.length + 2 + val.length;
//无论是否采用,此次结果的矩阵都要被清除,其它面积中和此矩阵冲突的要进行分割或裁减
delete self.areaMap[res.key];
self.conflict(res);
//比较增减
var reduce = val.length * count + temp;
var increase = sel.length + 2 + val.length;
// console.log(5, val, sel, reduce, increase, count, temp)
if(reduce > increase) {
for(var i = 0, len = res.xs.length; i < len; i++) {
var x = res.xs[i];
for(var j = 0, len2 = res.ys.length; j < len2; j++) {
var y = res.ys[j];
self.history[x + ',' + y] = true;
}
}
res.val = val;

@@ -188,4 +167,74 @@ res.sel = sel;

}
CalArea.prototype.conflict = function(res) {
var self = this;
var hash = {};
res.xs.forEach(function(x) {
res.ys.forEach(function(y) {
hash[x + ',' + y] = true;
});
});
self.area.forEach(function(area) {
var cf = false;
area.xs.forEach(function(x) {
area.ys.forEach(function(y) {
if(hash.hasOwnProperty(x + ',' + y)) {
cf = true;
}
});
});
if(cf) {
delete self.areaMap[area.key];
area.ignore = true;
area.xs.forEach(function(x) {
var ys = [];
area.ys.forEach(function(y) {
if(!hash.hasOwnProperty(x + ',' + y)) {
ys.push(y);
}
});
if(ys.length) {
self.insert(x, ys);
}
});
}
});
for(var i = self.area.length - 1; i >= 0; i--) {
if(self.area[i].ignore) {
self.area.splice(i, 1);
}
}
sort(self.area, function(a, b) {
return a.area > b.area;
});
}
CalArea.prototype.insert = function(col, ys) {
var self = this;
//冒泡组成若干个矩阵,进行横向增量扩充原有矩阵
for(var i = 0, len = ys.length; i < len - 1; i++) {
var temp = [ys[i]];
for(var j = i + 1; j < len; j++) {
temp.push(ys[j]);
var key = temp.join(',');
if(self.areaMap.hasOwnProperty(key)) {
var exist = self.areaMap[key];
if(exist.xs.indexOf(col) == -1) {
exist.xs.push(col);
exist.area += temp.length;
}
}
else {
var o = {
xs: [col],
ys: temp.concat([]),
key: key,
area: temp.length
};
self.area.push(o);
self.areaMap[key] = o;
}
}
}
}
exports.default=CalArea;
{
"name": "more-css",
"version": "0.7.2",
"version": "0.7.3",
"description": "a css pre-compiler & agressive compressor",

@@ -5,0 +5,0 @@ "maintainers": [

@@ -23,3 +23,3 @@ import ImpactChild from './ImpactChild';

//连续的1中可以出现0,因为无样式即不冲突可合并,但在真正合并时要考虑不能合并没有样式的选择器
//如此不会出现单个的1,连续的1表示此样式至少有2个相同的选择器里可合并
//如此不会出现单个的1和0,头和尾一定是1,连续的1表示此样式至少有2个相同的选择器里可合并
//计算最大面积时可按矩阵中组成1的最多的矩形计算

@@ -65,2 +65,3 @@ //并忽略掉横坐标:意为横向相隔可忽略

self.record(arr, i, j, k - 1);
// self.record2(arr, i, j, k - 1);
j = k + 1;

@@ -79,4 +80,3 @@ }

var self = this;
var add = [];
//冒泡组成若干个矩阵,将其存入临时数组,先横向增量扩充原有矩阵,再保存自身
//冒泡组成若干个矩阵,进行横向增量扩充原有矩阵
for(var i = start; i < end; i++) {

@@ -89,23 +89,17 @@ if(arr[i] == 1) {

var key = temp.join(',');
var o = {
xs: [col],
ys: temp.concat([]),
key: key,
area: temp.length
};
if(self.areaMap.hasOwnProperty(key)) {
self.areaMap[key].forEach(function(item) {
var n = {
xs: item.xs.concat(col),
ys: item.ys,
area: item.area + item.ys.length
};
self.area.push(n);
self.areaMap[key].push(n);
});
var exist = self.areaMap[key];
exist.xs.push(col);
exist.area += temp.length;
}
add.push(o);
//hash保存加快速度,增量扩充已有的矩阵时直接以边为key
self.areaMap[key] = self.areaMap[key] || [];
self.areaMap[key].push(o);
else {
var o = {
xs: [col],
ys: temp.concat([]),
key: key,
area: temp.length
};
self.area.push(o);
self.areaMap[key] = o;
}
}

@@ -115,3 +109,2 @@ }

}
self.area = self.area.concat(add);
}

@@ -124,23 +117,9 @@ getMax() {

var res = this.area.pop();
var has = false;
outer:
for(var i = 0, len = res.xs.length; i < len; i++) {
var x = res.xs[i];
for(var j = 0, len2 = res.ys.length; j < len2; j++) {
var y = res.ys[j];
if(self.history.hasOwnProperty([x + ',' + y])) {
has = true;
break outer;
}
}
}
if(has) {
continue;
}
//获取最大面积后要检查合并后是否体积变小
var reduce = 0;
var increase = 0;
var val = '';
var temp = 0;
var count = 0;
res.xs.forEach(function(x, i) {
val += self.keys[x];
reduce += self.keys[x].length;
if(i < res.xs.length - 1) {

@@ -150,2 +129,3 @@ val += ';';

});
reduce *= res.ys.length;
var sel = '';

@@ -158,24 +138,23 @@ var len = res.ys.length;

}
var count = 0;
self.list[y].styles.forEach(function(style) {
if(!style.ignore) {
count++;
}
});
//注意当被提取的样式所属的选择器不止一个样式时,会多省略1个分号
if(self.list[y].styles.length > 1) {
temp++;
if(count > 1) {
reduce++;
}
//否则会省略整个选择器
else {
temp += self.list[y].s2s.length + 2;
reduce += self.list[y].s2s.length + 2;
}
count++;
});
increase = sel.length + 2 + val.length;
//无论是否采用,此次结果的矩阵都要被清除,其它面积中和此矩阵冲突的要进行分割或裁减
delete self.areaMap[res.key];
self.conflict(res);
//比较增减
var reduce = val.length * count + temp;
var increase = sel.length + 2 + val.length;
// console.log(5, val, sel, reduce, increase, count, temp)
if(reduce > increase) {
for(var i = 0, len = res.xs.length; i < len; i++) {
var x = res.xs[i];
for(var j = 0, len2 = res.ys.length; j < len2; j++) {
var y = res.ys[j];
self.history[x + ',' + y] = true;
}
}
res.val = val;

@@ -188,4 +167,74 @@ res.sel = sel;

}
conflict(res) {
var self = this;
var hash = {};
res.xs.forEach(function(x) {
res.ys.forEach(function(y) {
hash[x + ',' + y] = true;
});
});
self.area.forEach(function(area) {
var cf = false;
area.xs.forEach(function(x) {
area.ys.forEach(function(y) {
if(hash.hasOwnProperty(x + ',' + y)) {
cf = true;
}
});
});
if(cf) {
delete self.areaMap[area.key];
area.ignore = true;
area.xs.forEach(function(x) {
var ys = [];
area.ys.forEach(function(y) {
if(!hash.hasOwnProperty(x + ',' + y)) {
ys.push(y);
}
});
if(ys.length) {
self.insert(x, ys);
}
});
}
});
for(var i = self.area.length - 1; i >= 0; i--) {
if(self.area[i].ignore) {
self.area.splice(i, 1);
}
}
sort(self.area, function(a, b) {
return a.area > b.area;
});
}
insert(col, ys) {
var self = this;
//冒泡组成若干个矩阵,进行横向增量扩充原有矩阵
for(var i = 0, len = ys.length; i < len - 1; i++) {
var temp = [ys[i]];
for(var j = i + 1; j < len; j++) {
temp.push(ys[j]);
var key = temp.join(',');
if(self.areaMap.hasOwnProperty(key)) {
var exist = self.areaMap[key];
if(exist.xs.indexOf(col) == -1) {
exist.xs.push(col);
exist.area += temp.length;
}
}
else {
var o = {
xs: [col],
ys: temp.concat([]),
key: key,
area: temp.length
};
self.area.push(o);
self.areaMap[key] = o;
}
}
}
}
}
export default CalArea;

@@ -190,7 +190,7 @@ var expect = require('expect.js');

var s = '.a{margin:0;padding:0;width:0;height:0}.b{margin:0;padding:1;width:2;height:0}.c{margin:1;padding:1;width:3;height:0}';
expect(More.compress(s, true)).to.eql('.a,.b{height:0;margin:0}.a{padding:0;width:0}.b,.c{padding:1}.b{width:2}.c{height:0;margin:1;width:3}');
expect(More.compress(s, true)).to.eql('.a,.b{margin:0}.a{height:0;padding:0;width:0}.b,.c{height:0;padding:1}.b{width:2}.c{margin:1;width:3}');
});
it('multi 4', function() {
var s = '.aaaaaaaa{margin:0;padding:0;width:0;height:0}.b{margin:0;padding:1;width:2;height:0}.cccccccc{margin:1;padding:1;width:3;height:0}';
expect(More.compress(s, true)).to.eql('.aaaaaaaa,.b{height:0;margin:0}.aaaaaaaa{padding:0;width:0}.b{padding:1;width:2}.cccccccc{height:0;margin:1;padding:1;width:3}');
expect(More.compress(s, true)).to.eql('.aaaaaaaa{height:0;margin:0;padding:0;width:0}.b,.cccccccc{height:0;padding:1}.b{margin:0;width:2}.cccccccc{margin:1;width:3}');
});

@@ -203,4 +203,4 @@ });

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/960-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/960-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/960-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/960-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});

@@ -211,4 +211,4 @@ it('animate', function() {

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/animate-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/animate-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/animate-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/animate-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});

@@ -219,4 +219,4 @@ it('blueprint', function() {

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/blueprint-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/blueprint-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/blueprint-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/blueprint-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});

@@ -227,4 +227,4 @@ it('bootstrap', function() {

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/bootstrap-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/bootstrap-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/bootstrap-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/bootstrap-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});

@@ -235,11 +235,11 @@ it('font-awesome', function() {

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/font-awesome-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/font-awesome-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/font-awesome-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/font-awesome-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});
it.skip('foundation', function() {
it('foundation', function() {
var s = fs.readFileSync(path.join(__dirname, 'file/foundation.css'), { encoding: 'utf-8' });
var res1 = More.compress(s);
fs.writeFileSync(path.join(__dirname, 'file/foundation-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/foundation-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/foundation-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/foundation-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});

@@ -250,4 +250,4 @@ it('gumby', function() {

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/gumby-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/gumby-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/gumby-res1.css'), res1, { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/gumby-res2.css'), res2, { encoding: 'utf-8' });
});

@@ -258,4 +258,4 @@ it('inuit', function() {

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/inuit-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/inuit-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/inuit-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/inuit-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});

@@ -266,4 +266,4 @@ it('normalize', function() {

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/normalize-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/normalize-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/normalize-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/normalize-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});

@@ -274,4 +274,4 @@ it('oocss', function() {

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/oocss-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/oocss-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/oocss-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/oocss-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});

@@ -282,4 +282,4 @@ it('pure', function() {

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/pure-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/pure-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/pure-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/pure-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});

@@ -290,5 +290,5 @@ it('reset', function() {

var res2 = More.compress(s, true);
fs.writeFileSync(path.join(__dirname, 'file/reset-res1.css'), res1.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/reset-res2.css'), res2.replace(/}\n?/g, '}\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/reset-res1.css'), res1.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
fs.writeFileSync(path.join(__dirname, 'file/reset-res2.css'), res2.replace(/(}+)\n?/g, '$1\n'), { encoding: 'utf-8' });
});
});

@@ -23,3 +23,3 @@ define(function(require, exports, module){var ImpactChild=function(){var _0=require('./ImpactChild');return _0.hasOwnProperty("ImpactChild")?_0.ImpactChild:_0.hasOwnProperty("default")?_0.default:_0}();

//连续的1中可以出现0,因为无样式即不冲突可合并,但在真正合并时要考虑不能合并没有样式的选择器
//如此不会出现单个的1,连续的1表示此样式至少有2个相同的选择器里可合并
//如此不会出现单个的1和0,头和尾一定是1,连续的1表示此样式至少有2个相同的选择器里可合并
//计算最大面积时可按矩阵中组成1的最多的矩形计算

@@ -65,2 +65,3 @@ //并忽略掉横坐标:意为横向相隔可忽略

self.record(arr, i, j, k - 1);
// self.record2(arr, i, j, k - 1);
j = k + 1;

@@ -79,4 +80,3 @@ }

var self = this;
var add = [];
//冒泡组成若干个矩阵,将其存入临时数组,先横向增量扩充原有矩阵,再保存自身
//冒泡组成若干个矩阵,进行横向增量扩充原有矩阵
for(var i = start; i < end; i++) {

@@ -89,23 +89,17 @@ if(arr[i] == 1) {

var key = temp.join(',');
var o = {
xs: [col],
ys: temp.concat([]),
key: key,
area: temp.length
};
if(self.areaMap.hasOwnProperty(key)) {
self.areaMap[key].forEach(function(item) {
var n = {
xs: item.xs.concat(col),
ys: item.ys,
area: item.area + item.ys.length
};
self.area.push(n);
self.areaMap[key].push(n);
});
var exist = self.areaMap[key];
exist.xs.push(col);
exist.area += temp.length;
}
add.push(o);
//hash保存加快速度,增量扩充已有的矩阵时直接以边为key
self.areaMap[key] = self.areaMap[key] || [];
self.areaMap[key].push(o);
else {
var o = {
xs: [col],
ys: temp.concat([]),
key: key,
area: temp.length
};
self.area.push(o);
self.areaMap[key] = o;
}
}

@@ -115,3 +109,2 @@ }

}
self.area = self.area.concat(add);
}

@@ -124,23 +117,9 @@ CalArea.prototype.getMax = function() {

var res = this.area.pop();
var has = false;
outer:
for(var i = 0, len = res.xs.length; i < len; i++) {
var x = res.xs[i];
for(var j = 0, len2 = res.ys.length; j < len2; j++) {
var y = res.ys[j];
if(self.history.hasOwnProperty([x + ',' + y])) {
has = true;
break outer;
}
}
}
if(has) {
continue;
}
//获取最大面积后要检查合并后是否体积变小
var reduce = 0;
var increase = 0;
var val = '';
var temp = 0;
var count = 0;
res.xs.forEach(function(x, i) {
val += self.keys[x];
reduce += self.keys[x].length;
if(i < res.xs.length - 1) {

@@ -150,2 +129,3 @@ val += ';';

});
reduce *= res.ys.length;
var sel = '';

@@ -158,24 +138,23 @@ var len = res.ys.length;

}
var count = 0;
self.list[y].styles.forEach(function(style) {
if(!style.ignore) {
count++;
}
});
//注意当被提取的样式所属的选择器不止一个样式时,会多省略1个分号
if(self.list[y].styles.length > 1) {
temp++;
if(count > 1) {
reduce++;
}
//否则会省略整个选择器
else {
temp += self.list[y].s2s.length + 2;
reduce += self.list[y].s2s.length + 2;
}
count++;
});
increase = sel.length + 2 + val.length;
//无论是否采用,此次结果的矩阵都要被清除,其它面积中和此矩阵冲突的要进行分割或裁减
delete self.areaMap[res.key];
self.conflict(res);
//比较增减
var reduce = val.length * count + temp;
var increase = sel.length + 2 + val.length;
// console.log(5, val, sel, reduce, increase, count, temp)
if(reduce > increase) {
for(var i = 0, len = res.xs.length; i < len; i++) {
var x = res.xs[i];
for(var j = 0, len2 = res.ys.length; j < len2; j++) {
var y = res.ys[j];
self.history[x + ',' + y] = true;
}
}
res.val = val;

@@ -188,4 +167,74 @@ res.sel = sel;

}
CalArea.prototype.conflict = function(res) {
var self = this;
var hash = {};
res.xs.forEach(function(x) {
res.ys.forEach(function(y) {
hash[x + ',' + y] = true;
});
});
self.area.forEach(function(area) {
var cf = false;
area.xs.forEach(function(x) {
area.ys.forEach(function(y) {
if(hash.hasOwnProperty(x + ',' + y)) {
cf = true;
}
});
});
if(cf) {
delete self.areaMap[area.key];
area.ignore = true;
area.xs.forEach(function(x) {
var ys = [];
area.ys.forEach(function(y) {
if(!hash.hasOwnProperty(x + ',' + y)) {
ys.push(y);
}
});
if(ys.length) {
self.insert(x, ys);
}
});
}
});
for(var i = self.area.length - 1; i >= 0; i--) {
if(self.area[i].ignore) {
self.area.splice(i, 1);
}
}
sort(self.area, function(a, b) {
return a.area > b.area;
});
}
CalArea.prototype.insert = function(col, ys) {
var self = this;
//冒泡组成若干个矩阵,进行横向增量扩充原有矩阵
for(var i = 0, len = ys.length; i < len - 1; i++) {
var temp = [ys[i]];
for(var j = i + 1; j < len; j++) {
temp.push(ys[j]);
var key = temp.join(',');
if(self.areaMap.hasOwnProperty(key)) {
var exist = self.areaMap[key];
if(exist.xs.indexOf(col) == -1) {
exist.xs.push(col);
exist.area += temp.length;
}
}
else {
var o = {
xs: [col],
ys: temp.concat([]),
key: key,
area: temp.length
};
self.area.push(o);
self.areaMap[key] = o;
}
}
}
}
exports.default=CalArea;});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc