WIP - add extractor, generate snippet_data
This commit is contained in:
21
node_modules/mini-svg-data-uri/LICENSE
generated
vendored
Normal file
21
node_modules/mini-svg-data-uri/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Taylor Hunt
|
||||
|
||||
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.
|
||||
98
node_modules/mini-svg-data-uri/README.md
generated
vendored
Normal file
98
node_modules/mini-svg-data-uri/README.md
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
Mini SVG `data:` URI
|
||||
====================
|
||||
|
||||
This tool converts SVGs into the most compact, compressible `data:` URI that SVG-supporting browsers tolerate. The results look like this (169 bytes):
|
||||
|
||||
```url
|
||||
data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50'
|
||||
%3e%3cpath d='M22 38V51L32 32l19-19v12C44 26 43 10 38 0 52 15 49 39 22 38z'/%3e
|
||||
%3c/svg%3e
|
||||
```
|
||||
|
||||
Compare to the Base64 version (210 bytes):
|
||||
|
||||
```url
|
||||
data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIH
|
||||
ZpZXdCb3g9IjAgMCA1MCA1MCI+PHBhdGggZD0iTTIyIDM4VjUxTDMyIDMybDE5LTE5djEyQzQ0IDI2ID
|
||||
QzIDEwIDM4IDAgNTIgMTUgNDkgMzkgMjIgMzh6Ii8+PC9zdmc+
|
||||
```
|
||||
|
||||
Or the URL-encoded version other tools produce (256 bytes):
|
||||
|
||||
```url
|
||||
data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%
|
||||
2F2000%2Fsvg%22%20viewBox%3D%220%200%2050%2050%22%3E%3Cpath%20d%3D%22M22%2038V51
|
||||
L32%2032l19-19v12C44%2026%2043%2010%2038%200%2052%2015%2049%2039%2022%2038z%22%2
|
||||
F%3E%3C%2Fsvg%3E
|
||||
```
|
||||
|
||||
For a more realistic example, I inlined the icons from the [Open Iconic](https://useiconic.com/open) project into CSS files with the 3 above methods:
|
||||
|
||||
| Compression | Base64 | Basic %-encoding | `mini-svg-data-uri` |
|
||||
|-------------|----------:|-----------------:|--------------------:|
|
||||
| None | 96.459 kB | 103.268 kB | 76.583 kB |
|
||||
| `gzip -9` | 17.902 kB | 13.780 kB | 12.974 kB |
|
||||
| `brotli -Z` | 15.797 kB | 11.693 kB | 10.976 kB |
|
||||
|
||||
Roughly 6% smaller compressed, but don't write off the ≈20% uncompressed savings either. [Some browser caches decompress before store](https://blogs.msdn.microsoft.com/ieinternals/2014/10/21/compressing-the-web/), and parsing time/memory usage scale linearly with uncompressed filesize.
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
```js
|
||||
var svgToMiniDataURI = require('mini-svg-data-uri');
|
||||
|
||||
var svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"><path d="M22 38V51L32 32l19-19v12C44 26 43 10 38 0 52 15 49 39 22 38z"/></svg>';
|
||||
|
||||
var optimizedSVGDataURI = svgToMiniDataURI(svg);
|
||||
// "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50'%3e%3cpath d='M22 38V51L32 32l19-19v12C44 26 43 10 38 0 52 15 49 39 22 38z'/%3e%3c/svg%3e"
|
||||
```
|
||||
|
||||
You can also [try it in your browser at RunKit](https://npm.runkit.com/mini-svg-data-uri).
|
||||
|
||||
### Warning
|
||||
|
||||
* This **does not optimize the SVG source file**. You’ll want [svgo](https://github.com/svg/svgo) or its brother [SVGOMG](https://jakearchibald.github.io/svgomg/) for that.
|
||||
|
||||
* The default output **does not work inside `srcset` attributes**. Use the `.toSrcset` method for that:
|
||||
|
||||
```js
|
||||
var srcsetExample = html`
|
||||
<picture>
|
||||
<source srcset="${svgToMiniDataURI.toSrcset(svg)}">
|
||||
<img src="${svgToMiniDataURI(svg)}">
|
||||
</picture>`;
|
||||
```
|
||||
|
||||
* The resulting Data URI should be wrapped with double quotes: `url("…")`, `<img src="…">`, etc.
|
||||
|
||||
* This might change or break SVGs that use `"` in character data, like inside `<text>` or `aria-label` or something. Try curly quotes (`“”`) or `"` instead.
|
||||
|
||||
|
||||
FAQ
|
||||
---
|
||||
|
||||
### Don’t you need a `charset` in the MIME Type?
|
||||
|
||||
`charset` does nothing for Data URIs. The URI can only be the encoding of its parent file — it’s included in it!
|
||||
|
||||
### Why lowercase the URL-encoded hex pairs?
|
||||
|
||||
It compresses slightly better. No, really. Using the same files from earlier:
|
||||
|
||||
| Compression | Uppercase (`%AF`) | Lowercase (`%af`) |
|
||||
|-------------|------------------:|------------------:|
|
||||
| `gzip -9` | 12.978 kB | 12.974 kB |
|
||||
| `brotli -Z` | 10.988 kB | 10.976 kB |
|
||||
|
||||
I did say *slightly*.
|
||||
|
||||
|
||||
Browser support
|
||||
---------------
|
||||
|
||||
* Internet Explorer 9 and up, including Edge
|
||||
* Firefox, Safari, Chrome, whatever else uses their engines
|
||||
* Android WebKit 3+
|
||||
* Opera Mini’s server-side Presto
|
||||
55
node_modules/mini-svg-data-uri/index.js
generated
vendored
Normal file
55
node_modules/mini-svg-data-uri/index.js
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
var shorterNames = require('./shorter-css-color-names');
|
||||
var REGEX = {
|
||||
whitespace: /\s+/g,
|
||||
urlHexPairs: /%[\dA-F]{2}/g,
|
||||
quotes: /"/g,
|
||||
}
|
||||
|
||||
function collapseWhitespace(str) {
|
||||
return str.trim().replace(REGEX.whitespace, ' ');
|
||||
}
|
||||
|
||||
function dataURIPayload(string) {
|
||||
return encodeURIComponent(string)
|
||||
.replace(REGEX.urlHexPairs, specialHexEncode);
|
||||
}
|
||||
|
||||
// `#` gets converted to `%23`, so quite a few CSS named colors are shorter than
|
||||
// their equivalent URL-encoded hex codes.
|
||||
function colorCodeToShorterNames(string) {
|
||||
Object.keys(shorterNames).forEach(function(key) {
|
||||
if (shorterNames[key].test(string)) {
|
||||
string = string.replace(shorterNames[key], key);
|
||||
}
|
||||
});
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
function specialHexEncode(match) {
|
||||
switch (match) { // Browsers tolerate these characters, and they're frequent
|
||||
case '%20': return ' ';
|
||||
case '%3D': return '=';
|
||||
case '%3A': return ':';
|
||||
case '%2F': return '/';
|
||||
default: return match.toLowerCase(); // compresses better
|
||||
}
|
||||
}
|
||||
|
||||
function svgToTinyDataUri(svgString) {
|
||||
if (typeof svgString !== 'string') {
|
||||
throw new TypeError('Expected a string, but received ' + typeof svgString);
|
||||
}
|
||||
// Strip the Byte-Order Mark if the SVG has one
|
||||
if (svgString.charCodeAt(0) === 0xfeff) { svgString = svgString.slice(1) }
|
||||
|
||||
var body = colorCodeToShorterNames(collapseWhitespace(svgString))
|
||||
.replace(REGEX.quotes, "'");
|
||||
return 'data:image/svg+xml,' + dataURIPayload(body);
|
||||
}
|
||||
|
||||
svgToTinyDataUri.toSrcset = function toSrcset(svgString) {
|
||||
return svgToTinyDataUri(svgString).replace(/ /g, '%20');
|
||||
}
|
||||
|
||||
module.exports = svgToTinyDataUri;
|
||||
53
node_modules/mini-svg-data-uri/package.json
generated
vendored
Normal file
53
node_modules/mini-svg-data-uri/package.json
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"_from": "mini-svg-data-uri@^1.0.0",
|
||||
"_id": "mini-svg-data-uri@1.1.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-EeKOmdzekjdPe53/GdxmUpNgDQFkNeSte6XkJmOBt4BfWL6FQ9G9RtLNh+JMjFS3LhdpSICMIkZdznjiecASHQ==",
|
||||
"_location": "/mini-svg-data-uri",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "mini-svg-data-uri@^1.0.0",
|
||||
"name": "mini-svg-data-uri",
|
||||
"escapedName": "mini-svg-data-uri",
|
||||
"rawSpec": "^1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/gatsby-plugin-sharp"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/mini-svg-data-uri/-/mini-svg-data-uri-1.1.3.tgz",
|
||||
"_shasum": "9759ee5f4d89a4b724d089ce52eab4b623bfbc88",
|
||||
"_spec": "mini-svg-data-uri@^1.0.0",
|
||||
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/gatsby-plugin-sharp",
|
||||
"author": {
|
||||
"name": "Taylor “Tigt” Hunt",
|
||||
"email": "holla@ti.gt",
|
||||
"url": "https://ti.gt/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/tigt/mini-svg-data-uri/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Small, efficient encoding of SVG data URIs for CSS, HTML, etc.",
|
||||
"homepage": "https://github.com/tigt/mini-svg-data-uri#readme",
|
||||
"keywords": [
|
||||
"svg",
|
||||
"url",
|
||||
"data",
|
||||
"uri",
|
||||
"minification",
|
||||
"url encoding"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "mini-svg-data-uri",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/tigt/mini-svg-data-uri.git"
|
||||
},
|
||||
"version": "1.1.3"
|
||||
}
|
||||
56
node_modules/mini-svg-data-uri/shorter-css-color-names.js
generated
vendored
Normal file
56
node_modules/mini-svg-data-uri/shorter-css-color-names.js
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
module.exports = {
|
||||
aqua: /#00ffff(ff)?(?!\w)|#0ff(f)?(?!\w)/gi,
|
||||
azure: /#f0ffff(ff)?(?!\w)/gi,
|
||||
beige: /#f5f5dc(ff)?(?!\w)/gi,
|
||||
bisque: /#ffe4c4(ff)?(?!\w)/gi,
|
||||
black: /#000000(ff)?(?!\w)|#000(f)?(?!\w)/gi,
|
||||
blue: /#0000ff(ff)?(?!\w)|#00f(f)?(?!\w)/gi,
|
||||
brown: /#a52a2a(ff)?(?!\w)/gi,
|
||||
coral: /#ff7f50(ff)?(?!\w)/gi,
|
||||
cornsilk: /#fff8dc(ff)?(?!\w)/gi,
|
||||
crimson: /#dc143c(ff)?(?!\w)/gi,
|
||||
cyan: /#00ffff(ff)?(?!\w)|#0ff(f)?(?!\w)/gi,
|
||||
darkblue: /#00008b(ff)?(?!\w)/gi,
|
||||
darkcyan: /#008b8b(ff)?(?!\w)/gi,
|
||||
darkgrey: /#a9a9a9(ff)?(?!\w)/gi,
|
||||
darkred: /#8b0000(ff)?(?!\w)/gi,
|
||||
deeppink: /#ff1493(ff)?(?!\w)/gi,
|
||||
dimgrey: /#696969(ff)?(?!\w)/gi,
|
||||
gold: /#ffd700(ff)?(?!\w)/gi,
|
||||
green: /#008000(ff)?(?!\w)/gi,
|
||||
grey: /#808080(ff)?(?!\w)/gi,
|
||||
honeydew: /#f0fff0(ff)?(?!\w)/gi,
|
||||
hotpink: /#ff69b4(ff)?(?!\w)/gi,
|
||||
indigo: /#4b0082(ff)?(?!\w)/gi,
|
||||
ivory: /#fffff0(ff)?(?!\w)/gi,
|
||||
khaki: /#f0e68c(ff)?(?!\w)/gi,
|
||||
lavender: /#e6e6fa(ff)?(?!\w)/gi,
|
||||
lime: /#00ff00(ff)?(?!\w)|#0f0(f)?(?!\w)/gi,
|
||||
linen: /#faf0e6(ff)?(?!\w)/gi,
|
||||
maroon: /#800000(ff)?(?!\w)/gi,
|
||||
moccasin: /#ffe4b5(ff)?(?!\w)/gi,
|
||||
navy: /#000080(ff)?(?!\w)/gi,
|
||||
oldlace: /#fdf5e6(ff)?(?!\w)/gi,
|
||||
olive: /#808000(ff)?(?!\w)/gi,
|
||||
orange: /#ffa500(ff)?(?!\w)/gi,
|
||||
orchid: /#da70d6(ff)?(?!\w)/gi,
|
||||
peru: /#cd853f(ff)?(?!\w)/gi,
|
||||
pink: /#ffc0cb(ff)?(?!\w)/gi,
|
||||
plum: /#dda0dd(ff)?(?!\w)/gi,
|
||||
purple: /#800080(ff)?(?!\w)/gi,
|
||||
red: /#ff0000(ff)?(?!\w)|#f00(f)?(?!\w)/gi,
|
||||
salmon: /#fa8072(ff)?(?!\w)/gi,
|
||||
seagreen: /#2e8b57(ff)?(?!\w)/gi,
|
||||
seashell: /#fff5ee(ff)?(?!\w)/gi,
|
||||
sienna: /#a0522d(ff)?(?!\w)/gi,
|
||||
silver: /#c0c0c0(ff)?(?!\w)/gi,
|
||||
skyblue: /#87ceeb(ff)?(?!\w)/gi,
|
||||
snow: /#fffafa(ff)?(?!\w)/gi,
|
||||
tan: /#d2b48c(ff)?(?!\w)/gi,
|
||||
teal: /#008080(ff)?(?!\w)/gi,
|
||||
thistle: /#d8bfd8(ff)?(?!\w)/gi,
|
||||
tomato: /#ff6347(ff)?(?!\w)/gi,
|
||||
violet: /#ee82ee(ff)?(?!\w)/gi,
|
||||
wheat: /#f5deb3(ff)?(?!\w)/gi,
|
||||
white: /#ffffff(ff)?(?!\w)|#fff(f)?(?!\w)/gi,
|
||||
};
|
||||
Reference in New Issue
Block a user