first commit

This commit is contained in:
DanielRamirezGe
2020-01-14 20:43:08 -06:00
parent 3557894f7f
commit 5eecfbf6cd
26326 changed files with 2434803 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
Copyright (c) Ben Briggs <beneb.info@gmail.com> (http://beneb.info)
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.
+126
View File
@@ -0,0 +1,126 @@
# [postcss][postcss]-svgo
> Optimise inline SVG with PostCSS.
## Install
With [npm](https://npmjs.org/package/postcss-svgo) do:
```
npm install postcss-svgo --save
```
## Example
### Input
```css
h1 {
background: url('data:image/svg+xml;charset=utf-8,<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve"><circle cx="50" cy="50" r="40" fill="yellow" /></svg>');
}
h2 {
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PGNpcmNsZSBjeD0iNTAiIGN5PSI1MCIgcj0iNDAiIGZpbGw9InllbGxvdyIgLz48IS0tdGVzdCBjb21tZW50LS0+PC9zdmc+');
}
```
### Output
```css
h1 {
background: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" fill="%23ff0"/></svg>');
}
h2 {
background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxjaXJjbGUgY3g9IjUwIiBjeT0iNTAiIHI9IjQwIiBmaWxsPSIjZmYwIi8+PC9zdmc+');
}
```
## API
### `svgo([options])`
Note that postcss-svgo is an *asynchronous* processor. It cannot be used
like this:
```js
var result = postcss([ svgo() ]).process(css).css;
console.log(result);
```
Instead make sure your PostCSS runner uses the asynchronous API:
```js
postcss([ svgo() ]).process(css).then(function (result) {
console.log(result.css);
});
```
#### options
##### encode
Type: `boolean`
Default: `undefined`
If `true`, it will encode URL-unsafe characters such as `<`, `>` and `&`;
`false` will decode these characters, and `undefined` will neither encode nor
decode the original input. Note that regardless of this setting, `#` will
always be URL-encoded.
##### plugins
Optionally, you can customise the output by specifying the `plugins` option. You
will need to provide the config in comma separated objects, like the example
below. Note that you can either disable the plugin by setting it to `false`,
or pass different options to change the default behaviour.
```js
var postcss = require('postcss');
var svgo = require('postcss-svgo');
var opts = {
plugins: [{
removeDoctype: false
}, {
removeComments: false
}, {
cleanupNumericValues: {
floatPrecision: 2
}
}, {
convertColors: {
names2hex: false,
rgb2hex: false
}
}]
};
postcss([ svgo(opts) ]).process(css).then(function (result) {
console.log(result.css)
});
```
You can view the [full list of plugins here][plugins].
## Usage
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
examples for your environment.
## Contributors
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).
## License
MIT © [Ben Briggs](http://beneb.info)
[postcss]: https://github.com/postcss/postcss
[plugins]: https://github.com/svg/svgo/tree/master/plugins
+131
View File
@@ -0,0 +1,131 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _postcss = require('postcss');
var _postcss2 = _interopRequireDefault(_postcss);
var _postcssValueParser = require('postcss-value-parser');
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
var _svgo = require('svgo');
var _svgo2 = _interopRequireDefault(_svgo);
var _isSvg = require('is-svg');
var _isSvg2 = _interopRequireDefault(_isSvg);
var _url = require('./lib/url');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const PLUGIN = 'postcss-svgo';
const dataURI = /data:image\/svg\+xml(;((charset=)?utf-8|base64))?,/i;
const dataURIBase64 = /data:image\/svg\+xml;base64,/i;
function minifyPromise(decl, getSvgo, opts) {
const promises = [];
const parsed = (0, _postcssValueParser2.default)(decl.value);
decl.value = parsed.walk(node => {
if (node.type !== 'function' || node.value.toLowerCase() !== 'url' || !node.nodes.length) {
return;
}
let { value, quote } = node.nodes[0];
let isBase64, isUriEncoded;
let svg = value.replace(dataURI, '');
if (dataURIBase64.test(value)) {
svg = Buffer.from(svg, 'base64').toString('utf8');
isBase64 = true;
} else {
let decodedUri;
try {
decodedUri = (0, _url.decode)(svg);
isUriEncoded = decodedUri !== svg;
} catch (e) {
// Swallow exception if we cannot decode the value
isUriEncoded = false;
}
if (isUriEncoded) {
svg = decodedUri;
}
if (opts.encode !== undefined) {
isUriEncoded = opts.encode;
}
}
if (!(0, _isSvg2.default)(svg)) {
return;
}
promises.push(getSvgo().optimize(svg).then(result => {
let data, optimizedValue;
if (isBase64) {
data = Buffer.from(result.data).toString('base64');
optimizedValue = 'data:image/svg+xml;base64,' + data;
} else {
data = isUriEncoded ? (0, _url.encode)(result.data) : result.data;
// Should always encode # otherwise we yield a broken SVG
// in Firefox (works in Chrome however). See this issue:
// https://github.com/cssnano/cssnano/issues/245
data = data.replace(/#/g, '%23');
optimizedValue = 'data:image/svg+xml;charset=utf-8,' + data;
quote = isUriEncoded ? '"' : '\'';
}
node.nodes[0] = Object.assign({}, node.nodes[0], {
value: optimizedValue,
quote: quote,
type: 'string',
before: '',
after: ''
});
}).catch(error => {
throw new Error(`${PLUGIN}: ${error}`);
}));
return false;
});
return Promise.all(promises).then(() => decl.value = decl.value.toString());
}
exports.default = _postcss2.default.plugin(PLUGIN, (opts = {}) => {
let svgo = null;
const getSvgo = () => {
if (!svgo) {
svgo = new _svgo2.default(opts);
}
return svgo;
};
return css => {
return new Promise((resolve, reject) => {
const svgoQueue = [];
css.walkDecls(decl => {
if (!dataURI.test(decl.value)) {
return;
}
svgoQueue.push(minifyPromise(decl, getSvgo, opts));
});
return Promise.all(svgoQueue).then(resolve, reject);
});
};
});
module.exports = exports['default'];
+11
View File
@@ -0,0 +1,11 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.encode = encode;
function encode(data) {
return data.replace(/"/g, '\'').replace(/%/g, '%25').replace(/</g, '%3C').replace(/>/g, '%3E').replace(/&/g, '%26').replace(/#/g, '%23').replace(/\s+/g, ' ');
};
const decode = exports.decode = decodeURIComponent;
+75
View File
@@ -0,0 +1,75 @@
{
"_from": "postcss-svgo@^4.0.2",
"_id": "postcss-svgo@4.0.2",
"_inBundle": false,
"_integrity": "sha512-C6wyjo3VwFm0QgBy+Fu7gCYOkCmgmClghO+pjcxvrcBKtiKt0uCF+hvbMO1fyv5BMImRK90SMb+dwUnfbGd+jw==",
"_location": "/postcss-svgo",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "postcss-svgo@^4.0.2",
"name": "postcss-svgo",
"escapedName": "postcss-svgo",
"rawSpec": "^4.0.2",
"saveSpec": null,
"fetchSpec": "^4.0.2"
},
"_requiredBy": [
"/cssnano-preset-default"
],
"_resolved": "https://registry.npmjs.org/postcss-svgo/-/postcss-svgo-4.0.2.tgz",
"_shasum": "17b997bc711b333bab143aaed3b8d3d6e3d38258",
"_spec": "postcss-svgo@^4.0.2",
"_where": "/home/george/citwa/red_de_investigacion_front/first/node_modules/cssnano-preset-default",
"author": {
"name": "Ben Briggs",
"email": "beneb.info@gmail.com",
"url": "http://beneb.info"
},
"bugs": {
"url": "https://github.com/cssnano/cssnano/issues"
},
"bundleDependencies": false,
"dependencies": {
"is-svg": "^3.0.0",
"postcss": "^7.0.0",
"postcss-value-parser": "^3.0.0",
"svgo": "^1.0.0"
},
"deprecated": false,
"description": "Optimise inline SVG with PostCSS.",
"devDependencies": {
"babel-cli": "^6.0.0",
"cross-env": "^5.0.0",
"pleeease-filters": "^4.0.0"
},
"engines": {
"node": ">=6.9.0"
},
"files": [
"LICENSE-MIT",
"dist"
],
"homepage": "https://github.com/cssnano/cssnano",
"keywords": [
"css",
"minify",
"optimise",
"postcss",
"postcss-plugin",
"svg",
"svgo"
],
"license": "MIT",
"main": "dist/index.js",
"name": "postcss-svgo",
"repository": {
"type": "git",
"url": "git+https://github.com/cssnano/cssnano.git"
},
"scripts": {
"prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
},
"version": "4.0.2"
}