stylecow-plugin-msfilter-background-alpha
Advanced tools
Comparing version 4.1.0 to 5.0.0
100
index.js
@@ -0,62 +1,64 @@ | ||
"use strict"; | ||
var Color = require('color'); | ||
module.exports = function (stylecow) { | ||
module.exports = function (tasks) { | ||
stylecow.addTask({ | ||
forBrowsersLowerThan: { | ||
explorer: 9.0 | ||
}, | ||
filter: { | ||
type: 'Declaration', | ||
name: ['background', 'background-color'] | ||
}, | ||
fn: function (declaration) { | ||
var fn = declaration.get({ | ||
type: 'Function', | ||
name: ['rgba', 'hsla'] | ||
}); | ||
tasks.addTask({ | ||
forBrowsersLowerThan: { | ||
explorer: 9.0 | ||
}, | ||
filter: { | ||
type: 'Declaration', | ||
name: ['background', 'background-color'] | ||
}, | ||
fn: function (declaration) { | ||
var fn = declaration.get({ | ||
type: 'Function', | ||
name: ['rgba', 'hsla'] | ||
}); | ||
if (fn) { | ||
var color = Color(fn.toString()); | ||
var hex = color.hexString(); | ||
if (fn) { | ||
let color = Color(fn.toString()), | ||
hex = color.hexString(); | ||
if (color.alpha() == 1) { | ||
return fn.replaceWith(stylecow.parse(hex, 'Hex')); | ||
} | ||
if (color.alpha() == 1) { | ||
return fn.replaceWithCode(hex, 'Hex'); | ||
} | ||
hex = hex.replace('#', '#' + Math.round(255 * color.alpha()).toString(16)); | ||
hex = hex.replace('#', '#' + Math.round(255 * color.alpha()).toString(16)); | ||
addMsFilter(declaration.getParent('Block'), 'progid:DXImageTransform.Microsoft.gradient(startColorStr="' + hex + '", endColorStr="' + hex + '")'); | ||
} | ||
} | ||
}); | ||
addMsFilter(declaration.getAncestor('Block'), 'progid:DXImageTransform.Microsoft.gradient(startColorStr="' + hex + '", endColorStr="' + hex + '")'); | ||
} | ||
} | ||
}); | ||
function addMsFilter (block, filter) { | ||
var declaration = block.getChild({ | ||
type: 'Declaration', | ||
name: 'filter', | ||
vendor: 'ms' | ||
}); | ||
function addMsFilter (block, filter) { | ||
var declaration = block.getChild({ | ||
type: 'Declaration', | ||
name: 'filter', | ||
vendor: 'ms' | ||
}); | ||
if (!declaration) { | ||
return block.push(stylecow.parse('-ms-filter: ' + filter, 'Declaration', 'createMsFilter')); | ||
} | ||
if (!declaration) { | ||
return block.pushCode('-ms-filter: ' + filter, 'Declaration', 'createMsFilter'); | ||
} | ||
if (declaration.is({string: '-ms-filter: none;'})) { | ||
return declaration | ||
.get({ | ||
type: 'Keyword', | ||
name: 'none' | ||
}) | ||
.replaceWith((new stylecow.String()).setName(filter)); | ||
} | ||
if (declaration.is({string: '-ms-filter: none;'})) { | ||
return declaration | ||
.get({ | ||
type: 'Keyword', | ||
name: 'none' | ||
}) | ||
.replaceWith((new stylecow.String()).setName(filter)); | ||
} | ||
var string = declaration.get('String'); | ||
var string = declaration.get('String'); | ||
if (string.name) { | ||
string.name += ',' + filter; | ||
} else { | ||
string.name = filter; | ||
} | ||
} | ||
if (string.name) { | ||
string.name += ',' + filter; | ||
} else { | ||
string.name = filter; | ||
} | ||
} | ||
}; |
{ | ||
"name": "stylecow-plugin-msfilter-background-alpha", | ||
"description": "Stylecow plugin to add ms filters emulating the rgba/hsla colors in backgrounds in explorer < 9 using ms filters.", | ||
"version": "4.1.0", | ||
"version": "5.0.0", | ||
"engines": { | ||
"node": ">=4.0" | ||
}, | ||
"author": "Oscar Otero <oom@oscarotero.com>", | ||
@@ -17,4 +20,4 @@ "homepage": "https://github.com/stylecow/stylecow-plugin-msfilter-background-alpha", | ||
"devDependencies": { | ||
"mocha": "^2.2.5", | ||
"stylecow-core": "^1.0.1" | ||
"mocha": "^2.3.2", | ||
"stylecow-core": "^2.0.0" | ||
}, | ||
@@ -21,0 +24,0 @@ "scripts": { |
@@ -1,29 +0,20 @@ | ||
var assert = require('assert'); | ||
var stylecow = require('stylecow-core'); | ||
stylecow | ||
.loadNpmModule(__dirname + '/../index') | ||
.minSupport({ | ||
"explorer": 0, | ||
"firefox": 0, | ||
"chrome": 0, | ||
"safari": 0, | ||
"opera": 0, | ||
"android": 0, | ||
"ios": 0 | ||
}) | ||
.testCases(__dirname + '/cases', function (test) { | ||
stylecow.run(test.css); | ||
var tests = new stylecow.Test(__dirname + '/cases'); | ||
var tasks = (new stylecow.Tasks()).use(require('../index')); | ||
describe('cases/' + test.name, function() { | ||
it('should match output.css', function() { | ||
//test.write('output.css', test.css.toString()); | ||
assert.equal(test.css.toString(), test.read('output.css')); | ||
}); | ||
tests.run(function (test) { | ||
tasks.run(test.css); | ||
it('should match ast.json', function() { | ||
//test.writeJson('ast.json', test.css.toAst()); | ||
assert.deepEqual(test.css.toAst(), test.readJson('ast.json')); | ||
}); | ||
}); | ||
}); | ||
describe('cases/' + test.name, function() { | ||
it('should match output.css', function() { | ||
//test.writeString() | ||
test.assertString(); | ||
}); | ||
it('should match ast.json', function() { | ||
//test.writeAst() | ||
test.assertAst(); | ||
}); | ||
}); | ||
}); |
{ | ||
"class": "Root", | ||
"type": "Root", | ||
"children": [ | ||
{ | ||
"class": "Rule", | ||
"type": "Rule", | ||
"children": [ | ||
{ | ||
"class": "Selectors", | ||
"type": "Selectors", | ||
"children": [ | ||
{ | ||
"class": "Selector", | ||
"type": "Selector", | ||
"children": [ | ||
{ | ||
"class": "TypeSelector", | ||
"type": "TypeSelector", | ||
"name": "div" | ||
@@ -22,6 +22,6 @@ } | ||
{ | ||
"class": "Block", | ||
"type": "Block", | ||
"children": [ | ||
{ | ||
"class": "Declaration", | ||
"type": "Declaration", | ||
"name": "background", | ||
@@ -31,6 +31,6 @@ "vendor": null, | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Function", | ||
"type": "Function", | ||
"name": "rgba", | ||
@@ -40,6 +40,6 @@ "vendor": null, | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Number", | ||
"type": "Number", | ||
"name": 0 | ||
@@ -50,6 +50,6 @@ } | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Number", | ||
"type": "Number", | ||
"name": 0 | ||
@@ -60,6 +60,6 @@ } | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Number", | ||
"type": "Number", | ||
"name": 0 | ||
@@ -70,6 +70,6 @@ } | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Number", | ||
"type": "Number", | ||
"name": 0.5 | ||
@@ -86,3 +86,3 @@ } | ||
{ | ||
"class": "Declaration", | ||
"type": "Declaration", | ||
"name": "filter", | ||
@@ -92,6 +92,6 @@ "vendor": "ms", | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "String", | ||
"type": "String", | ||
"name": "progid:DXImageTransform.Microsoft.gradient(startColorStr=#80000000,endColorStr=#80000000)" | ||
@@ -108,12 +108,12 @@ } | ||
{ | ||
"class": "Rule", | ||
"type": "Rule", | ||
"children": [ | ||
{ | ||
"class": "Selectors", | ||
"type": "Selectors", | ||
"children": [ | ||
{ | ||
"class": "Selector", | ||
"type": "Selector", | ||
"children": [ | ||
{ | ||
"class": "TypeSelector", | ||
"type": "TypeSelector", | ||
"name": "div" | ||
@@ -126,6 +126,6 @@ } | ||
{ | ||
"class": "Block", | ||
"type": "Block", | ||
"children": [ | ||
{ | ||
"class": "Declaration", | ||
"type": "Declaration", | ||
"name": "background", | ||
@@ -135,6 +135,6 @@ "vendor": null, | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Hex", | ||
"type": "Hex", | ||
"name": "000000" | ||
@@ -151,12 +151,12 @@ } | ||
{ | ||
"class": "Rule", | ||
"type": "Rule", | ||
"children": [ | ||
{ | ||
"class": "Selectors", | ||
"type": "Selectors", | ||
"children": [ | ||
{ | ||
"class": "Selector", | ||
"type": "Selector", | ||
"children": [ | ||
{ | ||
"class": "TypeSelector", | ||
"type": "TypeSelector", | ||
"name": "div" | ||
@@ -169,6 +169,6 @@ } | ||
{ | ||
"class": "Block", | ||
"type": "Block", | ||
"children": [ | ||
{ | ||
"class": "Declaration", | ||
"type": "Declaration", | ||
"name": "background-color", | ||
@@ -178,6 +178,6 @@ "vendor": null, | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Hex", | ||
"type": "Hex", | ||
"name": "000000" | ||
@@ -194,12 +194,12 @@ } | ||
{ | ||
"class": "Rule", | ||
"type": "Rule", | ||
"children": [ | ||
{ | ||
"class": "Selectors", | ||
"type": "Selectors", | ||
"children": [ | ||
{ | ||
"class": "Selector", | ||
"type": "Selector", | ||
"children": [ | ||
{ | ||
"class": "TypeSelector", | ||
"type": "TypeSelector", | ||
"name": "div" | ||
@@ -212,6 +212,6 @@ } | ||
{ | ||
"class": "Block", | ||
"type": "Block", | ||
"children": [ | ||
{ | ||
"class": "Declaration", | ||
"type": "Declaration", | ||
"name": "background-color", | ||
@@ -221,6 +221,6 @@ "vendor": null, | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Function", | ||
"type": "Function", | ||
"name": "hsla", | ||
@@ -230,6 +230,6 @@ "vendor": null, | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Number", | ||
"type": "Number", | ||
"name": 100 | ||
@@ -240,10 +240,10 @@ } | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Unit", | ||
"type": "Unit", | ||
"name": "%", | ||
"children": [ | ||
{ | ||
"class": "Number", | ||
"type": "Number", | ||
"name": 50 | ||
@@ -256,10 +256,10 @@ } | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Unit", | ||
"type": "Unit", | ||
"name": "%", | ||
"children": [ | ||
{ | ||
"class": "Number", | ||
"type": "Number", | ||
"name": 50 | ||
@@ -272,6 +272,6 @@ } | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Number", | ||
"type": "Number", | ||
"name": 0.5 | ||
@@ -288,3 +288,3 @@ } | ||
{ | ||
"class": "Declaration", | ||
"type": "Declaration", | ||
"name": "filter", | ||
@@ -294,6 +294,6 @@ "vendor": "ms", | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "String", | ||
"type": "String", | ||
"name": "progid:DXImageTransform.Microsoft.gradient(startColorStr=#806ABF40,endColorStr=#806ABF40)" | ||
@@ -310,12 +310,12 @@ } | ||
{ | ||
"class": "Rule", | ||
"type": "Rule", | ||
"children": [ | ||
{ | ||
"class": "Selectors", | ||
"type": "Selectors", | ||
"children": [ | ||
{ | ||
"class": "Selector", | ||
"type": "Selector", | ||
"children": [ | ||
{ | ||
"class": "TypeSelector", | ||
"type": "TypeSelector", | ||
"name": "div" | ||
@@ -328,6 +328,6 @@ } | ||
{ | ||
"class": "Block", | ||
"type": "Block", | ||
"children": [ | ||
{ | ||
"class": "Declaration", | ||
"type": "Declaration", | ||
"name": "background-color", | ||
@@ -337,6 +337,6 @@ "vendor": null, | ||
{ | ||
"class": "Value", | ||
"type": "Value", | ||
"children": [ | ||
{ | ||
"class": "Hex", | ||
"type": "Hex", | ||
"name": "6ABF40" | ||
@@ -343,0 +343,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
14318
424