diff --git a/.gitignore b/.gitignore index 2e7b3f5..3c3629e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ node_modules -test.css -test.js diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 4a3c398..0000000 --- a/.npmignore +++ /dev/null @@ -1,6 +0,0 @@ -support -test -examples -*.sock -test.css -test.js diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6e5919d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: node_js -node_js: - - "0.10" diff --git a/History.md b/History.md index 6a916b8..dbc401c 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +2.0.0 / 2014-06-18 +================== + + * update 'css' to 2.0.0 + * depend on the 'css' package, which now contains the stringifier 1.4.1 / 2013-12-09 ================== @@ -9,20 +14,20 @@ * add source map generation -1.3.2 / 2013-10-18 +1.3.2 / 2013-10-18 ================== * fix whitespace and indentation in the Compressed compiler. * add @namespace support * add .stylesheet(node) -1.3.1 / 2013-06-02 +1.3.1 / 2013-06-02 ================== * fix output of rules with no declarations for Identity compiler * fix defaulting of options -1.3.0 / 2013-05-28 +1.3.0 / 2013-05-28 ================== * add ignoring of empty rulesets. Closes #7 @@ -33,38 +38,38 @@ * fix trailing ; with comments within rules * fix comment indentation -1.2.0 / 2013-05-21 +1.2.0 / 2013-05-21 ================== * add @document compilation. Closes #82 -1.1.0 / 2013-03-19 +1.1.0 / 2013-03-19 ================== * add omission of comments when compressed * add comment support -1.0.5 / 2013-03-15 +1.0.5 / 2013-03-15 ================== * fix indentation of multiple selectors in @media. Closes #11 -1.0.4 / 2012-11-15 +1.0.4 / 2012-11-15 ================== * fix indentation -1.0.3 / 2012-09-04 +1.0.3 / 2012-09-04 ================== * add __@charset__ support [rstacruz] -1.0.2 / 2012-09-01 +1.0.2 / 2012-09-01 ================== * add component support -1.0.1 / 2012-07-26 +1.0.1 / 2012-07-26 ================== * add "selectors" array support diff --git a/Makefile b/Makefile deleted file mode 100644 index d78a055..0000000 --- a/Makefile +++ /dev/null @@ -1,8 +0,0 @@ - -test: - @./node_modules/.bin/mocha \ - --require should \ - --reporter spec \ - --bail - -.PHONY: test diff --git a/Readme.md b/Readme.md index 8b691c9..954623d 100644 --- a/Readme.md +++ b/Readme.md @@ -1,63 +1,15 @@ -# css-stringify [![Build Status](https://travis-ci.org/reworkcss/css-stringify.png)](https://travis-ci.org/reworkcss/css-stringify) +# css-stringify - CSS compiler using the AST provided by [css-parse](https://github.com/visionmedia/css-parse). + JavaScript CSS stringifier for Node.js (exports the `stringify` method of [css](https://github.com/reworkcss/css)) -## API +## Installation -### stringify(object, [options]) + $ npm install css-stringify - Accepts an AST `object` from css-parse and returns a CSS string. +## Usage -```js -var stringify = require('css-stringify'); -var parse = require('css-parse'); - -var ast = parse('body { font-size: 12px; }'); -var css = stringify(ast); -``` - - Optionally you may `compress` the output: - -```js -var css = stringify(ast, { compress: true }); -``` - - Or return a `sourcemap` along with the CSS output, - which requires the use of the css-parse `position` option. - -```js -var ast = parse('body { font-size: 12px; }', { position: true }); -var result = stringify(ast, { sourcemap: true }); - -result.code // string with CSS -result.map // source map -``` - -## Performance - - Formats 15,000 lines of CSS (2mb) in 23ms on my macbook air. + Please see the [css](https://github.com/reworkcss/css) module documentation. ## License -(The MIT License) - -Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca> - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -'Software'), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + MIT diff --git a/component.json b/component.json deleted file mode 100644 index 816685f..0000000 --- a/component.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "css-stringify", - "repo": "reworkcss/css-stringify", - "version": "1.4.1", - "description": "CSS compiler", - "keywords": ["css", "stringify", "stylesheet"], - "scripts": [ - "index.js", - "lib/compress.js", - "lib/identity.js", - "lib/compiler.js", - "lib/source-map-support.js" - ] -} diff --git a/examples/comments.css b/examples/comments.css deleted file mode 100644 index 87e95a3..0000000 --- a/examples/comments.css +++ /dev/null @@ -1,8 +0,0 @@ -/* comment */ - -body { - /* foo */ - /* bar */ - color: #eee; - /* baz */ -} diff --git a/examples/comments.js b/examples/comments.js deleted file mode 100644 index c255105..0000000 --- a/examples/comments.js +++ /dev/null @@ -1,12 +0,0 @@ - -/** - * Module dependencies. - */ - -var parse = require('css-parse') - , stringify = require('..') - , fs = require('fs') - , read = fs.readFileSync - , css = read('examples/comments.css', 'utf8'); - -console.log(stringify(parse(css))); diff --git a/examples/dialog.css b/examples/dialog.css deleted file mode 100644 index df74183..0000000 --- a/examples/dialog.css +++ /dev/null @@ -1,92 +0,0 @@ -#dialog { - position: fixed; - left: 50%; - top: 150px; - max-width: 600px; - min-width: 250px; - border: 1px solid #eee; - background: white; - z-index: 1000; -} - -#dialog .content { - padding: 15px 20px; -} - -#dialog h1 { - margin: 0 0 5px 0; - font-size: 16px; - font-weight: normal; -} - -#dialog p { - margin: 0; - padding: 0; - font-size: .9em; -} - -#dialog.modal { - box-shadow: 0 1px 8px 0 black; -} - -/* close */ - -#dialog .close { - position: absolute; - top: 3px; - right: 10px; - text-decoration: none; - color: #888; - font-size: 16px; - font-weight: bold; - display: none; -} - -#dialog.closable .close { - display: block; -} - -#dialog .close:hover { - color: black; -} - -#dialog .close:active { - margin-top: 1px; -} - -/* slide */ - -#dialog.slide { - -webkit-transition: opacity 300ms, top 300ms; - -moz-transition: opacity 300ms, top 300ms; -} - -#dialog.slide.hide { - opacity: 0; - top: -500px; -} - -/* fade */ - -#dialog.fade { - -webkit-transition: opacity 300ms; - -moz-transition: opacity 300ms; -} - -#dialog.fade.hide { - opacity: 0; -} - -/* scale */ - -#dialog.scale { - -webkit-transition: -webkit-transform 300ms; - -moz-transition: -moz-transform 300ms; - -webkit-transform: scale(1); - -moz-transform: scale(1); -} - -#dialog.scale.hide { - -webkit-transform: scale(0); - -moz-transform: scale(0); -} \ No newline at end of file diff --git a/examples/dialog.js b/examples/dialog.js deleted file mode 100644 index 69cb6fe..0000000 --- a/examples/dialog.js +++ /dev/null @@ -1,12 +0,0 @@ - -/** - * Module dependencies. - */ - -var parse = require('css-parse') - , stringify = require('..') - , fs = require('fs') - , read = fs.readFileSync - , css = read('examples/dialog.css', 'utf8'); - -console.log(stringify(parse(css), { compress: true })); diff --git a/examples/document.css b/examples/document.css deleted file mode 100644 index 7ddf3d6..0000000 --- a/examples/document.css +++ /dev/null @@ -1,17 +0,0 @@ -@-moz-document url-prefix() { - .icon-spin { - height: .9em - } - - .btn .icon-spin { - height: auto - } - - .icon-spin.icon-large { - height: 1.25em - } - - .btn .icon-spin.icon-large { - height: .75em - } -} diff --git a/examples/document.js b/examples/document.js deleted file mode 100644 index 3fc8793..0000000 --- a/examples/document.js +++ /dev/null @@ -1,12 +0,0 @@ - -/** - * Module dependencies. - */ - -var parse = require('css-parse') - , stringify = require('..') - , fs = require('fs') - , read = fs.readFileSync - , css = read('examples/document.css', 'utf8'); - -console.log(stringify(parse(css), { compress: false })); diff --git a/examples/empty.css b/examples/empty.css deleted file mode 100644 index c14f1e9..0000000 --- a/examples/empty.css +++ /dev/null @@ -1,4 +0,0 @@ - -body { - -} diff --git a/examples/empty.js b/examples/empty.js deleted file mode 100644 index 3c32c33..0000000 --- a/examples/empty.js +++ /dev/null @@ -1,12 +0,0 @@ - -/** - * Module dependencies. - */ - -var parse = require('css-parse') - , stringify = require('..') - , fs = require('fs') - , read = fs.readFileSync - , css = read('examples/empty.css', 'utf8'); - -console.log(stringify(parse(css), { compress: true })); diff --git a/examples/keyframes.css b/examples/keyframes.css deleted file mode 100644 index a50d14a..0000000 --- a/examples/keyframes.css +++ /dev/null @@ -1,10 +0,0 @@ -@keyframes fade { - from { - opacity: 0; - opacity: 1 - } - - to { - opacity: 1 - } -} \ No newline at end of file diff --git a/examples/keyframes.js b/examples/keyframes.js deleted file mode 100644 index 7454ff9..0000000 --- a/examples/keyframes.js +++ /dev/null @@ -1,12 +0,0 @@ - -/** - * Module dependencies. - */ - -var parse = require('css-parse') - , stringify = require('..') - , fs = require('fs') - , read = fs.readFileSync - , css = read('examples/keyframes.css', 'utf8'); - -console.log(stringify(parse(css), { compress: true })); diff --git a/examples/media.css b/examples/media.css deleted file mode 100644 index d50e65b..0000000 --- a/examples/media.css +++ /dev/null @@ -1,27 +0,0 @@ - -/* some comment */ - -@media screen, projection { - html { - background: #fffef0; - color: #300; - } - - body { - max-width: 35em; - margin: 0 auto; - } -} - -@media print { - html { - background: #fff; - color: #000; - } - - body, - #content { - padding: 1in; - border: 0.5pt solid #666; - } -} diff --git a/examples/media.js b/examples/media.js deleted file mode 100644 index ec5bcf5..0000000 --- a/examples/media.js +++ /dev/null @@ -1,12 +0,0 @@ - -/** - * Module dependencies. - */ - -var parse = require('css-parse') - , stringify = require('..') - , fs = require('fs') - , read = fs.readFileSync - , css = read('examples/media.css', 'utf8'); - -console.log(stringify(parse(css), { compress: false })); diff --git a/examples/page.css b/examples/page.css deleted file mode 100644 index a413d84..0000000 --- a/examples/page.css +++ /dev/null @@ -1,8 +0,0 @@ -@page { - size: auto; - margin: 10% -} - -@page foo, bar { - bar: baz -} diff --git a/examples/page.js b/examples/page.js deleted file mode 100644 index 1d402aa..0000000 --- a/examples/page.js +++ /dev/null @@ -1,12 +0,0 @@ - -/** - * Module dependencies. - */ - -var parse = require('css-parse') - , stringify = require('..') - , fs = require('fs') - , read = fs.readFileSync - , css = read('examples/page.css', 'utf8'); - -console.log(stringify(parse(css), { compress: false })); diff --git a/examples/sourcemaps.js b/examples/sourcemaps.js deleted file mode 100644 index ef1fe4b..0000000 --- a/examples/sourcemaps.js +++ /dev/null @@ -1,12 +0,0 @@ - -/** - * Module dependencies. - */ - -var parse = require('css-parse') - , stringify = require('..') - , fs = require('fs') - , read = fs.readFileSync - , css = read('examples/media.css', 'utf8'); - -console.log(stringify(parse(css), { compress: false, sourcemap: true })); diff --git a/index.js b/index.js index 7c3dbc4..b4c1752 100644 --- a/index.js +++ b/index.js @@ -1,42 +1 @@ - -/** - * Module dependencies. - */ - -var Compressed = require('./lib/compress'); -var Identity = require('./lib/identity'); - -/** - * Stringfy the given AST `node`. - * - * Options: - * - * - `compress` space-optimized output - * - `sourcemap` return an object with `.code` and `.map` - * - * @param {Object} node - * @param {Object} [options] - * @return {String} - * @api public - */ - -module.exports = function(node, options){ - options = options || {}; - - var compiler = options.compress - ? new Compressed(options) - : new Identity(options); - - // source maps - if (options.sourcemap) { - var sourcemaps = require('./lib/source-map-support'); - sourcemaps(compiler); - - var code = compiler.compile(node); - return { code: code, map: compiler.map.toJSON() }; - } - - var code = compiler.compile(node); - return code; -}; - +module.exports = require('css').stringify; diff --git a/lib/compiler.js b/lib/compiler.js deleted file mode 100644 index 6d01a14..0000000 --- a/lib/compiler.js +++ /dev/null @@ -1,50 +0,0 @@ - -/** - * Expose `Compiler`. - */ - -module.exports = Compiler; - -/** - * Initialize a compiler. - * - * @param {Type} name - * @return {Type} - * @api public - */ - -function Compiler(opts) { - this.options = opts || {}; -} - -/** - * Emit `str` - */ - -Compiler.prototype.emit = function(str) { - return str; -}; - -/** - * Visit `node`. - */ - -Compiler.prototype.visit = function(node){ - return this[node.type](node); -}; - -/** - * Map visit over array of `nodes`, optionally using a `delim` - */ - -Compiler.prototype.mapVisit = function(nodes, delim){ - var buf = ''; - delim = delim || ''; - - for (var i = 0, length = nodes.length; i < length; i++) { - buf += this.visit(nodes[i]); - if (delim && i < length - 1) buf += this.emit(delim); - } - - return buf; -}; diff --git a/lib/compress.js b/lib/compress.js deleted file mode 100644 index 601bd73..0000000 --- a/lib/compress.js +++ /dev/null @@ -1,168 +0,0 @@ - -/** - * Module dependencies. - */ - -var Base = require('./compiler'); - -/** - * Expose compiler. - */ - -module.exports = Compiler; - -/** - * Initialize a new `Compiler`. - */ - -function Compiler(options) { - Base.call(this, options); -} - -/** - * Inherit from `Base.prototype`. - */ - -Compiler.prototype.__proto__ = Base.prototype; - -/** - * Compile `node`. - */ - -Compiler.prototype.compile = function(node){ - return node.stylesheet - .rules.map(this.visit, this) - .join(''); -}; - -/** - * Visit comment node. - */ - -Compiler.prototype.comment = function(node){ - return this.emit('', node.position); -}; - -/** - * Visit import node. - */ - -Compiler.prototype.import = function(node){ - return this.emit('@import ' + node.import + ';', node.position); -}; - -/** - * Visit media node. - */ - -Compiler.prototype.media = function(node){ - return this.emit('@media ' + node.media, node.position, true) - + this.emit('{') - + this.mapVisit(node.rules) - + this.emit('}'); -}; - -/** - * Visit document node. - */ - -Compiler.prototype.document = function(node){ - var doc = '@' + (node.vendor || '') + 'document ' + node.document; - - return this.emit(doc, node.position, true) - + this.emit('{') - + this.mapVisit(node.rules) - + this.emit('}'); -}; - -/** - * Visit charset node. - */ - -Compiler.prototype.charset = function(node){ - return this.emit('@charset ' + node.charset + ';', node.position); -}; - -/** - * Visit namespace node. - */ - -Compiler.prototype.namespace = function(node){ - return this.emit('@namespace ' + node.namespace + ';', node.position); -}; - -/** - * Visit supports node. - */ - -Compiler.prototype.supports = function(node){ - return this.emit('@supports ' + node.supports, node.position, true) - + this.emit('{') - + this.mapVisit(node.rules) - + this.emit('}'); -}; - -/** - * Visit keyframes node. - */ - -Compiler.prototype.keyframes = function(node){ - return this.emit('@' - + (node.vendor || '') - + 'keyframes ' - + node.name, node.position, true) - + this.emit('{') - + this.mapVisit(node.keyframes) - + this.emit('}'); -}; - -/** - * Visit keyframe node. - */ - -Compiler.prototype.keyframe = function(node){ - var decls = node.declarations; - - return this.emit(node.values.join(','), node.position, true) - + this.emit('{') - + this.mapVisit(decls) - + this.emit('}'); -}; - -/** - * Visit page node. - */ - -Compiler.prototype.page = function(node){ - var sel = node.selectors.length - ? node.selectors.join(', ') - : ''; - - return this.emit('@page ' + sel, node.position, true) - + this.emit('{') - + this.mapVisit(node.declarations) - + this.emit('}'); -}; - -/** - * Visit rule node. - */ - -Compiler.prototype.rule = function(node){ - var decls = node.declarations; - if (!decls.length) return ''; - - return this.emit(node.selectors.join(','), node.position, true) - + this.emit('{') - + this.mapVisit(decls) - + this.emit('}'); -}; - -/** - * Visit declaration node. - */ - -Compiler.prototype.declaration = function(node){ - return this.emit(node.property + ':' + node.value, node.position) + this.emit(';'); -}; - diff --git a/lib/identity.js b/lib/identity.js deleted file mode 100644 index cc9fd5c..0000000 --- a/lib/identity.js +++ /dev/null @@ -1,217 +0,0 @@ - -/** - * Module dependencies. - */ - -var Base = require('./compiler'); - -/** - * Expose compiler. - */ - -module.exports = Compiler; - -/** - * Initialize a new `Compiler`. - */ - -function Compiler(options) { - options = options || {}; - Base.call(this, options); - this.indentation = options.indent; -} - -/** - * Inherit from `Base.prototype`. - */ - -Compiler.prototype.__proto__ = Base.prototype; - -/** - * Compile `node`. - */ - -Compiler.prototype.compile = function(node){ - return this.stylesheet(node); -}; - -/** - * Visit stylesheet node. - */ - -Compiler.prototype.stylesheet = function(node){ - return this.mapVisit(node.stylesheet.rules, '\n\n'); -}; - -/** - * Visit comment node. - */ - -Compiler.prototype.comment = function(node){ - return this.emit(this.indent() + '/*' + node.comment + '*/', node.position); -}; - -/** - * Visit import node. - */ - -Compiler.prototype.import = function(node){ - return this.emit('@import ' + node.import + ';', node.position); -}; - -/** - * Visit media node. - */ - -Compiler.prototype.media = function(node){ - return this.emit('@media ' + node.media, node.position, true) - + this.emit( - ' {\n' - + this.indent(1)) - + this.mapVisit(node.rules, '\n\n') - + this.emit( - this.indent(-1) - + '\n}'); -}; - -/** - * Visit document node. - */ - -Compiler.prototype.document = function(node){ - var doc = '@' + (node.vendor || '') + 'document ' + node.document; - - return this.emit(doc, node.position, true) - + this.emit( - ' ' - + ' {\n' - + this.indent(1)) - + this.mapVisit(node.rules, '\n\n') - + this.emit( - this.indent(-1) - + '\n}'); -}; - -/** - * Visit charset node. - */ - -Compiler.prototype.charset = function(node){ - return this.emit('@charset ' + node.charset + ';', node.position); -}; - -/** - * Visit namespace node. - */ - -Compiler.prototype.namespace = function(node){ - return this.emit('@namespace ' + node.namespace + ';', node.position); -}; - -/** - * Visit supports node. - */ - -Compiler.prototype.supports = function(node){ - return this.emit('@supports ' + node.supports, node.position, true) - + this.emit( - ' {\n' - + this.indent(1)) - + this.mapVisit(node.rules, '\n\n') - + this.emit( - this.indent(-1) - + '\n}'); -}; - -/** - * Visit keyframes node. - */ - -Compiler.prototype.keyframes = function(node){ - return this.emit('@' + (node.vendor || '') + 'keyframes ' + node.name, node.position, true) - + this.emit( - ' {\n' - + this.indent(1)) - + this.mapVisit(node.keyframes, '\n') - + this.emit( - this.indent(-1) - + '}'); -}; - -/** - * Visit keyframe node. - */ - -Compiler.prototype.keyframe = function(node){ - var decls = node.declarations; - - return this.emit(this.indent()) - + this.emit(node.values.join(', '), node.position, true) - + this.emit( - ' {\n' - + this.indent(1)) - + this.mapVisit(decls, '\n') - + this.emit( - this.indent(-1) - + '\n' - + this.indent() + '}\n'); -}; - -/** - * Visit page node. - */ - -Compiler.prototype.page = function(node){ - var sel = node.selectors.length - ? node.selectors.join(', ') + ' ' - : ''; - - return this.emit('@page ' + sel, node.position, true) - + this.emit('{\n') - + this.emit(this.indent(1)) - + this.mapVisit(node.declarations, '\n') - + this.emit(this.indent(-1)) - + this.emit('\n}'); -}; - -/** - * Visit rule node. - */ - -Compiler.prototype.rule = function(node){ - var indent = this.indent(); - var decls = node.declarations; - if (!decls.length) return ''; - - return this.emit(node.selectors.map(function(s){ return indent + s }).join(',\n'), node.position, true) - + this.emit(' {\n') - + this.emit(this.indent(1)) - + this.mapVisit(decls, '\n') - + this.emit(this.indent(-1)) - + this.emit('\n' + this.indent() + '}'); -}; - -/** - * Visit declaration node. - */ - -Compiler.prototype.declaration = function(node){ - return this.emit(this.indent()) - + this.emit(node.property + ': ' + node.value, node.position) - + this.emit(';'); -}; - -/** - * Increase, decrease or return current indentation. - */ - -Compiler.prototype.indent = function(level) { - this.level = this.level || 1; - - if (null != level) { - this.level += level; - return ''; - } - - return Array(this.level).join(this.indentation || ' '); -}; diff --git a/lib/source-map-support.js b/lib/source-map-support.js deleted file mode 100644 index 1e60513..0000000 --- a/lib/source-map-support.js +++ /dev/null @@ -1,84 +0,0 @@ - -/** - * Module dependencies. - */ - -var SourceMap = require('source-map').SourceMapGenerator; - -/** - * Expose `mixin()`. - */ - -module.exports = mixin; - -/** - * Mixin source map support into `compiler`. - * - * @param {Compiler} compiler - * @api public - */ - -function mixin(compiler) { - var file = compiler.options.filename || 'generated.css'; - compiler.map = new SourceMap({ file: file }); - compiler.position = { line: 1, column: 1 }; - for (var k in exports) compiler[k] = exports[k]; -} - -/** - * Update position. - * - * @param {String} str - * @api private - */ - -exports.updatePosition = function(str) { - var lines = str.match(/\n/g); - if (lines) this.position.line += lines.length; - var i = str.lastIndexOf('\n'); - this.position.column = ~i ? str.length - i : this.position.column + str.length; -}; - -/** - * Emit `str`. - * - * @param {String} str - * @param {Number} [pos] - * @param {Boolean} [startOnly] - * @return {String} - * @api private - */ - -exports.emit = function(str, pos, startOnly) { - if (pos && pos.start) { - this.map.addMapping({ - source: pos.source || 'source.css', - generated: { - line: this.position.line, - column: Math.max(this.position.column - 1, 0) - }, - original: { - line: pos.start.line, - column: pos.start.column - 1 - } - }); - } - - this.updatePosition(str); - - if (!startOnly && pos && pos.end) { - this.map.addMapping({ - source: pos.source || 'source.css', - generated: { - line: this.position.line, - column: Math.max(this.position.column - 1, 0) - }, - original: { - line: pos.end.line, - column: pos.end.column - 1 - } - }); - } - - return str; -}; diff --git a/package.json b/package.json index d1771a7..3f55a24 100644 --- a/package.json +++ b/package.json @@ -1,27 +1,23 @@ { "name": "css-stringify", - "version": "1.4.1", + "version": "2.0.0", "description": "CSS compiler", - "keywords": [ - "css", - "stringify", - "stylesheet" + "main": "index", + "files": [ + "index.js" ], - "author": "TJ Holowaychuk ", - "devDependencies": { - "mocha": "*", - "should": "*", - "css-parse": "1.6.0" + "dependencies": { + "css": "^2.0.0" }, - "main": "index", + "author": "TJ Holowaychuk ", + "license": "MIT", "repository": { "type": "git", "url": "https://github.com/reworkcss/css-stringify.git" }, - "scripts": { - "test": "make test" - }, - "dependencies": { - "source-map": "~0.1.31" - } + "keywords": [ + "css", + "stringify", + "stylesheet" + ] } diff --git a/test/cases/at_charset.css b/test/cases/at_charset.css deleted file mode 100644 index e63c05c..0000000 --- a/test/cases/at_charset.css +++ /dev/null @@ -1 +0,0 @@ -@charset "utf-8"; diff --git a/test/cases/at_namespace.css b/test/cases/at_namespace.css deleted file mode 100644 index edc75cf..0000000 --- a/test/cases/at_namespace.css +++ /dev/null @@ -1 +0,0 @@ -@namespace svg "http://www.w3.org/2000/svg"; diff --git a/test/cases/comments.compressed.css b/test/cases/comments.compressed.css deleted file mode 100644 index 7ca44b1..0000000 --- a/test/cases/comments.compressed.css +++ /dev/null @@ -1 +0,0 @@ -body{color:#eee;} diff --git a/test/cases/comments.css b/test/cases/comments.css deleted file mode 100644 index 87e95a3..0000000 --- a/test/cases/comments.css +++ /dev/null @@ -1,8 +0,0 @@ -/* comment */ - -body { - /* foo */ - /* bar */ - color: #eee; - /* baz */ -} diff --git a/test/cases/document.compressed.css b/test/cases/document.compressed.css deleted file mode 100644 index d56d0a5..0000000 --- a/test/cases/document.compressed.css +++ /dev/null @@ -1 +0,0 @@ -@-moz-document url-prefix(){.icon-spin{height:.9em;}.btn .icon-spin{height:auto;}.icon-spin.icon-large{height:1.25em;}.btn .icon-spin.icon-large{height:.75em;}} diff --git a/test/cases/document.css b/test/cases/document.css deleted file mode 100644 index e6302e7..0000000 --- a/test/cases/document.css +++ /dev/null @@ -1,17 +0,0 @@ -@-moz-document url-prefix() { - .icon-spin { - height: .9em; - } - - .btn .icon-spin { - height: auto; - } - - .icon-spin.icon-large { - height: 1.25em; - } - - .btn .icon-spin.icon-large { - height: .75em; - } -} diff --git a/test/cases/import.css b/test/cases/import.css deleted file mode 100644 index ebeed7b..0000000 --- a/test/cases/import.css +++ /dev/null @@ -1 +0,0 @@ -@import 'foo.css'; \ No newline at end of file diff --git a/test/cases/keyframes.compressed.css b/test/cases/keyframes.compressed.css deleted file mode 100644 index 75a9dbb..0000000 --- a/test/cases/keyframes.compressed.css +++ /dev/null @@ -1 +0,0 @@ -@keyframes fade{from{opacity:0;opacity:1;}to{opacity:1;}} diff --git a/test/cases/keyframes.css b/test/cases/keyframes.css deleted file mode 100644 index e8ed694..0000000 --- a/test/cases/keyframes.css +++ /dev/null @@ -1,10 +0,0 @@ -@keyframes fade { - from { - opacity: 0; - opacity: 1; - } - - to { - opacity: 1; - } -} diff --git a/test/cases/media.compressed.css b/test/cases/media.compressed.css deleted file mode 100644 index a34785a..0000000 --- a/test/cases/media.compressed.css +++ /dev/null @@ -1 +0,0 @@ -@media screen, projection{html{background:#fffef0;color:#300;}body{max-width:35em;margin:0 auto;}}@media print{html{background:#fff;color:#000;}body{padding:1in;border:0.5pt solid #666;}} diff --git a/test/cases/media.css b/test/cases/media.css deleted file mode 100644 index c234e7d..0000000 --- a/test/cases/media.css +++ /dev/null @@ -1,23 +0,0 @@ -@media screen, projection { - html { - background: #fffef0; - color: #300; - } - - body { - max-width: 35em; - margin: 0 auto; - } -} - -@media print { - html { - background: #fff; - color: #000; - } - - body { - padding: 1in; - border: 0.5pt solid #666; - } -} diff --git a/test/cases/page.compressed.css b/test/cases/page.compressed.css deleted file mode 100644 index 84595d2..0000000 --- a/test/cases/page.compressed.css +++ /dev/null @@ -1 +0,0 @@ -@page {margin:2.5cm;}@page :left{margin-left:5cm;}@page :right{margin-right:5cm;}@page :first{margin-top:8cm;} \ No newline at end of file diff --git a/test/cases/page.css b/test/cases/page.css deleted file mode 100644 index 34f2a09..0000000 --- a/test/cases/page.css +++ /dev/null @@ -1,15 +0,0 @@ -@page { - margin: 2.5cm; -} - -@page :left { - margin-left: 5cm; -} - -@page :right { - margin-right: 5cm; -} - -@page :first { - margin-top: 8cm; -} diff --git a/test/cases/rules.compressed.css b/test/cases/rules.compressed.css deleted file mode 100644 index 3a4188c..0000000 --- a/test/cases/rules.compressed.css +++ /dev/null @@ -1 +0,0 @@ -tobi{name:'tobi';age:2;}loki{name:'loki';age:1;} diff --git a/test/cases/rules.css b/test/cases/rules.css deleted file mode 100644 index 5b98d01..0000000 --- a/test/cases/rules.css +++ /dev/null @@ -1,9 +0,0 @@ -tobi { - name: 'tobi'; - age: 2; -} - -loki { - name: 'loki'; - age: 1; -} diff --git a/test/cases/selectors.compressed.css b/test/cases/selectors.compressed.css deleted file mode 100644 index ee0faf9..0000000 --- a/test/cases/selectors.compressed.css +++ /dev/null @@ -1 +0,0 @@ -foo,bar,baz{color:'black';} diff --git a/test/cases/selectors.css b/test/cases/selectors.css deleted file mode 100644 index 9f214f1..0000000 --- a/test/cases/selectors.css +++ /dev/null @@ -1,5 +0,0 @@ -foo, -bar, -baz { - color: 'black'; -} diff --git a/test/cases/supports.compressed.css b/test/cases/supports.compressed.css deleted file mode 100644 index 61d4ee2..0000000 --- a/test/cases/supports.compressed.css +++ /dev/null @@ -1 +0,0 @@ -@supports (display: flex){div{display:flex;}div{something:else;}} diff --git a/test/cases/supports.css b/test/cases/supports.css deleted file mode 100644 index 37952f1..0000000 --- a/test/cases/supports.css +++ /dev/null @@ -1,9 +0,0 @@ -@supports (display: flex) { - div { - display: flex; - } - - div { - something: else; - } -} diff --git a/test/css-stringify.js b/test/css-stringify.js deleted file mode 100644 index b37ee7f..0000000 --- a/test/css-stringify.js +++ /dev/null @@ -1,70 +0,0 @@ - -/** - * Module dependencies. - */ - -var stringify = require('..') - , parse = require('css-parse') - , fs = require('fs') - , path = require('path') - , read = fs.readFileSync - , readdir = fs.readdirSync - , SourceMapConsumer = require('source-map').SourceMapConsumer; - -describe('stringify(obj)', function(){ - readdir('test/cases').forEach(function(file){ - var compress = ~file.indexOf('.compressed'); - it('should stringify ' + path.basename(file), function(){ - var expect; - if (compress) { - expect = read(path.join('test', 'cases', file), 'utf8'); - file = file.replace('.compressed', ''); - } - var css = read(path.join('test', 'cases', file), 'utf8'); - var ret = stringify(parse(css), { compress: compress }); - ret.trim().should.equal((expect || css).trim()); - }); - }); -}); - -describe('stringify(obj, {sourcemap: true})', function(){ - var src = read('test/source-map-case.css', 'utf8'); - var stylesheet = parse(src, { source: 'rules.css', position: true }); - function loc(line, column) { - return { line: line, column: column, source: 'rules.css', name: null } - }; - - var locs = { - tobiSelector: loc(1, 0), - tobiNameName: loc(2, 2), - tobiNameValue: loc(2, 2), - mediaBlock: loc(11, 0), - mediaOnly: loc(12, 2), - comment: loc(17, 0), - }; - - it('should generate source maps alongside when using identity compiler', function(){ - var result = stringify(stylesheet, { sourcemap: true }); - result.should.have.property('code'); - result.should.have.property('map'); - var map = new SourceMapConsumer(result.map); - map.originalPositionFor({ line: 1, column: 0 }).should.eql(locs.tobiSelector); - map.originalPositionFor({ line: 2, column: 2 }).should.eql(locs.tobiNameName); - map.originalPositionFor({ line: 2, column: 8 }).should.eql(locs.tobiNameValue); - map.originalPositionFor({ line: 11, column: 0 }).should.eql(locs.mediaBlock); - map.originalPositionFor({ line: 12, column: 2 }).should.eql(locs.mediaOnly); - map.originalPositionFor({ line: 17, column: 0 }).should.eql(locs.comment); - }); - - it('should generate source maps alongside when using compress compiler', function(){ - var result = stringify(stylesheet, { compress: true, sourcemap: true }); - result.should.have.property('code'); - result.should.have.property('map'); - var map = new SourceMapConsumer(result.map); - map.originalPositionFor({ line: 1, column: 0 }).should.eql(locs.tobiSelector); - map.originalPositionFor({ line: 1, column: 5 }).should.eql(locs.tobiNameName); - map.originalPositionFor({ line: 1, column: 10 }).should.eql(locs.tobiNameValue); - map.originalPositionFor({ line: 1, column: 50 }).should.eql(locs.mediaBlock); - map.originalPositionFor({ line: 1, column: 64 }).should.eql(locs.mediaOnly); - }); -}); diff --git a/test/source-map-case.css b/test/source-map-case.css deleted file mode 100644 index 47598d7..0000000 --- a/test/source-map-case.css +++ /dev/null @@ -1,17 +0,0 @@ -tobi { - name: 'tobi'; - age: 2; -} - -loki { - name: 'loki'; - age: 1; -} - -@media screen { - screen-only { - display: block; - } -} - -/* comment */