-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 396567c
Showing
109 changed files
with
12,377 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/engine'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var css = require('css'); | ||
var shorthands = require('./properties'); | ||
|
||
module.exports = function(cssString) { | ||
var cssObject = css.parse(cssString); | ||
var longPropertiesPositions = []; | ||
|
||
cssObject.stylesheet.rules.forEach(function(rule) { | ||
if (rule.type === "rule") { | ||
var declarations = []; | ||
|
||
rule.declarations.forEach(function(declaration) { | ||
declarations[declaration.property] = declaration; | ||
}); | ||
|
||
shorthands.forEach(function(shorthand) { | ||
var shorthandValue = shorthand.getShorthandValue(shorthand, declarations); | ||
|
||
if (shorthandValue !== "") { | ||
var newDeclarations = []; | ||
|
||
// Add the new shorthand property | ||
newDeclarations.push({ | ||
type: 'declaration', | ||
property: shorthand.shorthandProperty, | ||
value: shorthandValue | ||
}); | ||
|
||
// Add properties having nothing to do with the property being shorthanded | ||
rule.declarations.forEach(function(declaration) { | ||
if (shorthand.properties.indexOf(declaration.property) <= -1) { | ||
newDeclarations.push(declaration); | ||
} | ||
else { | ||
longPropertiesPositions.push(declaration.position); | ||
} | ||
}); | ||
|
||
rule.declarations = newDeclarations; | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
return { | ||
string: css.stringify(cssObject), | ||
longPropertiesPositions: longPropertiesPositions | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This is the default function that is used to convert most properties to their shorthand version. It simply replaces | ||
var basicShorthandReplace = function(shorthand, declarations) { | ||
var shorthandValue = shorthand.shorthandSyntax; | ||
|
||
shorthand.properties.forEach(function(longProperty) { | ||
if (declarations[longProperty]) { | ||
shorthandValue = shorthandValue.replace(longProperty, declarations[longProperty].value); | ||
} | ||
else { | ||
shorthandValue = shorthandValue.replace(longProperty, ''); | ||
} | ||
}); | ||
|
||
shorthandValue = shorthandValue.replace(' ', ' ').trim(); | ||
return shorthandValue; | ||
}; | ||
|
||
// This array defines all the shorthand properties and their details | ||
module.exports = [{ | ||
shorthandProperty: 'background', | ||
properties: ['background-color', 'background-image', 'background-repeat', 'background-position', 'background-attachment'], | ||
shorthandSyntax: 'background-color background-image background-repeat background-position background-attachment', | ||
getShorthandValue: basicShorthandReplace | ||
}, { | ||
shorthandProperty: 'font', | ||
properties: ['font-style', 'font-variant', 'font-weight', 'font-size', 'line-height', 'font-family'], | ||
shorthandSyntax: 'font-style font-variant font-weight font-size/line-height font-family', | ||
getShorthandValue: function(shorthand, declarations) { | ||
var shorthandValue = basicShorthandReplace(shorthand, declarations); | ||
|
||
// We must at least have size & family or else the shorthand will get ignored by the browser | ||
if (!declarations['font-size'] || !declarations['font-family']) { | ||
return ""; | ||
} | ||
|
||
// Remove slash if line-height is not specified | ||
if (!declarations['line-height']) { | ||
shorthandValue = shorthandValue.replace('/', ''); | ||
} | ||
|
||
return shorthandValue.replace(' ', ' ').trim(); | ||
} | ||
}, { | ||
shorthandProperty: 'border', | ||
properties: ['border-width', 'border-style', 'border-color'], | ||
shorthandSyntax: 'border-width border-style border-color', | ||
getShorthandValue: basicShorthandReplace | ||
}, { | ||
shorthandProperty: 'outline', | ||
properties: ['outline-width', 'outline-style', 'outline-color'], | ||
shorthandSyntax: 'outline-width outline-style outline-color', | ||
getShorthandValue: basicShorthandReplace | ||
}, { | ||
shorthandProperty: 'list-style', | ||
properties: ['list-style-type', 'list-style-position', 'list-style-image'], | ||
shorthandSyntax: 'list-style-type list-style-position list-style-image', | ||
getShorthandValue: basicShorthandReplace | ||
}]; |
Oops, something went wrong.