forked from strarsis/svgo
-
Notifications
You must be signed in to change notification settings - Fork 0
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
deepsweet
committed
Apr 9, 2013
1 parent
f01c7f4
commit 2816424
Showing
36 changed files
with
886 additions
and
935 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 |
---|---|---|
@@ -1,216 +1,40 @@ | ||
plugins: | ||
|
||
- name: removeDoctype | ||
active: true | ||
type: perItem | ||
|
||
- name: removeXMLProcInst | ||
active: true | ||
type: perItem | ||
|
||
- name: removeComments | ||
active: true | ||
type: perItem | ||
|
||
- name: removeMetadata | ||
active: true | ||
type: perItem | ||
|
||
- name: removeEditorsNSData | ||
active: true | ||
type: perItem | ||
|
||
- name: cleanupAttrs | ||
active: true | ||
type: perItem | ||
params: | ||
newlines: true | ||
trim: true | ||
spaces: true | ||
|
||
- name: convertStyleToAttrs | ||
active: true | ||
type: perItem | ||
|
||
- name: removeRasterImages | ||
active: false | ||
type: perItem | ||
|
||
- name: cleanupNumericValues | ||
active: true | ||
type: perItem | ||
params: | ||
floatPrecision: 3 | ||
leadingZero: true | ||
defaultPx: true | ||
|
||
- name: convertColors | ||
active: true | ||
type: perItem | ||
params: | ||
names2hex: true | ||
rgb2hex: true | ||
shorthex: true | ||
|
||
- name: removeUnknownsAndDefaults | ||
active: true | ||
type: perItem | ||
params: | ||
SVGid: true | ||
unknownContent: true | ||
unknownAttrs: true | ||
defaultAttrs: true | ||
|
||
- name: removeNonInheritableGroupAttrs | ||
active: true | ||
type: perItem | ||
|
||
- name: removeUselessStrokeAndFill | ||
active: true | ||
type: perItem | ||
params: | ||
stroke: true | ||
fill: true | ||
|
||
- name: removeViewBox | ||
active: true | ||
type: perItem | ||
|
||
- name: cleanupEnableBackground | ||
active: true | ||
type: perItem | ||
|
||
- name: removeHiddenElems | ||
active: true | ||
type: perItem | ||
params: | ||
displayNone: true | ||
opacity0: true | ||
circleR0: true | ||
ellipseRX0: true | ||
ellipseRY0: true | ||
rectWidth0: true | ||
rectHeight0: true | ||
patternWidth0: true | ||
patternHeight0: true | ||
imageWidth0: true | ||
imageHeight0: true | ||
pathEmptyD: true | ||
polylineEmptyPoints: true | ||
polygonEmptyPoints: true | ||
|
||
- name: removeEmptyText | ||
active: true | ||
type: perItem | ||
params: | ||
text: true | ||
tspan: true | ||
tref: true | ||
|
||
- name: moveElemsAttrsToGroup | ||
active: true | ||
type: perItemReverse | ||
|
||
- name: collapseGroups | ||
active: true | ||
type: perItemReverse | ||
|
||
- name: moveGroupAttrsToElems | ||
active: true | ||
type: perItemReverse | ||
|
||
- name: convertPathData | ||
active: true | ||
type: perItem | ||
params: | ||
applyTransforms: true | ||
straightCurves: true | ||
lineShorthands: true | ||
curveSmoothShorthands: true | ||
floatPrecision: 3 | ||
removeUseless: true | ||
collapseRepeated: true | ||
leadingZero: true | ||
negativeExtraSpace: true | ||
|
||
- name: convertTransform | ||
active: true | ||
type: perItem | ||
params: | ||
convertToShorts: true | ||
floatPrecision: 3 | ||
matrixToTransform: true | ||
shortTranslate: true | ||
shortScale: true | ||
shortRotate: true | ||
removeUseless: true | ||
collapseIntoOne: true | ||
leadingZero: true | ||
negativeExtraSpace: false | ||
|
||
- name: removeEmptyAttrs | ||
active: true | ||
type: perItem | ||
|
||
- name: removeEmptyContainers | ||
active: true | ||
type: perItemReverse | ||
|
||
- name: cleanupIDs | ||
active: true | ||
type: full | ||
params: | ||
remove: true | ||
minify: true | ||
|
||
- name: removeUnusedNS | ||
active: true | ||
type: full | ||
|
||
- name: cropAndCenterAlongPath | ||
active: false | ||
type: full | ||
params: | ||
hcrop: true | ||
vcenter: true | ||
floatPrecision: 3 | ||
leadingZero: true | ||
negativeExtraSpace: true | ||
|
||
svg2js: | ||
|
||
strict: true | ||
trim: true | ||
normalize: true | ||
lowercase: true | ||
xmlns: true | ||
position: false | ||
|
||
js2svg: | ||
|
||
doctypeStart: "<!DOCTYPE" | ||
doctypeEnd: ">" | ||
procInstStart: "<?" | ||
procInstEnd: "?>" | ||
tagOpenStart: "<" | ||
tagOpenEnd: ">" | ||
tagCloseStart: "</" | ||
tagCloseEnd: ">" | ||
tagShortStart: "<" | ||
tagShortEnd: "/>" | ||
attrStart: "=\"" | ||
attrEnd: "\"" | ||
commentStart: "<!--" | ||
commentEnd: "-->" | ||
cdataStart: "<![CDATA[" | ||
cdataEnd: "]]>" | ||
textStart: "" | ||
textEnd: "" | ||
indent: " " | ||
entities: | ||
"&": "&" | ||
"'": "'" | ||
"\"": """ | ||
">": ">" | ||
"<": "<" | ||
pretty: false | ||
# - name | ||
# | ||
# or: | ||
# - name: false | ||
# - name: true | ||
# | ||
# or: | ||
# - name: | ||
# param1: 1 | ||
# param2: 2 | ||
|
||
- removeDoctype | ||
- removeXMLProcInst | ||
- removeComments | ||
- removeMetadata | ||
- removeEditorsNSData | ||
- cleanupAttrs | ||
- convertStyleToAttrs | ||
- removeRasterImages | ||
- cleanupNumericValues | ||
- convertColors | ||
- removeUnknownsAndDefaults | ||
- removeNonInheritableGroupAttrs | ||
- removeUselessStrokeAndFill | ||
- removeViewBox | ||
- cleanupEnableBackground | ||
- removeHiddenElems | ||
- removeEmptyText | ||
- moveElemsAttrsToGroup | ||
- collapseGroups | ||
- moveGroupAttrsToElems | ||
- convertPathData | ||
- convertTransform | ||
- removeEmptyAttrs | ||
- removeEmptyContainers | ||
- cleanupIDs | ||
- removeUnusedNS | ||
- cropAndCenterAlongPath |
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 |
---|---|---|
|
@@ -5,118 +5,32 @@ | |
* | ||
* @see http://deepsweet.github.com/svgo/ | ||
* | ||
* @module svgo | ||
* | ||
* @author Kir Belevich <[email protected]> (https://github.com/deepsweet) | ||
* @copyright © 2012 Kir Belevich | ||
* @license MIT https://raw.github.com/deepsweet/svgo/master/LICENSE | ||
*/ | ||
|
||
var INHERIT = require('inherit'), | ||
Q = require('q'), | ||
FS = require('fs'), | ||
CONFIG = require('./svgo/config'), | ||
var CONFIG = require('./svgo/config'), | ||
SVG2JS = require('./svgo/svg2js'), | ||
PLUGINS = require('./svgo/plugins'), | ||
JS2SVG = require('./svgo/js2svg'), | ||
decodeSVGDatauri = require('./svgo/tools').decodeSVGDatauri; | ||
|
||
/** | ||
* @class SVGO. | ||
*/ | ||
module.exports = INHERIT(/** @lends SVGO.prototype */{ | ||
|
||
/** | ||
* @param {Object} [config] custom config to extend default | ||
* | ||
* @constructs | ||
* | ||
* @private | ||
*/ | ||
__constructor: function(config) { | ||
|
||
this.config = CONFIG(config); | ||
|
||
}, | ||
|
||
/** | ||
* Optimize SVG data from string. | ||
* | ||
* @param {String} str input string | ||
* | ||
* @return {Object} output string deferred promise | ||
*/ | ||
fromString: function(str) { | ||
|
||
var startTime = Date.now(); | ||
|
||
str = decodeSVGDatauri(str); | ||
|
||
return this.config | ||
.then(function(config) { | ||
|
||
return SVG2JS(str, config.svg2js) | ||
.then(function(jsdata) { | ||
|
||
var result = JS2SVG(PLUGINS(jsdata, config.plugins), config.js2svg); | ||
|
||
result.info.inBytes = Buffer.byteLength(str, 'utf-8'); | ||
result.info.outBytes = Buffer.byteLength(result.data, 'utf-8'); | ||
|
||
result.info.time = Date.now() - startTime; | ||
|
||
return result; | ||
|
||
}); | ||
|
||
}); | ||
|
||
}, | ||
|
||
/** | ||
* Optimize SVG data from Stream. | ||
* | ||
* @param {Object} stream input stream | ||
* | ||
* @return {Object} output string deferred promise | ||
*/ | ||
fromStream: function(stream) { | ||
|
||
var deferred = Q.defer(), | ||
inputData = '', | ||
self = this; | ||
JS2SVG = require('./svgo/js2svg'); | ||
|
||
stream.pause(); | ||
var SVGO = module.exports = function(config) { | ||
|
||
stream | ||
.on('data', function(chunk) { | ||
inputData += chunk; | ||
}) | ||
.once('end', function() { | ||
deferred.resolve(inputData); | ||
}) | ||
.resume(); | ||
this.config = CONFIG(config); | ||
|
||
return deferred.promise | ||
.then(function(str) { | ||
}; | ||
|
||
return self.fromString(str); | ||
SVGO.prototype.optimize = function(svgstr, callback) { | ||
|
||
}); | ||
var config = this.config; | ||
|
||
}, | ||
SVG2JS(svgstr, function(svgjs) { | ||
|
||
/** | ||
* Optimize SVG data from file. | ||
* | ||
* @param {String} path file path | ||
* | ||
* @return {Object} output string deferred promise | ||
*/ | ||
fromFile: function(path) { | ||
svgjs = PLUGINS(svgjs, config.plugins); | ||
|
||
return this.fromStream(FS.createReadStream(path, { encoding: 'utf8' })); | ||
callback(JS2SVG(svgjs, config.js2svg)); | ||
|
||
} | ||
}); | ||
|
||
}); | ||
}; |
Oops, something went wrong.