0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

101
web/node_modules/rework/Readme.md generated vendored Normal file
View file

@ -0,0 +1,101 @@
# rework [![Build Status](https://travis-ci.org/reworkcss/rework.png)](https://travis-ci.org/reworkcss/rework)
CSS manipulations built on [`css`](https://github.com/reworkcss/css), allowing
you to automate vendor prefixing, create your own properties, inline images,
anything you can imagine!
Please refer to [`css`](https://github.com/reworkcss/css) for AST documentation
and to report parser/stringifier issues.
## Installation
$ npm install rework
## Usage
```js
var rework = require('rework');
var pluginA = require('pluginA');
var pluginB = require('pluginB');
rework('body { font-size: 12px; }', { source: 'source.css' })
.use(pluginA)
.use(pluginB)
.toString({ sourcemap: true })
```
## API
### rework(code, [options])
Accepts a CSS string and returns a new `Rework` instance. The `options` are
passed directly to `css.parse`.
### Rework#use(fn)
Use the given plugin `fn`. A rework "plugin" is simply a function accepting the
stylesheet root node and the `Rework` instance.
### Rework#toString([options])
Returns the string representation of the manipulated CSS. The `options` are
passed directly to `css.stringify`.
Unlike `css.stringify`, if you pass `sourcemap: true` a string will still be
returned, with the source map inlined. Also use `sourcemapAsObject: true` if
you want the `css.stringify` return value.
## Plugins
Rework has a rich collection of plugins and mixins. Browse all the [Rework
plugins](https://www.npmjs.org/search?q=rework) available on npm.
Plugins of particular note:
- [at2x](https://github.com/reworkcss/rework-plugin-at2x/) serve high resolution images
- [calc](https://github.com/reworkcss/rework-calc) resolve simple `calc()` expressions
- [colors](https://github.com/reworkcss/rework-plugin-colors/) color helpers like `rgba(#fc0, .5)`
- [ease](https://github.com/reworkcss/rework-plugin-ease/) several additional easing functions
- [extend](https://github.com/reworkcss/rework-inherit/) `extend: selector` support
- [function](https://github.com/reworkcss/rework-plugin-function/) user-defined CSS functions
- [import](https://github.com/reworkcss/rework-import) read and inline CSS via `@import`
- [inline](https://github.com/reworkcss/rework-plugin-inline) inline assets as data URIs
- [mixin](https://github.com/reworkcss/rework-plugin-mixin/) custom property logic with mixins
- [npm](https://github.com/reworkcss/rework-npm) - inline CSS via `@import` using node's module resolver
- [references](https://github.com/reworkcss/rework-plugin-references/) property references like `height: @width`
- [url](https://github.com/reworkcss/rework-plugin-url/) rewrite `url()`s with a given function
- [variables](https://github.com/reworkcss/rework-vars/) W3C-style variables
## Built with rework
- [styl](https://github.com/visionmedia/styl)
- [rework-pure-css](https://github.com/ianstormtaylor/rework-pure-css)
- [rework-suit](https://github.com/suitcss/rework-suit)
- [resin](https://github.com/topcoat/resin)
- [Myth](https://github.com/segmentio/myth)
## License
(The MIT License)
Copyright (c) 20122013 TJ Holowaychuk <tj@vision-media.ca>
Copyright (c) 2014 Contributors
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.

82
web/node_modules/rework/index.js generated vendored Normal file
View file

@ -0,0 +1,82 @@
/**
* Module dependencies.
*/
var css = require('css');
var convertSourceMap = require('convert-source-map');
var parse = css.parse;
var stringify = css.stringify;
/**
* Expose `rework`.
*/
exports = module.exports = rework;
/**
* Initialize a new stylesheet `Rework` with `str`.
*
* @param {String} str
* @param {Object} options
* @return {Rework}
* @api public
*/
function rework(str, options) {
return new Rework(parse(str, options));
}
/**
* Initialize a new stylesheet `Rework` with `obj`.
*
* @param {Object} obj
* @api private
*/
function Rework(obj) {
this.obj = obj;
}
/**
* Use the given plugin `fn(style, rework)`.
*
* @param {Function} fn
* @return {Rework}
* @api public
*/
Rework.prototype.use = function(fn){
fn(this.obj.stylesheet, this);
return this;
};
/**
* Stringify the stylesheet.
*
* @param {Object} options
* @return {String}
* @api public
*/
Rework.prototype.toString = function(options){
options = options || {};
var result = stringify(this.obj, options);
if (options.sourcemap && !options.sourcemapAsObject) {
result = result.code + '\n' + sourcemapToComment(result.map);
}
return result;
};
/**
* Convert sourcemap to base64-encoded comment
*
* @param {Object} map
* @return {String}
* @api private
*/
function sourcemapToComment(map) {
var content = convertSourceMap.fromObject(map).toBase64();
return '/*# sourceMappingURL=data:application/json;base64,' + content + ' */';
}

View file

@ -0,0 +1,16 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
node_modules
npm-debug.log
tmp

View file

@ -0,0 +1,5 @@
language: node_js
node_js:
- 0.8
- 0.10
- 0.11

View file

@ -0,0 +1,23 @@
Copyright 2013 Thorsten Lorenz.
All rights reserved.
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.

View file

@ -0,0 +1,114 @@
# convert-source-map [![build status](https://secure.travis-ci.org/thlorenz/convert-source-map.png)](http://travis-ci.org/thlorenz/convert-source-map)
[![NPM](https://nodei.co/npm/convert-source-map.png?downloads=true&stars=true)](https://nodei.co/npm/convert-source-map/)
Converts a source-map from/to different formats and allows adding/changing properties.
```js
var convert = require('convert-source-map');
var json = convert
.fromComment('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9vLmpzIiwic291cmNlcyI6WyJjb25zb2xlLmxvZyhcImhpXCIpOyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=')
.toJSON();
var modified = convert
.fromComment('//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9vLmpzIiwic291cmNlcyI6WyJjb25zb2xlLmxvZyhcImhpXCIpOyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=')
.setProperty('sources', [ 'CONSOLE.LOG("HI");' ])
.toJSON();
console.log(json);
console.log(modified);
```
```json
{"version":3,"file":"foo.js","sources":["console.log(\"hi\");"],"names":[],"mappings":"AAAA","sourceRoot":"/"}
{"version":3,"file":"foo.js","sources":["CONSOLE.LOG(\"HI\");"],"names":[],"mappings":"AAAA","sourceRoot":"/"}
```
## API
### fromObject(obj)
Returns source map converter from given object.
### fromJSON(json)
Returns source map converter from given json string.
### fromBase64(base64)
Returns source map converter from given base64 encoded json string.
### fromComment(comment)
Returns source map converter from given base64 encoded json string prefixed with `//# sourceMappingURL=...`.
### fromMapFileComment(comment, mapFileDir)
Returns source map converter from given `filename` by parsing `//# sourceMappingURL=filename`.
`filename` must point to a file that is found inside the `mapFileDir`. Most tools store this file right next to the
generated file, i.e. the one containing the source map.
### fromSource(source)
Finds last sourcemap comment in file and returns source map converter or returns null if no source map comment was
found.
### fromMapFileSource(source, mapFileDir)
Finds last sourcemap comment in file and returns source map converter or returns null if no source map comment was
found.
The sourcemap will be read from the map file found by parsing `# sourceMappingURL=file` comment. For more info see
fromMapFileComment.
### toObject()
Returns a copy of the underlying source map.
### toJSON([space])
Converts source map to json string. If `space` is given (optional), this will be passed to
[JSON.stringify](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify) when the
JSON string is generated.
### toBase64()
Converts source map to base64 encoded json string.
### toComment()
Converts source map to base64 encoded json string prefixed with `//# sourceMappingURL=...`.
### addProperty(key, value)
Adds given property to the source map. Throws an error if property already exists.
### setProperty(key, value)
Sets given property to the source map. If property doesn't exist it is added, otherwise its value is updated.
### getProperty(key)
Gets given property of the source map.
### removeComments(src)
Returns `src` with all source map comments removed
### removeMapFileComments(src)
Returns `src` with all source map comments pointing to map files removed.
### commentRegex
Returns the regex used to find source map comments.
### mapFileCommentRegex
Returns the regex used to find source map comments pointing to map files.
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/thlorenz/convert-source-map/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

View file

@ -0,0 +1,15 @@
'use strict';
var convert = require('..');
var json = convert
.fromComment('//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9vLmpzIiwic291cmNlcyI6WyJjb25zb2xlLmxvZyhcImhpXCIpOyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=')
.toJSON();
var modified = convert
.fromComment('//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9vLmpzIiwic291cmNlcyI6WyJjb25zb2xlLmxvZyhcImhpXCIpOyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSIsInNvdXJjZVJvb3QiOiIvIn0=')
.setProperty('sources', [ 'CONSOLE.LOG("HI");' ])
.toJSON();
console.log(json);
console.log(modified);

View file

@ -0,0 +1,139 @@
'use strict';
var fs = require('fs');
var path = require('path');
var commentRx = /^[ \t]*(?:\/\/|\/\*)[@#][ \t]+sourceMappingURL=data:(?:application|text)\/json;base64,(.+)(?:\*\/)?/mg;
var mapFileCommentRx =
// //# sourceMappingURL=foo.js.map /*# sourceMappingURL=foo.js.map */
/(?:^[ \t]*\/\/[@|#][ \t]+sourceMappingURL=(.+?)[ \t]*$)|(?:^[ \t]*\/\*[@#][ \t]+sourceMappingURL=(.+?)[ \t]*\*\/[ \t]*$)/mg
function decodeBase64(base64) {
return new Buffer(base64, 'base64').toString();
}
function stripComment(sm) {
return sm.split(',').pop();
}
function readFromFileMap(sm, dir) {
// NOTE: this will only work on the server since it attempts to read the map file
var r = mapFileCommentRx.exec(sm);
mapFileCommentRx.lastIndex = 0;
// for some odd reason //# .. captures in 1 and /* .. */ in 2
var filename = r[1] || r[2];
var filepath = path.join(dir, filename);
try {
return fs.readFileSync(filepath, 'utf8');
} catch (e) {
throw new Error('An error occurred while trying to read the map file at ' + filepath + '\n' + e);
}
}
function Converter (sm, opts) {
opts = opts || {};
try {
if (opts.isFileComment) sm = readFromFileMap(sm, opts.commentFileDir);
if (opts.hasComment) sm = stripComment(sm);
if (opts.isEncoded) sm = decodeBase64(sm);
if (opts.isJSON || opts.isEncoded) sm = JSON.parse(sm);
this.sourcemap = sm;
} catch(e) {
console.error(e);
return null;
}
}
Converter.prototype.toJSON = function (space) {
return JSON.stringify(this.sourcemap, null, space);
};
Converter.prototype.toBase64 = function () {
var json = this.toJSON();
return new Buffer(json).toString('base64');
};
Converter.prototype.toComment = function () {
var base64 = this.toBase64();
return '//# sourceMappingURL=data:application/json;base64,' + base64;
};
// returns copy instead of original
Converter.prototype.toObject = function () {
return JSON.parse(this.toJSON());
};
Converter.prototype.addProperty = function (key, value) {
if (this.sourcemap.hasOwnProperty(key)) throw new Error('property %s already exists on the sourcemap, use set property instead');
return this.setProperty(key, value);
};
Converter.prototype.setProperty = function (key, value) {
this.sourcemap[key] = value;
return this;
};
Converter.prototype.getProperty = function (key) {
return this.sourcemap[key];
};
exports.fromObject = function (obj) {
return new Converter(obj);
};
exports.fromJSON = function (json) {
return new Converter(json, { isJSON: true });
};
exports.fromBase64 = function (base64) {
return new Converter(base64, { isEncoded: true });
};
exports.fromComment = function (comment) {
comment = comment
.replace(/^\/\*/g, '//')
.replace(/\*\/$/g, '');
return new Converter(comment, { isEncoded: true, hasComment: true });
};
exports.fromMapFileComment = function (comment, dir) {
return new Converter(comment, { commentFileDir: dir, isFileComment: true, isJSON: true });
};
// Finds last sourcemap comment in file or returns null if none was found
exports.fromSource = function (content) {
var m = content.match(commentRx);
commentRx.lastIndex = 0;
return m ? exports.fromComment(m.pop()) : null;
};
// Finds last sourcemap comment in file or returns null if none was found
exports.fromMapFileSource = function (content, dir) {
var m = content.match(mapFileCommentRx);
mapFileCommentRx.lastIndex = 0;
return m ? exports.fromMapFileComment(m.pop(), dir) : null;
};
exports.removeComments = function (src) {
commentRx.lastIndex = 0;
return src.replace(commentRx, '');
};
exports.removeMapFileComments = function (src) {
mapFileCommentRx.lastIndex = 0;
return src.replace(mapFileCommentRx, '');
};
exports.__defineGetter__('commentRegex', function () {
commentRx.lastIndex = 0;
return commentRx;
});
exports.__defineGetter__('mapFileCommentRegex', function () {
mapFileCommentRx.lastIndex = 0;
return mapFileCommentRx;
});

View file

@ -0,0 +1,36 @@
{
"name": "convert-source-map",
"version": "0.3.5",
"description": "Converts a source-map from/to different formats and allows adding/changing properties.",
"main": "index.js",
"scripts": {
"test": "tap test/*.js"
},
"repository": {
"type": "git",
"url": "git://github.com/thlorenz/convert-source-map.git"
},
"homepage": "https://github.com/thlorenz/convert-source-map",
"dependencies": {},
"devDependencies": {
"inline-source-map": "~0.3.0",
"tap": "~0.4.3"
},
"keywords": [
"convert",
"sourcemap",
"source",
"map",
"browser",
"debug"
],
"author": {
"name": "Thorsten Lorenz",
"email": "thlorenz@gmx.de",
"url": "http://thlorenz.com"
},
"license": "MIT",
"engine": {
"node": ">=0.6"
}
}

View file

@ -0,0 +1,100 @@
'use strict';
/*jshint asi: true */
var test = require('tap').test
, generator = require('inline-source-map')
, rx = require('..').commentRegex
, mapFileRx = require('..').mapFileCommentRegex
function comment(s) {
rx.lastIndex = 0;
return rx.test(s + 'sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9')
}
test('comment regex old spec - @', function (t) {
[ '//@ '
, ' //@ '
, '\t//@ '
].forEach(function (x) { t.ok(comment(x), 'matches ' + x) });
[ '///@ '
, '}}//@ '
, ' @// @'
].forEach(function (x) { t.ok(!comment(x), 'does not match ' + x) })
t.end()
})
test('comment regex new spec - #', function (t) {
[ '//# '
, ' //# '
, '\t//# '
].forEach(function (x) { t.ok(comment(x), 'matches ' + x) });
[ '///# '
, '}}//# '
, ' #// #'
].forEach(function (x) { t.ok(!comment(x), 'does not match ' + x) })
t.end()
})
function mapFileComment(s) {
mapFileRx.lastIndex = 0;
return mapFileRx.test(s + 'sourceMappingURL=foo.js.map')
}
test('mapFileComment regex old spec - @', function (t) {
[ '//@ '
, ' //@ '
, '\t//@ '
].forEach(function (x) { t.ok(mapFileComment(x), 'matches ' + x) });
[ '///@ '
, '}}//@ '
, ' @// @'
].forEach(function (x) { t.ok(!mapFileComment(x), 'does not match ' + x) })
t.end()
})
test('mapFileComment regex new spec - #', function (t) {
[ '//# '
, ' //# '
, '\t//# '
].forEach(function (x) { t.ok(mapFileComment(x), 'matches ' + x) });
[ '///# '
, '}}//# '
, ' #// #'
].forEach(function (x) { t.ok(!mapFileComment(x), 'does not match ' + x) })
t.end()
})
function mapFileCommentWrap(s1, s2) {
mapFileRx.lastIndex = 0;
return mapFileRx.test(s1 + 'sourceMappingURL=foo.js.map' + s2)
}
test('mapFileComment regex /* */ old spec - @', function (t) {
[ [ '/*@ ', '*/' ]
, [' /*@ ', ' */ ' ]
, [ '\t/*@ ', ' \t*/\t ']
].forEach(function (x) { t.ok(mapFileCommentWrap(x[0], x[1]), 'matches ' + x.join(' :: ')) });
[ [ '/*/*@ ', '*/' ]
, ['}}/*@ ', ' */ ' ]
, [ ' @/*@ ', ' \t*/\t ']
].forEach(function (x) { t.ok(!mapFileCommentWrap(x[0], x[1]), 'does not match ' + x.join(' :: ')) });
t.end()
})
test('mapFileComment regex /* */ new spec - #', function (t) {
[ [ '/*# ', '*/' ]
, [' /*# ', ' */ ' ]
, [ '\t/*# ', ' \t*/\t ']
].forEach(function (x) { t.ok(mapFileCommentWrap(x[0], x[1]), 'matches ' + x.join(' :: ')) });
[ [ '/*/*# ', '*/' ]
, ['}}/*# ', ' */ ' ]
, [ ' #/*# ', ' \t*/\t ']
].forEach(function (x) { t.ok(!mapFileCommentWrap(x[0], x[1]), 'does not match ' + x.join(' :: ')) });
t.end()
})

View file

@ -0,0 +1,161 @@
'use strict';
/*jshint asi: true */
var test = require('tap').test
, generator = require('inline-source-map')
, convert = require('..')
var gen = generator()
.addMappings('foo.js', [{ original: { line: 2, column: 3 } , generated: { line: 5, column: 10 } }], { line: 5 })
.addGeneratedMappings('bar.js', 'var a = 2;\nconsole.log(a)', { line: 23, column: 22 })
, base64 = gen.base64Encode()
, comment = gen.inlineMappingUrl()
, json = gen.toString()
, obj = JSON.parse(json)
test('different formats', function (t) {
t.equal(convert.fromComment(comment).toComment(), comment, 'comment -> comment')
t.equal(convert.fromComment(comment).toBase64(), base64, 'comment -> base64')
t.equal(convert.fromComment(comment).toJSON(), json, 'comment -> json')
t.deepEqual(convert.fromComment(comment).toObject(), obj, 'comment -> object')
t.equal(convert.fromBase64(base64).toBase64(), base64, 'base64 -> base64')
t.equal(convert.fromBase64(base64).toComment(), comment, 'base64 -> comment')
t.equal(convert.fromBase64(base64).toJSON(), json, 'base64 -> json')
t.deepEqual(convert.fromBase64(base64).toObject(), obj, 'base64 -> object')
t.equal(convert.fromJSON(json).toJSON(), json, 'json -> json')
t.equal(convert.fromJSON(json).toBase64(), base64, 'json -> base64')
t.equal(convert.fromJSON(json).toComment(), comment, 'json -> comment')
t.deepEqual(convert.fromJSON(json).toObject(), obj, 'json -> object')
t.end()
})
test('to object returns a copy', function (t) {
var c = convert.fromJSON(json)
var o = c.toObject()
o.version = '99';
t.equal(c.toObject().version, 3, 'setting property on returned object does not affect original')
t.end()
})
test('from source', function (t) {
var foo = [
'function foo() {'
, ' console.log("hello I am foo");'
, ' console.log("who are you");'
, '}'
, ''
, 'foo();'
, ''
].join('\n')
, map = '//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9'
, otherMap = '//# sourceMappingURL=data:application/json;base64,otherZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9'
function getComment(src) {
var map = convert.fromSource(src);
return map ? map.toComment() : null;
}
t.equal(getComment(foo), null, 'no comment returns null')
t.equal(getComment(foo + map), map, 'beginning of last line')
t.equal(getComment(foo + ' ' + map), map, 'indented of last line')
t.equal(getComment(foo + ' ' + map + '\n\n'), map, 'indented on last non empty line')
t.equal(getComment(foo + map + '\nconsole.log("more code");\nfoo()\n'), map, 'in the middle of code')
t.equal(getComment(foo + otherMap + '\n' + map), map, 'finds last map in source')
t.end()
})
test('remove comments', function (t) {
var foo = [
'function foo() {'
, ' console.log("hello I am foo");'
, ' console.log("who are you");'
, '}'
, ''
, 'foo();'
, ''
].join('\n')
// this one is old spec on purpose
, map = '//@ sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9'
, otherMap = '//# sourceMappingURL=data:application/json;base64,otherZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9'
, extraCode = '\nconsole.log("more code");\nfoo()\n'
t.equal(convert.removeComments(foo + map), foo, 'from last line')
t.equal(convert.removeComments(foo + map + extraCode), foo + extraCode, 'from the middle of code')
t.equal(convert.removeComments(foo + otherMap + extraCode + map + map), foo + extraCode, 'multiple comments from the middle of code')
t.end()
})
test('remove map file comments', function (t) {
var foo = [
'function foo() {'
, ' console.log("hello I am foo");'
, ' console.log("who are you");'
, '}'
, ''
, 'foo();'
, ''
].join('\n')
, fileMap1 = '//# sourceMappingURL=foo.js.map'
, fileMap2 = '/*# sourceMappingURL=foo.js.map */';
t.equal(convert.removeMapFileComments(foo + fileMap1), foo, '// style filemap comment')
t.equal(convert.removeMapFileComments(foo + fileMap2), foo, '/* */ style filemap comment')
t.end()
})
test('pretty json', function (t) {
var mod = convert.fromJSON(json).toJSON(2)
, expected = JSON.stringify(obj, null, 2);
t.equal(
mod
, expected
, 'pretty prints json when space is given')
t.end()
})
test('adding properties', function (t) {
var mod = convert
.fromJSON(json)
.addProperty('foo', 'bar')
.toJSON()
, expected = JSON.parse(json);
expected.foo = 'bar';
t.equal(
mod
, JSON.stringify(expected)
, 'includes added property'
)
t.end()
})
test('setting properties', function (t) {
var mod = convert
.fromJSON(json)
.setProperty('version', '2')
.setProperty('mappings', ';;;UACG')
.setProperty('should add', 'this')
.toJSON()
, expected = JSON.parse(json);
expected.version = '2';
expected.mappings = ';;;UACG';
expected['should add'] = 'this';
t.equal(
mod
, JSON.stringify(expected)
, 'includes new property and changes existing properties'
)
t.end()
})
test('getting properties', function (t) {
var sm = convert.fromJSON(json)
t.equal(sm.getProperty('version'), 3, 'gets version')
t.deepEqual(sm.getProperty('sources'), ['foo.js', 'bar.js'], 'gets sources')
t.end()
})

View file

@ -0,0 +1,14 @@
.header {
background: #444;
border: solid;
padding: 10px;
border-radius: 10px 5px 10px 5px;
color: #b4b472; }
#main li {
color: green;
margin: 10px;
padding: 10px;
font-size: 18px; }
//# sourceMappingURL=map-file-comment.css.map

View file

@ -0,0 +1,14 @@
.header {
background: #444;
border: solid;
padding: 10px;
border-radius: 10px 5px 10px 5px;
color: #b4b472; }
#main li {
color: green;
margin: 10px;
padding: 10px;
font-size: 18px; }
/*# sourceMappingURL=data:application/json;base64,ewoidmVyc2lvbiI6ICIzIiwKIm1hcHBpbmdzIjogIkFBQUEsd0JBQXlCO0VBQ3ZCLFVBQVUsRUFBRSxJQUFJO0VBQ2hCLE1BQU0sRUFBRSxLQUFLO0VBQ2IsT0FBTyxFQUFFLElBQUk7RUFDYixhQUFhLEVBQUUsaUJBQWlCO0VBQ2hDLEtBQUssRUFBRSxPQUFrQjs7QUFHM0Isd0JBQXlCO0VBQ3ZCLE9BQU8sRUFBRSxJQUFJOztBQ1RmLGdCQUFpQjtFQUNmLFVBQVUsRUFBRSxJQUFJO0VBQ2hCLEtBQUssRUFBRSxNQUFNOztBQUdmLGtCQUFtQjtFQUNqQixNQUFNLEVBQUUsSUFBSTtFQUNaLE9BQU8sRUFBRSxJQUFJO0VBQ2IsVUFBVSxFQUFFLEtBQUs7RUFDakIsYUFBYSxFQUFFLEdBQUc7RUFDbEIsS0FBSyxFQUFFLEtBQUs7O0FBRWQsa0JBQW1CO0VBQ2pCLEtBQUssRUFBRSxLQUFLOztBQUdkLG1CQUFvQjtFQUNsQixLQUFLLEVBQUUsS0FBSztFQUNaLE1BQU0sRUFBRSxJQUFJO0VBQ1osT0FBTyxFQUFFLElBQUk7RUFDYixTQUFTLEVBQUUsSUFBSSIsCiJzb3VyY2VzIjogWyIuL2NsaWVudC9zYXNzL2NvcmUuc2NzcyIsIi4vY2xpZW50L3Nhc3MvbWFpbi5zY3NzIl0sCiJmaWxlIjogIm1hcC1maWxlLWNvbW1lbnQuY3NzIgp9 */

View file

@ -0,0 +1,14 @@
.header {
background: #444;
border: solid;
padding: 10px;
border-radius: 10px 5px 10px 5px;
color: #b4b472; }
#main li {
color: green;
margin: 10px;
padding: 10px;
font-size: 18px; }
/*# sourceMappingURL=map-file-comment.css.map */

View file

@ -0,0 +1,6 @@
{
"version": "3",
"mappings": "AAAA,wBAAyB;EACvB,UAAU,EAAE,IAAI;EAChB,MAAM,EAAE,KAAK;EACb,OAAO,EAAE,IAAI;EACb,aAAa,EAAE,iBAAiB;EAChC,KAAK,EAAE,OAAkB;;AAG3B,wBAAyB;EACvB,OAAO,EAAE,IAAI;;ACTf,gBAAiB;EACf,UAAU,EAAE,IAAI;EAChB,KAAK,EAAE,MAAM;;AAGf,kBAAmB;EACjB,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,IAAI;EACb,UAAU,EAAE,KAAK;EACjB,aAAa,EAAE,GAAG;EAClB,KAAK,EAAE,KAAK;;AAEd,kBAAmB;EACjB,KAAK,EAAE,KAAK;;AAGd,mBAAoB;EAClB,KAAK,EAAE,KAAK;EACZ,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,IAAI;EACb,SAAS,EAAE,IAAI",
"sources": ["./client/sass/core.scss","./client/sass/main.scss"],
"file": "map-file-comment.css"
}

View file

@ -0,0 +1,70 @@
'use strict';
/*jshint asi: true */
var test = require('tap').test
, rx = require('..')
, fs = require('fs')
, convert = require('..')
test('\nresolving a "/*# sourceMappingURL=map-file-comment.css.map*/" style comment inside a given css content', function (t) {
var css = fs.readFileSync(__dirname + '/fixtures/map-file-comment.css', 'utf8')
var conv = convert.fromMapFileSource(css, __dirname + '/fixtures');
var sm = conv.toObject();
t.deepEqual(
sm.sources
, [ './client/sass/core.scss',
'./client/sass/main.scss' ]
, 'resolves paths of original sources'
)
t.equal(sm.file, 'map-file-comment.css', 'includes filename of generated file')
t.equal(
sm.mappings
, 'AAAA,wBAAyB;EACvB,UAAU,EAAE,IAAI;EAChB,MAAM,EAAE,KAAK;EACb,OAAO,EAAE,IAAI;EACb,aAAa,EAAE,iBAAiB;EAChC,KAAK,EAAE,OAAkB;;AAG3B,wBAAyB;EACvB,OAAO,EAAE,IAAI;;ACTf,gBAAiB;EACf,UAAU,EAAE,IAAI;EAChB,KAAK,EAAE,MAAM;;AAGf,kBAAmB;EACjB,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,IAAI;EACb,UAAU,EAAE,KAAK;EACjB,aAAa,EAAE,GAAG;EAClB,KAAK,EAAE,KAAK;;AAEd,kBAAmB;EACjB,KAAK,EAAE,KAAK;;AAGd,mBAAoB;EAClB,KAAK,EAAE,KAAK;EACZ,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,IAAI;EACb,SAAS,EAAE,IAAI'
, 'includes mappings'
)
t.end()
})
test('\nresolving a "//# sourceMappingURL=map-file-comment.css.map" style comment inside a given css content', function (t) {
var css = fs.readFileSync(__dirname + '/fixtures/map-file-comment-double-slash.css', 'utf8')
var conv = convert.fromMapFileSource(css, __dirname + '/fixtures');
var sm = conv.toObject();
t.deepEqual(
sm.sources
, [ './client/sass/core.scss',
'./client/sass/main.scss' ]
, 'resolves paths of original sources'
)
t.equal(sm.file, 'map-file-comment.css', 'includes filename of generated file')
t.equal(
sm.mappings
, 'AAAA,wBAAyB;EACvB,UAAU,EAAE,IAAI;EAChB,MAAM,EAAE,KAAK;EACb,OAAO,EAAE,IAAI;EACb,aAAa,EAAE,iBAAiB;EAChC,KAAK,EAAE,OAAkB;;AAG3B,wBAAyB;EACvB,OAAO,EAAE,IAAI;;ACTf,gBAAiB;EACf,UAAU,EAAE,IAAI;EAChB,KAAK,EAAE,MAAM;;AAGf,kBAAmB;EACjB,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,IAAI;EACb,UAAU,EAAE,KAAK;EACjB,aAAa,EAAE,GAAG;EAClB,KAAK,EAAE,KAAK;;AAEd,kBAAmB;EACjB,KAAK,EAAE,KAAK;;AAGd,mBAAoB;EAClB,KAAK,EAAE,KAAK;EACZ,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,IAAI;EACb,SAAS,EAAE,IAAI'
, 'includes mappings'
)
t.end()
})
test('\nresolving a /*# sourceMappingURL=data:application/json;base64,... */ style comment inside a given css content', function(t) {
var css = fs.readFileSync(__dirname + '/fixtures/map-file-comment-inline.css', 'utf8')
var conv = convert.fromSource(css, __dirname + '/fixtures')
var sm = conv.toObject()
t.deepEqual(
sm.sources
, [ './client/sass/core.scss',
'./client/sass/main.scss' ]
, 'resolves paths of original sources'
)
t.equal(sm.file, 'map-file-comment.css', 'includes filename of generated file')
t.equal(
sm.mappings
, 'AAAA,wBAAyB;EACvB,UAAU,EAAE,IAAI;EAChB,MAAM,EAAE,KAAK;EACb,OAAO,EAAE,IAAI;EACb,aAAa,EAAE,iBAAiB;EAChC,KAAK,EAAE,OAAkB;;AAG3B,wBAAyB;EACvB,OAAO,EAAE,IAAI;;ACTf,gBAAiB;EACf,UAAU,EAAE,IAAI;EAChB,KAAK,EAAE,MAAM;;AAGf,kBAAmB;EACjB,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,IAAI;EACb,UAAU,EAAE,KAAK;EACjB,aAAa,EAAE,GAAG;EAClB,KAAK,EAAE,KAAK;;AAEd,kBAAmB;EACjB,KAAK,EAAE,KAAK;;AAGd,mBAAoB;EAClB,KAAK,EAAE,KAAK;EACZ,MAAM,EAAE,IAAI;EACZ,OAAO,EAAE,IAAI;EACb,SAAS,EAAE,IAAI'
, 'includes mappings'
)
t.end()
})

75
web/node_modules/rework/node_modules/css/History.md generated vendored Normal file
View file

@ -0,0 +1,75 @@
2.2.1 / 2015-06-17
==================
* fix parsing escaped quotes in quoted strings
2.2.0 / 2015-02-18
==================
* add `parsingErrors` to list errors when parsing with `silent: true`
* accept EOL characters and all other whitespace characters in `@` rules such
as `@media`
2.1.0 / 2014-08-05
==================
* change error message format and add `.reason` property to errors
* add `inputSourcemaps` option to disable input source map processing
* use `inherits` for inheritance (fixes some browsers)
* add `sourcemap: 'generator'` option to return the `SourceMapGenerator`
object
2.0.0 / 2014-06-18
==================
* add non-enumerable parent reference to each node
* drop Component(1) support
* add support for @custom-media, @host, and @font-face
* allow commas inside selector functions
* allow empty property values
* changed default options.position value to true
* remove comments from properties and values
* asserts when selectors are missing
* added node.position.content property
* absorb css-parse and css-stringify libraries
* apply original source maps from source files
1.6.1 / 2014-01-02
==================
* fix component.json
1.6.0 / 2013-12-21
==================
* update deps
1.5.0 / 2013-12-03
==================
* update deps
1.1.0 / 2013-04-04
==================
* update deps
1.0.7 / 2012-11-21
==================
* fix component.json
1.0.4 / 2012-11-15
==================
* update css-stringify
1.0.3 / 2012-09-01
==================
* add component support
0.0.1 / 2010-01-03
==================
* Initial release

9
web/node_modules/rework/node_modules/css/LICENSE generated vendored Normal file
View file

@ -0,0 +1,9 @@
(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.

314
web/node_modules/rework/node_modules/css/Readme.md generated vendored Normal file
View file

@ -0,0 +1,314 @@
# css [![Build Status](https://travis-ci.org/reworkcss/css.svg?branch=master)](https://travis-ci.org/reworkcss/css)
CSS parser / stringifier.
## Installation
$ npm install css
## Usage
```js
var css = require('css');
var obj = css.parse('body { font-size: 12px; }', options);
css.stringify(obj, options);
```
## API
### css.parse(code, [options])
Accepts a CSS string and returns an AST `object`.
`options`:
- silent: silently fail on parse errors.
- source: the path to the file containing `css`. Makes errors and source
maps more helpful, by letting them know where code comes from.
### css.stringify(object, [options])
Accepts an AST `object` (as `css.parse` produces) and returns a CSS string.
`options`:
- indent: the string used to indent the output. Defaults to two spaces.
- compress: omit comments and extraneous whitespace.
- sourcemap: return a sourcemap along with the CSS output. Using the `source`
option of `css.parse` is strongly recommended when creating a source map.
Specify `sourcemap: 'generator'` to return the SourceMapGenerator object
instead of serializing the source map.
- inputSourcemaps: (enabled by default, specify `false` to disable) reads any
source maps referenced by the input files when generating the output source
map. When enabled, file system access may be required for reading the
referenced source maps.
### Example
```js
var ast = css.parse('body { font-size: 12px; }', { source: 'source.css' });
var css = css.stringify(ast);
var result = css.stringify(ast, { sourcemap: true });
result.code // string with CSS
result.map // source map object
```
### Errors
Errors thrown during parsing have the following properties:
- message: `String`. The full error message with the source position.
- reason: `String`. The error message without position.
- filename: `String` or `undefined`. The value of `options.source` if
passed to `css.parse`. Otherwise `undefined`.
- line: `Integer`.
- column: `Integer`.
- source: `String`. The portion of code that couldn't be parsed.
When parsing with the `silent` option, errors are listed in the
`parsingErrors` property of the [`stylesheet`](#stylesheet) node instead
of being thrown.
If you create any errors in plugins such as in
[rework](https://github.com/reworkcss/rework), you __must__ set the same
properties for consistency.
## AST
Interactively explore the AST with <http://iamdustan.com/reworkcss_ast_explorer/>.
### Common properties
All nodes have the following properties.
#### position
Information about the position in the source string that corresponds to
the node.
`Object`:
- start: `Object`:
- line: `Number`.
- column: `Number`.
- end: `Object`:
- line: `Number`.
- column: `Number`.
- source: `String` or `undefined`. The value of `options.source` if passed to
`css.parse`. Otherwise `undefined`.
- content: `String`. The full source string passed to `css.parse`.
The line and column numbers are 1-based: The first line is 1 and the first
column of a line is 1 (not 0).
The `position` property lets you know from which source file the node comes
from (if available), what that file contains, and what part of that file was
parsed into the node.
#### type
`String`. The possible values are the ones listed in the Types section below.
#### parent
A reference to the parent node, or `null` if the node has no parent.
### Types
The available values of `node.type` are listed below, as well as the available
properties of each node (other than the common properties listed above.)
#### stylesheet
The root node returned by `css.parse`.
- stylesheet: `Object`:
- rules: `Array` of nodes with the types `rule`, `comment` and any of the
at-rule types.
- parsingErrors: `Array` of `Error`s. Errors collected during parsing when
option `silent` is true.
#### rule
- selectors: `Array` of `String`s. The list of selectors of the rule, split
on commas. Each selector is trimmed from whitespace and comments.
- declarations: `Array` of nodes with the types `declaration` and `comment`.
#### declaration
- property: `String`. The property name, trimmed from whitespace and
comments. May not be empty.
- value: `String`. The value of the property, trimmed from whitespace and
comments. Empty values are allowed.
#### comment
A rule-level or declaration-level comment. Comments inside selectors,
properties and values etc. are lost.
- comment: `String`. The part between the starting `/*` and the ending `*/`
of the comment, including whitespace.
#### charset
The `@charset` at-rule.
- charset: `String`. The part following `@charset `.
#### custom-media
The `@custom-media` at-rule.
- name: `String`. The `--`-prefixed name.
- media: `String`. The part following the name.
#### document
The `@document` at-rule.
- document: `String`. The part following `@document `.
- vendor: `String` or `undefined`. The vendor prefix in `@document`, or
`undefined` if there is none.
- rules: `Array` of nodes with the types `rule`, `comment` and any of the
at-rule types.
#### font-face
The `@font-face` at-rule.
- declarations: `Array` of nodes with the types `declaration` and `comment`.
#### host
The `@host` at-rule.
- rules: `Array` of nodes with the types `rule`, `comment` and any of the
at-rule types.
#### import
The `@import` at-rule.
- import: `String`. The part following `@import `.
#### keyframes
The `@keyframes` at-rule.
- name: `String`. The name of the keyframes rule.
- vendor: `String` or `undefined`. The vendor prefix in `@keyframes`, or
`undefined` if there is none.
- keyframes: `Array` of nodes with the types `keyframe` and `comment`.
#### keyframe
- values: `Array` of `String`s. The list of “selectors” of the keyframe rule,
split on commas. Each “selector” is trimmed from whitespace.
- declarations: `Array` of nodes with the types `declaration` and `comment`.
#### media
The `@media` at-rule.
- media: `String`. The part following `@media `.
- rules: `Array` of nodes with the types `rule`, `comment` and any of the
at-rule types.
#### namespace
The `@namespace` at-rule.
- namespace: `String`. The part following `@namespace `.
#### page
The `@page` at-rule.
- selectors: `Array` of `String`s. The list of selectors of the rule, split
on commas. Each selector is trimmed from whitespace and comments.
- declarations: `Array` of nodes with the types `declaration` and `comment`.
#### supports
The `@supports` at-rule.
- supports: `String`. The part following `@supports `.
- rules: `Array` of nodes with the types `rule`, `comment` and any of the
at-rule types.
### Example
CSS:
```css
body {
background: #eee;
color: #888;
}
```
Parse tree:
```json
{
"type": "stylesheet",
"stylesheet": {
"rules": [
{
"type": "rule",
"selectors": [
"body"
],
"declarations": [
{
"type": "declaration",
"property": "background",
"value": "#eee",
"position": {
"start": {
"line": 2,
"column": 3
},
"end": {
"line": 2,
"column": 19
}
}
},
{
"type": "declaration",
"property": "color",
"value": "#888",
"position": {
"start": {
"line": 3,
"column": 3
},
"end": {
"line": 3,
"column": 14
}
}
}
],
"position": {
"start": {
"line": 1,
"column": 1
},
"end": {
"line": 4,
"column": 2
}
}
}
]
}
}
```
## License
MIT

2
web/node_modules/rework/node_modules/css/index.js generated vendored Normal file
View file

@ -0,0 +1,2 @@
exports.parse = require('./lib/parse');
exports.stringify = require('./lib/stringify');

View file

@ -0,0 +1,603 @@
// http://www.w3.org/TR/CSS21/grammar.html
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g
module.exports = function(css, options){
options = options || {};
/**
* Positional.
*/
var lineno = 1;
var column = 1;
/**
* Update lineno and column based on `str`.
*/
function updatePosition(str) {
var lines = str.match(/\n/g);
if (lines) lineno += lines.length;
var i = str.lastIndexOf('\n');
column = ~i ? str.length - i : column + str.length;
}
/**
* Mark position and patch `node.position`.
*/
function position() {
var start = { line: lineno, column: column };
return function(node){
node.position = new Position(start);
whitespace();
return node;
};
}
/**
* Store position information for a node
*/
function Position(start) {
this.start = start;
this.end = { line: lineno, column: column };
this.source = options.source;
}
/**
* Non-enumerable source string
*/
Position.prototype.content = css;
/**
* Error `msg`.
*/
var errorsList = [];
function error(msg) {
var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
err.reason = msg;
err.filename = options.source;
err.line = lineno;
err.column = column;
err.source = css;
if (options.silent) {
errorsList.push(err);
} else {
throw err;
}
}
/**
* Parse stylesheet.
*/
function stylesheet() {
var rulesList = rules();
return {
type: 'stylesheet',
stylesheet: {
source: options.source,
rules: rulesList,
parsingErrors: errorsList
}
};
}
/**
* Opening brace.
*/
function open() {
return match(/^{\s*/);
}
/**
* Closing brace.
*/
function close() {
return match(/^}/);
}
/**
* Parse ruleset.
*/
function rules() {
var node;
var rules = [];
whitespace();
comments(rules);
while (css.length && css.charAt(0) != '}' && (node = atrule() || rule())) {
if (node !== false) {
rules.push(node);
comments(rules);
}
}
return rules;
}
/**
* Match `re` and return captures.
*/
function match(re) {
var m = re.exec(css);
if (!m) return;
var str = m[0];
updatePosition(str);
css = css.slice(str.length);
return m;
}
/**
* Parse whitespace.
*/
function whitespace() {
match(/^\s*/);
}
/**
* Parse comments;
*/
function comments(rules) {
var c;
rules = rules || [];
while (c = comment()) {
if (c !== false) {
rules.push(c);
}
}
return rules;
}
/**
* Parse comment.
*/
function comment() {
var pos = position();
if ('/' != css.charAt(0) || '*' != css.charAt(1)) return;
var i = 2;
while ("" != css.charAt(i) && ('*' != css.charAt(i) || '/' != css.charAt(i + 1))) ++i;
i += 2;
if ("" === css.charAt(i-1)) {
return error('End of comment missing');
}
var str = css.slice(2, i - 2);
column += 2;
updatePosition(str);
css = css.slice(i);
column += 2;
return pos({
type: 'comment',
comment: str
});
}
/**
* Parse selector.
*/
function selector() {
var m = match(/^([^{]+)/);
if (!m) return;
/* @fix Remove all comments from selectors
* http://ostermiller.org/findcomment.html */
return trim(m[0])
.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
.replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function(m) {
return m.replace(/,/g, '\u200C');
})
.split(/\s*(?![^(]*\)),\s*/)
.map(function(s) {
return s.replace(/\u200C/g, ',');
});
}
/**
* Parse declaration.
*/
function declaration() {
var pos = position();
// prop
var prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
if (!prop) return;
prop = trim(prop[0]);
// :
if (!match(/^:\s*/)) return error("property missing ':'");
// val
var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
var ret = pos({
type: 'declaration',
property: prop.replace(commentre, ''),
value: val ? trim(val[0]).replace(commentre, '') : ''
});
// ;
match(/^[;\s]*/);
return ret;
}
/**
* Parse declarations.
*/
function declarations() {
var decls = [];
if (!open()) return error("missing '{'");
comments(decls);
// declarations
var decl;
while (decl = declaration()) {
if (decl !== false) {
decls.push(decl);
comments(decls);
}
}
if (!close()) return error("missing '}'");
return decls;
}
/**
* Parse keyframe.
*/
function keyframe() {
var m;
var vals = [];
var pos = position();
while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) {
vals.push(m[1]);
match(/^,\s*/);
}
if (!vals.length) return;
return pos({
type: 'keyframe',
values: vals,
declarations: declarations()
});
}
/**
* Parse keyframes.
*/
function atkeyframes() {
var pos = position();
var m = match(/^@([-\w]+)?keyframes\s*/);
if (!m) return;
var vendor = m[1];
// identifier
var m = match(/^([-\w]+)\s*/);
if (!m) return error("@keyframes missing name");
var name = m[1];
if (!open()) return error("@keyframes missing '{'");
var frame;
var frames = comments();
while (frame = keyframe()) {
frames.push(frame);
frames = frames.concat(comments());
}
if (!close()) return error("@keyframes missing '}'");
return pos({
type: 'keyframes',
name: name,
vendor: vendor,
keyframes: frames
});
}
/**
* Parse supports.
*/
function atsupports() {
var pos = position();
var m = match(/^@supports *([^{]+)/);
if (!m) return;
var supports = trim(m[1]);
if (!open()) return error("@supports missing '{'");
var style = comments().concat(rules());
if (!close()) return error("@supports missing '}'");
return pos({
type: 'supports',
supports: supports,
rules: style
});
}
/**
* Parse host.
*/
function athost() {
var pos = position();
var m = match(/^@host\s*/);
if (!m) return;
if (!open()) return error("@host missing '{'");
var style = comments().concat(rules());
if (!close()) return error("@host missing '}'");
return pos({
type: 'host',
rules: style
});
}
/**
* Parse media.
*/
function atmedia() {
var pos = position();
var m = match(/^@media *([^{]+)/);
if (!m) return;
var media = trim(m[1]);
if (!open()) return error("@media missing '{'");
var style = comments().concat(rules());
if (!close()) return error("@media missing '}'");
return pos({
type: 'media',
media: media,
rules: style
});
}
/**
* Parse custom-media.
*/
function atcustommedia() {
var pos = position();
var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
if (!m) return;
return pos({
type: 'custom-media',
name: trim(m[1]),
media: trim(m[2])
});
}
/**
* Parse paged media.
*/
function atpage() {
var pos = position();
var m = match(/^@page */);
if (!m) return;
var sel = selector() || [];
if (!open()) return error("@page missing '{'");
var decls = comments();
// declarations
var decl;
while (decl = declaration()) {
decls.push(decl);
decls = decls.concat(comments());
}
if (!close()) return error("@page missing '}'");
return pos({
type: 'page',
selectors: sel,
declarations: decls
});
}
/**
* Parse document.
*/
function atdocument() {
var pos = position();
var m = match(/^@([-\w]+)?document *([^{]+)/);
if (!m) return;
var vendor = trim(m[1]);
var doc = trim(m[2]);
if (!open()) return error("@document missing '{'");
var style = comments().concat(rules());
if (!close()) return error("@document missing '}'");
return pos({
type: 'document',
document: doc,
vendor: vendor,
rules: style
});
}
/**
* Parse font-face.
*/
function atfontface() {
var pos = position();
var m = match(/^@font-face\s*/);
if (!m) return;
if (!open()) return error("@font-face missing '{'");
var decls = comments();
// declarations
var decl;
while (decl = declaration()) {
decls.push(decl);
decls = decls.concat(comments());
}
if (!close()) return error("@font-face missing '}'");
return pos({
type: 'font-face',
declarations: decls
});
}
/**
* Parse import
*/
var atimport = _compileAtrule('import');
/**
* Parse charset
*/
var atcharset = _compileAtrule('charset');
/**
* Parse namespace
*/
var atnamespace = _compileAtrule('namespace');
/**
* Parse non-block at-rules
*/
function _compileAtrule(name) {
var re = new RegExp('^@' + name + '\\s*([^;]+);');
return function() {
var pos = position();
var m = match(re);
if (!m) return;
var ret = { type: name };
ret[name] = m[1].trim();
return pos(ret);
}
}
/**
* Parse at rule.
*/
function atrule() {
if (css[0] != '@') return;
return atkeyframes()
|| atmedia()
|| atcustommedia()
|| atsupports()
|| atimport()
|| atcharset()
|| atnamespace()
|| atdocument()
|| atpage()
|| athost()
|| atfontface();
}
/**
* Parse rule.
*/
function rule() {
var pos = position();
var sel = selector();
if (!sel) return error('selector missing');
comments();
return pos({
type: 'rule',
selectors: sel,
declarations: declarations()
});
}
return addParent(stylesheet());
};
/**
* Trim `str`.
*/
function trim(str) {
return str ? str.replace(/^\s+|\s+$/g, '') : '';
}
/**
* Adds non-enumerable parent node reference to each node.
*/
function addParent(obj, parent) {
var isNode = obj && typeof obj.type === 'string';
var childParent = isNode ? obj : parent;
for (var k in obj) {
var value = obj[k];
if (Array.isArray(value)) {
value.forEach(function(v) { addParent(v, childParent); });
} else if (value && typeof value === 'object') {
addParent(value, childParent);
}
}
if (isNode) {
Object.defineProperty(obj, 'parent', {
configurable: true,
writable: true,
enumerable: false,
value: parent || null
});
}
return obj;
}

View file

@ -0,0 +1,50 @@
/**
* 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;
};

View file

@ -0,0 +1,199 @@
/**
* Module dependencies.
*/
var Base = require('./compiler');
var inherits = require('inherits');
/**
* Expose compiler.
*/
module.exports = Compiler;
/**
* Initialize a new `Compiler`.
*/
function Compiler(options) {
Base.call(this, options);
}
/**
* Inherit from `Base.prototype`.
*/
inherits(Compiler, Base);
/**
* 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ this.emit('{')
+ this.mapVisit(node.declarations)
+ this.emit('}');
};
/**
* Visit font-face node.
*/
Compiler.prototype['font-face'] = function(node){
return this.emit('@font-face', node.position)
+ this.emit('{')
+ this.mapVisit(node.declarations)
+ this.emit('}');
};
/**
* Visit host node.
*/
Compiler.prototype.host = function(node){
return this.emit('@host', node.position)
+ this.emit('{')
+ this.mapVisit(node.rules)
+ this.emit('}');
};
/**
* Visit custom-media node.
*/
Compiler.prototype['custom-media'] = function(node){
return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
};
/**
* Visit rule node.
*/
Compiler.prototype.rule = function(node){
var decls = node.declarations;
if (!decls.length) return '';
return this.emit(node.selectors.join(','), node.position)
+ 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(';');
};

View file

@ -0,0 +1,254 @@
/**
* Module dependencies.
*/
var Base = require('./compiler');
var inherits = require('inherits');
/**
* 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`.
*/
inherits(Compiler, Base);
/**
* 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ 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)
+ this.emit('{\n')
+ this.emit(this.indent(1))
+ this.mapVisit(node.declarations, '\n')
+ this.emit(this.indent(-1))
+ this.emit('\n}');
};
/**
* Visit font-face node.
*/
Compiler.prototype['font-face'] = function(node){
return this.emit('@font-face ', node.position)
+ this.emit('{\n')
+ this.emit(this.indent(1))
+ this.mapVisit(node.declarations, '\n')
+ this.emit(this.indent(-1))
+ this.emit('\n}');
};
/**
* Visit host node.
*/
Compiler.prototype.host = function(node){
return this.emit('@host', node.position)
+ this.emit(
' {\n'
+ this.indent(1))
+ this.mapVisit(node.rules, '\n\n')
+ this.emit(
this.indent(-1)
+ '\n}');
};
/**
* Visit custom-media node.
*/
Compiler.prototype['custom-media'] = function(node){
return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
};
/**
* 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)
+ 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 || ' ');
};

View file

@ -0,0 +1,47 @@
/**
* Module dependencies.
*/
var Compressed = require('./compress');
var Identity = require('./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('./source-map-support');
sourcemaps(compiler);
var code = compiler.compile(node);
compiler.applySourceMaps();
var map = options.sourcemap === 'generator'
? compiler.map
: compiler.map.toJSON();
return { code: code, map: map };
}
var code = compiler.compile(node);
return code;
};

View file

@ -0,0 +1,126 @@
/**
* Module dependencies.
*/
var SourceMap = require('source-map').SourceMapGenerator;
var SourceMapConsumer = require('source-map').SourceMapConsumer;
var sourceMapResolve = require('source-map-resolve');
var urix = require('urix');
var fs = require('fs');
var path = require('path');
/**
* Expose `mixin()`.
*/
module.exports = mixin;
/**
* Mixin source map support into `compiler`.
*
* @param {Compiler} compiler
* @api public
*/
function mixin(compiler) {
compiler._comment = compiler.comment;
compiler.map = new SourceMap();
compiler.position = { line: 1, column: 1 };
compiler.files = {};
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 {Object} [pos]
* @return {String}
* @api private
*/
exports.emit = function(str, pos) {
if (pos) {
var sourceFile = urix(pos.source || 'source.css');
this.map.addMapping({
source: sourceFile,
generated: {
line: this.position.line,
column: Math.max(this.position.column - 1, 0)
},
original: {
line: pos.start.line,
column: pos.start.column - 1
}
});
this.addFile(sourceFile, pos);
}
this.updatePosition(str);
return str;
};
/**
* Adds a file to the source map output if it has not already been added
* @param {String} file
* @param {Object} pos
*/
exports.addFile = function(file, pos) {
if (typeof pos.content !== 'string') return;
if (Object.prototype.hasOwnProperty.call(this.files, file)) return;
this.files[file] = pos.content;
};
/**
* Applies any original source maps to the output and embeds the source file
* contents in the source map.
*/
exports.applySourceMaps = function() {
Object.keys(this.files).forEach(function(file) {
var content = this.files[file];
this.map.setSourceContent(file, content);
if (this.options.inputSourcemaps !== false) {
var originalMap = sourceMapResolve.resolveSync(
content, file, fs.readFileSync);
if (originalMap) {
var map = new SourceMapConsumer(originalMap.map);
var relativeTo = originalMap.sourcesRelativeTo;
this.map.applySourceMap(map, file, urix(path.dirname(relativeTo)));
}
}
}, this);
};
/**
* Process comments, drops sourceMap comments.
* @param {Object} node
*/
exports.comment = function(node) {
if (/^# sourceMappingURL=/.test(node.comment))
return this.emit('', node.position);
else
return this._comment(node);
};

39
web/node_modules/rework/node_modules/css/package.json generated vendored Normal file
View file

@ -0,0 +1,39 @@
{
"name": "css",
"version": "2.2.4",
"description": "CSS parser / stringifier",
"main": "index",
"files": [
"index.js",
"lib",
"Readme.md"
],
"dependencies": {
"inherits": "^2.0.3",
"source-map": "^0.6.1",
"source-map-resolve": "^0.5.2",
"urix": "^0.1.0"
},
"devDependencies": {
"mocha": "^1.21.3",
"should": "^4.0.4",
"matcha": "^0.5.0",
"bytes": "^1.0.0"
},
"scripts": {
"benchmark": "matcha",
"test": "mocha --require should --reporter spec --bail test/*.js"
},
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/reworkcss/css.git"
},
"keywords": [
"css",
"parser",
"stringifier",
"stylesheet"
]
}

View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014, 2015, 2016, 2017, 2018, 2019 Simon Lydell
Copyright (c) 2019 ZHAO Jinxiang
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.

View file

@ -0,0 +1,108 @@
### Version 0.5.3 (2019-12-28) ###
- Fixed: base64 encoded source maps now correctly decodes as utf-8. Previously,
non-ASCII characters could end up garbled. Thanks to ZHAO Jinxiang
(@xiaoxiangmoe)! (Note: This fix does not work in old evironments not
supporting both `TextDecoder` and `Uint8Array`.)
- Improved: Reduced size of the npm package.
### Version 0.5.2 (2018-05-10) ###
- Improved: Updated the version range of `atob` to disallow depending on `2.0.3`
which as a [security
vulnerability](https://snyk.io/test/npm/atob/2.0.3?severity=high&severity=medium&severity=low).
### Version 0.5.1 (2017-10-21) ###
- Fixed: URLs are now decoded before being passed to `read` in Node.js. This
allows reading files with spaces, for example.
- Fixed: Missing or empty `sources` fields (such as `sources: []`) in source
maps are now handled. Previously, such source maps would cause crashes or
callbacks never bing called. Now, an empty result is produced:
```js
sourcesResolved: [],
sourcesContent: []
```
### Version 0.5.0 (2016-02-28) ###
- Improved: Errors now have a `sourceMapData` property that contain as much as
possible of the intended result of the function up until the error occurred.
- Changed: `resolveSources` and `resolve`, as well as their `*Sync`
alternatives, no longer fail when one single source fails to be fetched.
Instead, the `sourcesContent` array in the result object will contain error
objects for all failed sources, and strings otherwise. (Backwards-incompatible
change.)
### Version 0.4.0 (2015-08-29) ###
- Removed: The `ignoreSourceRoot` option of `resolveSources`. It has been
replaced with `sourceRoot: false`. (Backwards-incompatible change.)
- Added: The `sourceRoot` option of `resolveSources`. It not only allows to
ignore the source root, it also lets you replace it.
- Added: The `parseMapToJSON` method.
- Added: The `resolve` method now accepts `null, mapUrl, ...` as arguments, in
addition to the existing signature, which will read `mapUrl` instead of
looking for a sourceMappingURL in the code.
### Version 0.3.1 (2014-08-16) ###
- Improved: Updated the source-map-url dependency to 0.3.0.
### Version 0.3.0 (2014-07-02) ###
- Removed: Argument checking. Its not worth it. (Possibly
backwards-incompatible change.)
- Added: The `sourceRoot` property of source maps may now be ignored, which can
be useful when resolving sources outside of the browser.
- Added: It is now possible to resolve only the URLs of sources, without
reading them.
### Version 0.2.0 (2014-06-22) ###
- Changed: The result of `resolveSources` is now an object, not an array. The
old result array is available in the `sourcesContent` property.
(Backwards-incompatible change.)
- Changed: `sources` has been renamed to `sourcesContent` in the result object
of `resolve`. (Backwards-incompatible change.)
- Added: `resolveSources` now also returns all sources fully resolved, in the
`sourcesResolved` property.
- Added: The result object of `resolve` now contains the `sourcesResolved`
property from `resolveSources`.
### Version 0.1.4 (2014-06-16) ###
- Fixed: `sourcesContent` was mis-typed as `sourceContents`, which meant that
the `sourcesContent` property of source maps never was used when resolving
sources.
### Version 0.1.3 (2014-05-06) ###
- Only documentation and meta-data changes.
### Version 0.1.2 (2014-03-23) ###
- Improved: Source maps starting with `)]}'` are now parsed correctly. The spec
allows source maps to start with that character sequence to prevent XSSI
attacks.
### Version 0.1.1 (2014-03-06) ###
- Improved: Make sourceRoot resolving more sensible.
A source root such as `/scripts/subdir` is now treated as `/scripts/subdir/`
— that is, as a directory called “subdir”, not a file called “subdir”.
Pointing to a file as source root does not makes sense.
### Version 0.1.0 (2014-03-03) ###
- Initial release.

View file

@ -0,0 +1,8 @@
var decodeUriComponent = require("decode-uri-component")
function customDecodeUriComponent(string) {
// `decodeUriComponent` turns `+` into ` `, but that's not wanted.
return decodeUriComponent(string.replace(/\+/g, "%2B"))
}
module.exports = customDecodeUriComponent

View file

@ -0,0 +1,9 @@
var url = require("url")
function resolveUrl(/* ...urls */) {
return Array.prototype.reduce.call(arguments, function(resolved, nextUrl) {
return url.resolve(resolved, nextUrl)
})
}
module.exports = resolveUrl

View file

@ -0,0 +1,342 @@
var sourceMappingURL = require("source-map-url")
var resolveUrl = require("./resolve-url")
var decodeUriComponent = require("./decode-uri-component")
var urix = require("urix")
var atob = require("atob")
function callbackAsync(callback, error, result) {
setImmediate(function() { callback(error, result) })
}
function parseMapToJSON(string, data) {
try {
return JSON.parse(string.replace(/^\)\]\}'/, ""))
} catch (error) {
error.sourceMapData = data
throw error
}
}
function readSync(read, url, data) {
var readUrl = decodeUriComponent(url)
try {
return String(read(readUrl))
} catch (error) {
error.sourceMapData = data
throw error
}
}
function resolveSourceMap(code, codeUrl, read, callback) {
var mapData
try {
mapData = resolveSourceMapHelper(code, codeUrl)
} catch (error) {
return callbackAsync(callback, error)
}
if (!mapData || mapData.map) {
return callbackAsync(callback, null, mapData)
}
var readUrl = decodeUriComponent(mapData.url)
read(readUrl, function(error, result) {
if (error) {
error.sourceMapData = mapData
return callback(error)
}
mapData.map = String(result)
try {
mapData.map = parseMapToJSON(mapData.map, mapData)
} catch (error) {
return callback(error)
}
callback(null, mapData)
})
}
function resolveSourceMapSync(code, codeUrl, read) {
var mapData = resolveSourceMapHelper(code, codeUrl)
if (!mapData || mapData.map) {
return mapData
}
mapData.map = readSync(read, mapData.url, mapData)
mapData.map = parseMapToJSON(mapData.map, mapData)
return mapData
}
var dataUriRegex = /^data:([^,;]*)(;[^,;]*)*(?:,(.*))?$/
/**
* The media type for JSON text is application/json.
*
* {@link https://tools.ietf.org/html/rfc8259#section-11 | IANA Considerations }
*
* `text/json` is non-standard media type
*/
var jsonMimeTypeRegex = /^(?:application|text)\/json$/
/**
* JSON text exchanged between systems that are not part of a closed ecosystem
* MUST be encoded using UTF-8.
*
* {@link https://tools.ietf.org/html/rfc8259#section-8.1 | Character Encoding}
*/
var jsonCharacterEncoding = "utf-8"
function base64ToBuf(b64) {
var binStr = atob(b64)
var len = binStr.length
var arr = new Uint8Array(len)
for (var i = 0; i < len; i++) {
arr[i] = binStr.charCodeAt(i)
}
return arr
}
function decodeBase64String(b64) {
if (typeof TextDecoder === "undefined" || typeof Uint8Array === "undefined") {
return atob(b64)
}
var buf = base64ToBuf(b64);
// Note: `decoder.decode` method will throw a `DOMException` with the
// `"EncodingError"` value when an coding error is found.
var decoder = new TextDecoder(jsonCharacterEncoding, {fatal: true})
return decoder.decode(buf);
}
function resolveSourceMapHelper(code, codeUrl) {
codeUrl = urix(codeUrl)
var url = sourceMappingURL.getFrom(code)
if (!url) {
return null
}
var dataUri = url.match(dataUriRegex)
if (dataUri) {
var mimeType = dataUri[1] || "text/plain"
var lastParameter = dataUri[2] || ""
var encoded = dataUri[3] || ""
var data = {
sourceMappingURL: url,
url: null,
sourcesRelativeTo: codeUrl,
map: encoded
}
if (!jsonMimeTypeRegex.test(mimeType)) {
var error = new Error("Unuseful data uri mime type: " + mimeType)
error.sourceMapData = data
throw error
}
try {
data.map = parseMapToJSON(
lastParameter === ";base64" ? decodeBase64String(encoded) : decodeURIComponent(encoded),
data
)
} catch (error) {
error.sourceMapData = data
throw error
}
return data
}
var mapUrl = resolveUrl(codeUrl, url)
return {
sourceMappingURL: url,
url: mapUrl,
sourcesRelativeTo: mapUrl,
map: null
}
}
function resolveSources(map, mapUrl, read, options, callback) {
if (typeof options === "function") {
callback = options
options = {}
}
var pending = map.sources ? map.sources.length : 0
var result = {
sourcesResolved: [],
sourcesContent: []
}
if (pending === 0) {
callbackAsync(callback, null, result)
return
}
var done = function() {
pending--
if (pending === 0) {
callback(null, result)
}
}
resolveSourcesHelper(map, mapUrl, options, function(fullUrl, sourceContent, index) {
result.sourcesResolved[index] = fullUrl
if (typeof sourceContent === "string") {
result.sourcesContent[index] = sourceContent
callbackAsync(done, null)
} else {
var readUrl = decodeUriComponent(fullUrl)
read(readUrl, function(error, source) {
result.sourcesContent[index] = error ? error : String(source)
done()
})
}
})
}
function resolveSourcesSync(map, mapUrl, read, options) {
var result = {
sourcesResolved: [],
sourcesContent: []
}
if (!map.sources || map.sources.length === 0) {
return result
}
resolveSourcesHelper(map, mapUrl, options, function(fullUrl, sourceContent, index) {
result.sourcesResolved[index] = fullUrl
if (read !== null) {
if (typeof sourceContent === "string") {
result.sourcesContent[index] = sourceContent
} else {
var readUrl = decodeUriComponent(fullUrl)
try {
result.sourcesContent[index] = String(read(readUrl))
} catch (error) {
result.sourcesContent[index] = error
}
}
}
})
return result
}
var endingSlash = /\/?$/
function resolveSourcesHelper(map, mapUrl, options, fn) {
options = options || {}
mapUrl = urix(mapUrl)
var fullUrl
var sourceContent
var sourceRoot
for (var index = 0, len = map.sources.length; index < len; index++) {
sourceRoot = null
if (typeof options.sourceRoot === "string") {
sourceRoot = options.sourceRoot
} else if (typeof map.sourceRoot === "string" && options.sourceRoot !== false) {
sourceRoot = map.sourceRoot
}
// If the sourceRoot is the empty string, it is equivalent to not setting
// the property at all.
if (sourceRoot === null || sourceRoot === '') {
fullUrl = resolveUrl(mapUrl, map.sources[index])
} else {
// Make sure that the sourceRoot ends with a slash, so that `/scripts/subdir` becomes
// `/scripts/subdir/<source>`, not `/scripts/<source>`. Pointing to a file as source root
// does not make sense.
fullUrl = resolveUrl(mapUrl, sourceRoot.replace(endingSlash, "/"), map.sources[index])
}
sourceContent = (map.sourcesContent || [])[index]
fn(fullUrl, sourceContent, index)
}
}
function resolve(code, codeUrl, read, options, callback) {
if (typeof options === "function") {
callback = options
options = {}
}
if (code === null) {
var mapUrl = codeUrl
var data = {
sourceMappingURL: null,
url: mapUrl,
sourcesRelativeTo: mapUrl,
map: null
}
var readUrl = decodeUriComponent(mapUrl)
read(readUrl, function(error, result) {
if (error) {
error.sourceMapData = data
return callback(error)
}
data.map = String(result)
try {
data.map = parseMapToJSON(data.map, data)
} catch (error) {
return callback(error)
}
_resolveSources(data)
})
} else {
resolveSourceMap(code, codeUrl, read, function(error, mapData) {
if (error) {
return callback(error)
}
if (!mapData) {
return callback(null, null)
}
_resolveSources(mapData)
})
}
function _resolveSources(mapData) {
resolveSources(mapData.map, mapData.sourcesRelativeTo, read, options, function(error, result) {
if (error) {
return callback(error)
}
mapData.sourcesResolved = result.sourcesResolved
mapData.sourcesContent = result.sourcesContent
callback(null, mapData)
})
}
}
function resolveSync(code, codeUrl, read, options) {
var mapData
if (code === null) {
var mapUrl = codeUrl
mapData = {
sourceMappingURL: null,
url: mapUrl,
sourcesRelativeTo: mapUrl,
map: null
}
mapData.map = readSync(read, mapUrl, mapData)
mapData.map = parseMapToJSON(mapData.map, mapData)
} else {
mapData = resolveSourceMapSync(code, codeUrl, read)
if (!mapData) {
return null
}
}
var result = resolveSourcesSync(mapData.map, mapData.sourcesRelativeTo, read, options)
mapData.sourcesResolved = result.sourcesResolved
mapData.sourcesContent = result.sourcesContent
return mapData
}
module.exports = {
resolveSourceMap: resolveSourceMap,
resolveSourceMapSync: resolveSourceMapSync,
resolveSources: resolveSources,
resolveSourcesSync: resolveSourcesSync,
resolve: resolve,
resolveSync: resolveSync,
parseMapToJSON: parseMapToJSON
}

View file

@ -0,0 +1,47 @@
{
"name": "source-map-resolve",
"version": "0.5.3",
"author": "Simon Lydell",
"license": "MIT",
"description": "Resolve the source map and/or sources for a generated file.",
"keywords": [
"source map",
"sourcemap",
"source",
"map",
"sourceMappingURL",
"resolve",
"resolver",
"locate",
"locator",
"find",
"finder"
],
"repository": "lydell/source-map-resolve",
"main": "lib/source-map-resolve-node.js",
"browser": "source-map-resolve.js",
"files": [
"lib",
"source-map-resolve.js"
],
"scripts": {
"lint": "jshint lib/ test/",
"unit": "node test/source-map-resolve.js && node test/windows.js",
"test": "npm run lint && npm run unit",
"build": "node generate-source-map-resolve.js"
},
"dependencies": {
"atob": "^2.1.2",
"decode-uri-component": "^0.2.0",
"resolve-url": "^0.2.1",
"source-map-url": "^0.4.0",
"urix": "^0.1.0"
},
"devDependencies": {
"Base64": "1.1.0",
"jshint": "2.10.3",
"setimmediate": "1.0.5",
"simple-asyncify": "1.0.0",
"tape": "4.12.1"
}
}

View file

@ -0,0 +1,231 @@
Overview [![Build Status](https://travis-ci.org/lydell/source-map-resolve.svg?branch=master)](https://travis-ci.org/lydell/source-map-resolve)
========
Resolve the source map and/or sources for a generated file.
```js
var sourceMapResolve = require("source-map-resolve")
var sourceMap = require("source-map")
var code = [
"!function(){...}();",
"/*# sourceMappingURL=foo.js.map */"
].join("\n")
sourceMapResolve.resolveSourceMap(code, "/js/foo.js", fs.readFile, function(error, result) {
if (error) {
return notifyFailure(error)
}
result
// {
// map: {file: "foo.js", mappings: "...", sources: ["/coffee/foo.coffee"], names: []},
// url: "/js/foo.js.map",
// sourcesRelativeTo: "/js/foo.js.map",
// sourceMappingURL: "foo.js.map"
// }
sourceMapResolve.resolveSources(result.map, result.sourcesRelativeTo, fs.readFile, function(error, result) {
if (error) {
return notifyFailure(error)
}
result
// {
// sourcesResolved: ["/coffee/foo.coffee"],
// sourcesContent: ["<contents of /coffee/foo.coffee>"]
// }
})
})
sourceMapResolve.resolve(code, "/js/foo.js", fs.readFile, function(error, result) {
if (error) {
return notifyFailure(error)
}
result
// {
// map: {file: "foo.js", mappings: "...", sources: ["/coffee/foo.coffee"], names: []},
// url: "/js/foo.js.map",
// sourcesRelativeTo: "/js/foo.js.map",
// sourceMappingURL: "foo.js.map",
// sourcesResolved: ["/coffee/foo.coffee"],
// sourcesContent: ["<contents of /coffee/foo.coffee>"]
// }
result.map.sourcesContent = result.sourcesContent
var map = new sourceMap.sourceMapConsumer(result.map)
map.sourceContentFor("/coffee/foo.coffee")
// "<contents of /coffee/foo.coffee>"
})
```
Installation
============
- `npm install source-map-resolve`
- `bower install source-map-resolve`
- `component install lydell/source-map-resolve`
Works with CommonJS, AMD and browser globals, through UMD.
Note: This module requires `setImmediate` and `atob`.
Use polyfills if needed, such as:
- <https://github.com/NobleJS/setImmediate>
- <https://github.com/davidchambers/Base64.js>
Usage
=====
### `sourceMapResolve.resolveSourceMap(code, codeUrl, read, callback)` ###
- `code` is a string of code that may or may not contain a sourceMappingURL
comment. Such a comment is used to resolve the source map.
- `codeUrl` is the url to the file containing `code`. If the sourceMappingURL
is relative, it is resolved against `codeUrl`.
- `read(url, callback)` is a function that reads `url` and responds using
`callback(error, content)`. In Node.js you might want to use `fs.readFile`,
while in the browser you might want to use an asynchronus `XMLHttpRequest`.
- `callback(error, result)` is a function that is invoked with either an error
or `null` and the result.
The result is an object with the following properties:
- `map`: The source map for `code`, as an object (not a string).
- `url`: The url to the source map. If the source map came from a data uri,
this property is `null`, since then there is no url to it.
- `sourcesRelativeTo`: The url that the sources of the source map are relative
to. Since the sources are relative to the source map, and the url to the
source map is provided as the `url` property, this property might seem
superfluos. However, remember that the `url` property can be `null` if the
source map came from a data uri. If so, the sources are relative to the file
containing the data uri—`codeUrl`. This property will be identical to the
`url` property or `codeUrl`, whichever is appropriate. This way you can
conveniently resolve the sources without having to think about where the
source map came from.
- `sourceMappingURL`: The url of the sourceMappingURL comment in `code`.
If `code` contains no sourceMappingURL, the result is `null`.
### `sourceMapResolve.resolveSources(map, mapUrl, read, [options], callback)` ###
- `map` is a source map, as an object (not a string).
- `mapUrl` is the url to the file containing `map`. Relative sources in the
source map, if any, are resolved against `mapUrl`.
- `read(url, callback)` is a function that reads `url` and responds using
`callback(error, content)`. In Node.js you might want to use `fs.readFile`,
while in the browser you might want to use an asynchronus `XMLHttpRequest`.
- `options` is an optional object with any of the following properties:
- `sourceRoot`: Override the `sourceRoot` property of the source map, which
might only be relevant when resolving sources in the browser. This lets you
bypass it when using the module outside of a browser, if needed. Pass a
string to replace the `sourceRoot` property with, or `false` to ignore it.
Defaults to `undefined`.
- `callback(error, result)` is a function that is invoked with either an error
or `null` and the result.
The result is an object with the following properties:
- `sourcesResolved`: The same as `map.sources`, except all the sources are
fully resolved.
- `sourcesContent`: An array with the contents of all sources in `map.sources`,
in the same order as `map.sources`. If getting the contents of a source fails,
an error object is put into the array instead.
### `sourceMapResolve.resolve(code, codeUrl, read, [options], callback)` ###
The arguments are identical to `sourceMapResolve.resolveSourceMap`, except that
you may also provide the same `options` as in `sourceMapResolve.resolveSources`.
This is a convenience method that first resolves the source map and then its
sources. You could also do this by first calling
`sourceMapResolve.resolveSourceMap` and then `sourceMapResolve.resolveSources`.
The result is identical to `sourceMapResolve.resolveSourceMap`, with the
properties from `sourceMapResolve.resolveSources` merged into it.
There is one extra feature available, though. If `code` is `null`, `codeUrl` is
treated as a url to the source map instead of to `code`, and will be read. This
is handy if you _sometimes_ get the source map url from the `SourceMap: <url>`
header (see the [Notes] section). In this case, the `sourceMappingURL` property
of the result is `null`.
[Notes]: #notes
### `sourceMapResolve.*Sync()` ###
There are also sync versions of the three previous functions. They are identical
to the async versions, except:
- They expect a sync reading function. In Node.js you might want to use
`fs.readFileSync`, while in the browser you might want to use a synchronus
`XMLHttpRequest`.
- They throw errors and return the result instead of using a callback.
`sourceMapResolve.resolveSourcesSync` also accepts `null` as the `read`
parameter. The result is the same as when passing a function as the `read
parameter`, except that the `sourcesContent` property of the result will be an
empty array. In other words, the sources arent read. You only get the
`sourcesResolved` property. (This only supported in the synchronus version, since
there is no point doing it asynchronusly.)
### `sourceMapResolve.parseMapToJSON(string, [data])` ###
The spec says that if a source map (as a string) starts with `)]}'`, it should
be stripped off. This is to prevent XSSI attacks. This function does that and
returns the result of `JSON.parse`ing whats left.
If this function throws `error`, `error.sourceMapData === data`.
### Errors
All errors passed to callbacks or thrown by this module have a `sourceMapData`
property that contain as much as possible of the intended result of the function
up until the error occurred.
Note that while the `map` property of result objects always is an object,
`error.sourceMapData.map` will be a string if parsing that string fails.
Note
====
This module resolves the source map for a given generated file by looking for a
sourceMappingURL comment. The spec defines yet a way to provide the URL to the
source map: By sending the `SourceMap: <url>` header along with the generated
file. Since this module doesnt retrive the generated code for you (instead
_you_ give the generated code to the module), its up to you to look for such a
header when you retrieve the file (should the need arise).
Development
===========
Tests
-----
First off, run `npm install` to install testing modules and browser polyfills.
`npm test` lints the code and runs the test suite in Node.js.
x-package.json5
---------------
package.json, component.json and bower.json are all generated from
x-package.json5 by using [`xpkg`]. Only edit x-package.json5, and remember to
run `xpkg` before commiting!
[`xpkg`]: https://github.com/kof/node-xpkg
Generating the browser version
------------------------------
source-map-resolve.js is generated from source-map-resolve-node.js and
source-map-resolve-template.js. Only edit the two latter files, _not_
source-map-resolve.js! To generate it, run `npm run build`.
License
=======
[MIT](LICENSE).

View file

@ -0,0 +1,348 @@
// Note: source-map-resolve.js is generated from source-map-resolve-node.js and
// source-map-resolve-template.js. Only edit the two latter files, _not_
// source-map-resolve.js!
void (function(root, factory) {
if (typeof define === "function" && define.amd) {
define(["source-map-url", "resolve-url"], factory)
} else if (typeof exports === "object") {
var sourceMappingURL = require("source-map-url")
var resolveUrl = require("resolve-url")
module.exports = factory(sourceMappingURL, resolveUrl)
} else {
root.sourceMapResolve = factory(root.sourceMappingURL, root.resolveUrl)
}
}(this, function(sourceMappingURL, resolveUrl) {
function callbackAsync(callback, error, result) {
setImmediate(function() { callback(error, result) })
}
function parseMapToJSON(string, data) {
try {
return JSON.parse(string.replace(/^\)\]\}'/, ""))
} catch (error) {
error.sourceMapData = data
throw error
}
}
function readSync(read, url, data) {
var readUrl = url
try {
return String(read(readUrl))
} catch (error) {
error.sourceMapData = data
throw error
}
}
function resolveSourceMap(code, codeUrl, read, callback) {
var mapData
try {
mapData = resolveSourceMapHelper(code, codeUrl)
} catch (error) {
return callbackAsync(callback, error)
}
if (!mapData || mapData.map) {
return callbackAsync(callback, null, mapData)
}
var readUrl = mapData.url
read(readUrl, function(error, result) {
if (error) {
error.sourceMapData = mapData
return callback(error)
}
mapData.map = String(result)
try {
mapData.map = parseMapToJSON(mapData.map, mapData)
} catch (error) {
return callback(error)
}
callback(null, mapData)
})
}
function resolveSourceMapSync(code, codeUrl, read) {
var mapData = resolveSourceMapHelper(code, codeUrl)
if (!mapData || mapData.map) {
return mapData
}
mapData.map = readSync(read, mapData.url, mapData)
mapData.map = parseMapToJSON(mapData.map, mapData)
return mapData
}
var dataUriRegex = /^data:([^,;]*)(;[^,;]*)*(?:,(.*))?$/
/**
* The media type for JSON text is application/json.
*
* {@link https://tools.ietf.org/html/rfc8259#section-11 | IANA Considerations }
*
* `text/json` is non-standard media type
*/
var jsonMimeTypeRegex = /^(?:application|text)\/json$/
/**
* JSON text exchanged between systems that are not part of a closed ecosystem
* MUST be encoded using UTF-8.
*
* {@link https://tools.ietf.org/html/rfc8259#section-8.1 | Character Encoding}
*/
var jsonCharacterEncoding = "utf-8"
function base64ToBuf(b64) {
var binStr = atob(b64)
var len = binStr.length
var arr = new Uint8Array(len)
for (var i = 0; i < len; i++) {
arr[i] = binStr.charCodeAt(i)
}
return arr
}
function decodeBase64String(b64) {
if (typeof TextDecoder === "undefined" || typeof Uint8Array === "undefined") {
return atob(b64)
}
var buf = base64ToBuf(b64);
// Note: `decoder.decode` method will throw a `DOMException` with the
// `"EncodingError"` value when an coding error is found.
var decoder = new TextDecoder(jsonCharacterEncoding, {fatal: true})
return decoder.decode(buf);
}
function resolveSourceMapHelper(code, codeUrl) {
var url = sourceMappingURL.getFrom(code)
if (!url) {
return null
}
var dataUri = url.match(dataUriRegex)
if (dataUri) {
var mimeType = dataUri[1] || "text/plain"
var lastParameter = dataUri[2] || ""
var encoded = dataUri[3] || ""
var data = {
sourceMappingURL: url,
url: null,
sourcesRelativeTo: codeUrl,
map: encoded
}
if (!jsonMimeTypeRegex.test(mimeType)) {
var error = new Error("Unuseful data uri mime type: " + mimeType)
error.sourceMapData = data
throw error
}
try {
data.map = parseMapToJSON(
lastParameter === ";base64" ? decodeBase64String(encoded) : decodeURIComponent(encoded),
data
)
} catch (error) {
error.sourceMapData = data
throw error
}
return data
}
var mapUrl = resolveUrl(codeUrl, url)
return {
sourceMappingURL: url,
url: mapUrl,
sourcesRelativeTo: mapUrl,
map: null
}
}
function resolveSources(map, mapUrl, read, options, callback) {
if (typeof options === "function") {
callback = options
options = {}
}
var pending = map.sources ? map.sources.length : 0
var result = {
sourcesResolved: [],
sourcesContent: []
}
if (pending === 0) {
callbackAsync(callback, null, result)
return
}
var done = function() {
pending--
if (pending === 0) {
callback(null, result)
}
}
resolveSourcesHelper(map, mapUrl, options, function(fullUrl, sourceContent, index) {
result.sourcesResolved[index] = fullUrl
if (typeof sourceContent === "string") {
result.sourcesContent[index] = sourceContent
callbackAsync(done, null)
} else {
var readUrl = fullUrl
read(readUrl, function(error, source) {
result.sourcesContent[index] = error ? error : String(source)
done()
})
}
})
}
function resolveSourcesSync(map, mapUrl, read, options) {
var result = {
sourcesResolved: [],
sourcesContent: []
}
if (!map.sources || map.sources.length === 0) {
return result
}
resolveSourcesHelper(map, mapUrl, options, function(fullUrl, sourceContent, index) {
result.sourcesResolved[index] = fullUrl
if (read !== null) {
if (typeof sourceContent === "string") {
result.sourcesContent[index] = sourceContent
} else {
var readUrl = fullUrl
try {
result.sourcesContent[index] = String(read(readUrl))
} catch (error) {
result.sourcesContent[index] = error
}
}
}
})
return result
}
var endingSlash = /\/?$/
function resolveSourcesHelper(map, mapUrl, options, fn) {
options = options || {}
var fullUrl
var sourceContent
var sourceRoot
for (var index = 0, len = map.sources.length; index < len; index++) {
sourceRoot = null
if (typeof options.sourceRoot === "string") {
sourceRoot = options.sourceRoot
} else if (typeof map.sourceRoot === "string" && options.sourceRoot !== false) {
sourceRoot = map.sourceRoot
}
// If the sourceRoot is the empty string, it is equivalent to not setting
// the property at all.
if (sourceRoot === null || sourceRoot === '') {
fullUrl = resolveUrl(mapUrl, map.sources[index])
} else {
// Make sure that the sourceRoot ends with a slash, so that `/scripts/subdir` becomes
// `/scripts/subdir/<source>`, not `/scripts/<source>`. Pointing to a file as source root
// does not make sense.
fullUrl = resolveUrl(mapUrl, sourceRoot.replace(endingSlash, "/"), map.sources[index])
}
sourceContent = (map.sourcesContent || [])[index]
fn(fullUrl, sourceContent, index)
}
}
function resolve(code, codeUrl, read, options, callback) {
if (typeof options === "function") {
callback = options
options = {}
}
if (code === null) {
var mapUrl = codeUrl
var data = {
sourceMappingURL: null,
url: mapUrl,
sourcesRelativeTo: mapUrl,
map: null
}
var readUrl = mapUrl
read(readUrl, function(error, result) {
if (error) {
error.sourceMapData = data
return callback(error)
}
data.map = String(result)
try {
data.map = parseMapToJSON(data.map, data)
} catch (error) {
return callback(error)
}
_resolveSources(data)
})
} else {
resolveSourceMap(code, codeUrl, read, function(error, mapData) {
if (error) {
return callback(error)
}
if (!mapData) {
return callback(null, null)
}
_resolveSources(mapData)
})
}
function _resolveSources(mapData) {
resolveSources(mapData.map, mapData.sourcesRelativeTo, read, options, function(error, result) {
if (error) {
return callback(error)
}
mapData.sourcesResolved = result.sourcesResolved
mapData.sourcesContent = result.sourcesContent
callback(null, mapData)
})
}
}
function resolveSync(code, codeUrl, read, options) {
var mapData
if (code === null) {
var mapUrl = codeUrl
mapData = {
sourceMappingURL: null,
url: mapUrl,
sourcesRelativeTo: mapUrl,
map: null
}
mapData.map = readSync(read, mapUrl, mapData)
mapData.map = parseMapToJSON(mapData.map, mapData)
} else {
mapData = resolveSourceMapSync(code, codeUrl, read)
if (!mapData) {
return null
}
}
var result = resolveSourcesSync(mapData.map, mapData.sourcesRelativeTo, read, options)
mapData.sourcesResolved = result.sourcesResolved
mapData.sourcesContent = result.sourcesContent
return mapData
}
return {
resolveSourceMap: resolveSourceMap,
resolveSourceMapSync: resolveSourceMapSync,
resolveSources: resolveSources,
resolveSourcesSync: resolveSourcesSync,
resolve: resolve,
resolveSync: resolveSync,
parseMapToJSON: parseMapToJSON
}
}));

32
web/node_modules/rework/package.json generated vendored Normal file
View file

@ -0,0 +1,32 @@
{
"name": "rework",
"version": "1.0.1",
"description": "Plugin framework for CSS preprocessing",
"main": "index",
"files": [
"index.js"
],
"dependencies": {
"css": "^2.0.0",
"convert-source-map": "^0.3.3"
},
"devDependencies": {
"mocha": "^1.20.1",
"should": "^4.0.4"
},
"scripts": {
"test": "mocha --require should --reporter spec"
},
"keywords": [
"css",
"manipulation",
"preprocess",
"transform",
"server"
],
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"repository": {
"type": "git",
"url": "git://github.com/reworkcss/rework.git"
}
}