You've already forked dynamic-badges-action
🔀 Merge pull request #25 from runarberg/implement-direct-svg-badges
This commit is contained in:
@@ -11,7 +11,7 @@ inputs:
|
|||||||
description: 'The ID of the gist to use'
|
description: 'The ID of the gist to use'
|
||||||
required: true
|
required: true
|
||||||
filename:
|
filename:
|
||||||
description: 'The *.json filename of the badge data'
|
description: 'The *.json or *.svg filename of the badge data'
|
||||||
required: true
|
required: true
|
||||||
label:
|
label:
|
||||||
description: 'The left text of the badge'
|
description: 'The left text of the badge'
|
||||||
@@ -72,5 +72,5 @@ inputs:
|
|||||||
description: 'Lightness used by the color range feature. Defaults to 40.'
|
description: 'Lightness used by the color range feature. Defaults to 40.'
|
||||||
required: false
|
required: false
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node20'
|
||||||
main: 'index.js'
|
main: 'index.js'
|
||||||
|
|||||||
253
index.js
253
index.js
@@ -4,97 +4,82 @@
|
|||||||
// Copyright: (c) 2020 Simon Schneegans //
|
// Copyright: (c) 2020 Simon Schneegans //
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const core = require('@actions/core');
|
import core from '@actions/core';
|
||||||
const http = require('https');
|
import { makeBadge } from 'badge-maker';
|
||||||
|
|
||||||
// Performs an HTTP request and returns a Promise accordingly. See docs of
|
const gistUrl = new URL(
|
||||||
// http.request() for the available options.
|
core.getInput('gistID'),
|
||||||
function doRequest(options, data) {
|
'https://api.github.com/gists/'
|
||||||
return new Promise((resolve, reject) => {
|
);
|
||||||
const req = http.request(options, res => {
|
|
||||||
res.setEncoding('utf8');
|
|
||||||
let responseBody = '';
|
|
||||||
|
|
||||||
res.on('data', (chunk) => {
|
|
||||||
responseBody += chunk;
|
|
||||||
});
|
|
||||||
|
|
||||||
res.on('end', () => {
|
|
||||||
const {statusCode, statusMessage} = res;
|
|
||||||
resolve({statusCode, statusMessage, body: JSON.parse(responseBody)});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
req.on('error', (err) => {
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
req.write(data)
|
|
||||||
req.end();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// This uses the method above to update a gist with the given data. The user agent is
|
// This uses the method above to update a gist with the given data. The user agent is
|
||||||
// required as defined in https://developer.github.com/v3/#user-agent-required
|
// required as defined in https://developer.github.com/v3/#user-agent-required
|
||||||
function updateGist(data) {
|
async function updateGist(body) {
|
||||||
const updateGistOptions = {
|
const headers = new Headers([
|
||||||
host: 'api.github.com',
|
['Content-Type', 'application/json'],
|
||||||
path: '/gists/' + core.getInput('gistID'),
|
['Content-Length', body.length],
|
||||||
method: 'POST',
|
['User-Agent', 'Schneegans'],
|
||||||
headers: {
|
['Authorization', `token ${core.getInput('auth')}`],
|
||||||
'Content-Type': 'application/json',
|
]);
|
||||||
'Content-Length': data.length,
|
|
||||||
'User-Agent': 'Schneegans',
|
|
||||||
'Authorization': 'token ' + core.getInput('auth'),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
doRequest(updateGistOptions, data).then(res => {
|
const response = await fetch(gistUrl, {
|
||||||
if (res.statusCode < 200 || res.statusCode >= 400) {
|
method: 'POST',
|
||||||
core.setFailed(
|
headers,
|
||||||
'Failed to create gist, response status code: ' + res.statusCode +
|
body,
|
||||||
', status message: ' + res.statusMessage);
|
|
||||||
} else {
|
|
||||||
console.log('Success!');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.log(await response.text());
|
||||||
|
core.setFailed(
|
||||||
|
`Failed to create gist, response status code: ${response.status} ${response.statusText}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Success!');
|
||||||
}
|
}
|
||||||
|
|
||||||
// We wrap the entire action in a try / catch block so we can set it to "failed" if
|
// We wrap the entire action in a try / catch block so we can set it to "failed" if
|
||||||
// something goes wrong.
|
// something goes wrong.
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// This object will be stringified and uploaded to the gist. The schemaVersion, label
|
// This object will be stringified and uploaded to the gist. The schemaVersion, label
|
||||||
// and message attributes are always required. All others are optional and added to the
|
// and message attributes are always required. All others are optional and added to the
|
||||||
// content object only if they are given to the action.
|
// content object only if they are given to the action.
|
||||||
let content = {
|
let data = {
|
||||||
schemaVersion: 1,
|
|
||||||
label: core.getInput('label'),
|
label: core.getInput('label'),
|
||||||
message: core.getInput('message')
|
message: core.getInput('message'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filename = core.getInput('filename');
|
||||||
|
const isSvgFile = filename.endsWith('.svg');
|
||||||
|
|
||||||
|
if (!isSvgFile) {
|
||||||
|
data.schemaVersion = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Compute the message color based on the given inputs.
|
// Compute the message color based on the given inputs.
|
||||||
const color = core.getInput('color');
|
const color = core.getInput('color');
|
||||||
const valColorRange = core.getInput('valColorRange');
|
const valColorRange = core.getInput('valColorRange');
|
||||||
const minColorRange = core.getInput('minColorRange');
|
const minColorRange = core.getInput('minColorRange');
|
||||||
const maxColorRange = core.getInput('maxColorRange');
|
const maxColorRange = core.getInput('maxColorRange');
|
||||||
const invertColorRange = core.getInput('invertColorRange');
|
const invertColorRange = core.getInput('invertColorRange');
|
||||||
const colorRangeSaturation = core.getInput('colorRangeSaturation');
|
const colorRangeSaturation = core.getInput('colorRangeSaturation');
|
||||||
const colorRangeLightness = core.getInput('colorRangeLightness');
|
const colorRangeLightness = core.getInput('colorRangeLightness');
|
||||||
|
|
||||||
if (minColorRange != '' && maxColorRange != '' && valColorRange != '') {
|
if (minColorRange != '' && maxColorRange != '' && valColorRange != '') {
|
||||||
const max = parseFloat(maxColorRange);
|
const max = parseFloat(maxColorRange);
|
||||||
const min = parseFloat(minColorRange);
|
const min = parseFloat(minColorRange);
|
||||||
let val = parseFloat(valColorRange);
|
let val = parseFloat(valColorRange);
|
||||||
|
|
||||||
if (val < min) val = min;
|
if (val < min) val = min;
|
||||||
if (val > max) val = max;
|
if (val > max) val = max;
|
||||||
|
|
||||||
let hue = 0;
|
let hue = 0;
|
||||||
if (invertColorRange == '') {
|
if (invertColorRange == '') {
|
||||||
hue = Math.floor((val - min) / (max - min) * 120);
|
hue = Math.floor(((val - min) / (max - min)) * 120);
|
||||||
} else {
|
} else {
|
||||||
hue = Math.floor((max - val) / (max - min) * 120);
|
hue = Math.floor(((max - val) / (max - min)) * 120);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sat = 100;
|
let sat = 100;
|
||||||
@@ -107,116 +92,122 @@ try {
|
|||||||
lig = parseFloat(colorRangeLightness);
|
lig = parseFloat(colorRangeLightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
content.color = 'hsl(' + hue + ', ' + sat + '%, ' + lig + '%)';
|
data.color = 'hsl(' + hue + ', ' + sat + '%, ' + lig + '%)';
|
||||||
|
|
||||||
} else if (color != '') {
|
} else if (color != '') {
|
||||||
|
data.color = color;
|
||||||
content.color = color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all optional attributes and add them to the content object if given.
|
// Get all optional attributes and add them to the content object if given.
|
||||||
const labelColor = core.getInput('labelColor');
|
const labelColor = core.getInput('labelColor');
|
||||||
const isError = core.getInput('isError');
|
const isError = core.getInput('isError');
|
||||||
const namedLogo = core.getInput('namedLogo');
|
const namedLogo = core.getInput('namedLogo');
|
||||||
const logoSvg = core.getInput('logoSvg');
|
const logoSvg = core.getInput('logoSvg');
|
||||||
const logoColor = core.getInput('logoColor');
|
const logoColor = core.getInput('logoColor');
|
||||||
const logoWidth = core.getInput('logoWidth');
|
const logoWidth = core.getInput('logoWidth');
|
||||||
const logoPosition = core.getInput('logoPosition');
|
const logoPosition = core.getInput('logoPosition');
|
||||||
const style = core.getInput('style');
|
const style = core.getInput('style');
|
||||||
const cacheSeconds = core.getInput('cacheSeconds');
|
const cacheSeconds = core.getInput('cacheSeconds');
|
||||||
const filename = core.getInput('filename');
|
|
||||||
|
|
||||||
if (labelColor != '') {
|
if (labelColor != '') {
|
||||||
content.labelColor = labelColor;
|
data.labelColor = labelColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isError != '') {
|
if (!isSvgFile && isError != '') {
|
||||||
content.isError = isError;
|
data.isError = isError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (namedLogo != '') {
|
if (!isSvgFile && namedLogo != '') {
|
||||||
content.namedLogo = namedLogo;
|
data.namedLogo = namedLogo;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logoSvg != '') {
|
if (!isSvgFile && logoSvg != '') {
|
||||||
content.logoSvg = logoSvg;
|
data.logoSvg = logoSvg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logoColor != '') {
|
if (!isSvgFile && logoColor != '') {
|
||||||
content.logoColor = logoColor;
|
data.logoColor = logoColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logoWidth != '') {
|
if (!isSvgFile && logoWidth != '') {
|
||||||
content.logoWidth = parseInt(logoWidth);
|
data.logoWidth = parseInt(logoWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logoPosition != '') {
|
if (!isSvgFile && logoPosition != '') {
|
||||||
content.logoPosition = logoPosition;
|
data.logoPosition = logoPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style != '') {
|
if (style != '') {
|
||||||
content.style = style;
|
data.style = style;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cacheSeconds != '') {
|
if (!isSvgFile && cacheSeconds != '') {
|
||||||
content.cacheSeconds = parseInt(cacheSeconds);
|
data.cacheSeconds = parseInt(cacheSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
let content = '';
|
||||||
|
|
||||||
|
if (isSvgFile) {
|
||||||
|
content = makeBadge(data);
|
||||||
|
} else {
|
||||||
|
content = JSON.stringify({ content: data });
|
||||||
}
|
}
|
||||||
|
|
||||||
// For the POST request, the above content is set as file contents for the
|
// For the POST request, the above content is set as file contents for the
|
||||||
// given filename.
|
// given filename.
|
||||||
const request =
|
const body = JSON.stringify({ files: { [filename]: { content } } });
|
||||||
JSON.stringify({files: {[filename]: {content: JSON.stringify(content)}}});
|
|
||||||
|
|
||||||
// If "forceUpdate" is set to true, we can simply update the gist. If not, we have to
|
// If "forceUpdate" is set to true, we can simply update the gist. If not, we have to
|
||||||
// get the gist data and compare it to the new value before.
|
// get the gist data and compare it to the new value before.
|
||||||
if (core.getBooleanInput('forceUpdate')) {
|
if (core.getBooleanInput('forceUpdate')) {
|
||||||
updateGist(request);
|
updateGist(body);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Get the old gist.
|
// Get the old gist.
|
||||||
const getGistOptions = {
|
fetch(gistUrl, {
|
||||||
host: 'api.github.com',
|
|
||||||
path: '/gists/' + core.getInput('gistID'),
|
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: new Headers([
|
||||||
'Content-Type': 'application/json',
|
['Content-Type', 'application/json'],
|
||||||
'User-Agent': 'Schneegans',
|
['User-Agent', 'Schneegans'],
|
||||||
'Authorization': 'token ' + core.getInput('auth'),
|
['Authorization', `token ${core.getInput('auth')}`],
|
||||||
}
|
]),
|
||||||
};
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (!response.ok) {
|
||||||
|
// print the error, but don't fail the action.
|
||||||
|
console.log(
|
||||||
|
`Failed to get gist: ${response.status} ${response.statusText}`
|
||||||
|
);
|
||||||
|
response.text().then((text) => console.log(text));
|
||||||
|
|
||||||
doRequest(getGistOptions, JSON.stringify({})).then(oldGist => {
|
return {};
|
||||||
if (oldGist.statusCode < 200 || oldGist.statusCode >= 400) {
|
|
||||||
// print the error, but don't fail the action.
|
|
||||||
console.log(
|
|
||||||
'Failed to get gist, response status code: ' + oldGist.statusCode +
|
|
||||||
', status message: ' + oldGist.statusMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
let shouldUpdate = true;
|
|
||||||
|
|
||||||
if (oldGist && oldGist.body && oldGist.body.files && oldGist.body.files[filename]) {
|
|
||||||
const oldContent = oldGist.body.files[filename].content;
|
|
||||||
|
|
||||||
if (oldContent === JSON.stringify(content)) {
|
|
||||||
console.log(`Content did not change, not updating gist at ${filename}.`);
|
|
||||||
shouldUpdate = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldUpdate) {
|
|
||||||
if (oldGist.body.files[filename]) {
|
|
||||||
console.log(`Content changed, updating gist at ${filename}.`);
|
|
||||||
} else {
|
|
||||||
console.log(`Content didn't exist, creating gist at ${filename}.`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGist(request);
|
return response.json();
|
||||||
}
|
})
|
||||||
});
|
.then((oldGist) => {
|
||||||
|
let shouldUpdate = true;
|
||||||
|
|
||||||
|
if (oldGist?.body?.files?.[filename]) {
|
||||||
|
const oldContent = oldGist.body.files[filename].content;
|
||||||
|
|
||||||
|
if (oldContent === content) {
|
||||||
|
console.log(
|
||||||
|
`Content did not change, not updating gist at ${filename}.`
|
||||||
|
);
|
||||||
|
shouldUpdate = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldUpdate) {
|
||||||
|
if (oldGist?.body?.files?.[filename]) {
|
||||||
|
console.log(`Content changed, updating gist at ${filename}.`);
|
||||||
|
} else {
|
||||||
|
console.log(`Content didn't exist, creating gist at ${filename}.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateGist(body);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(error);
|
core.setFailed(error);
|
||||||
}
|
}
|
||||||
|
|||||||
1
node_modules/.bin/badge
generated
vendored
Symbolic link
1
node_modules/.bin/badge
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../badge-maker/lib/badge-cli.js
|
||||||
64
node_modules/.package-lock.json
generated
vendored
64
node_modules/.package-lock.json
generated
vendored
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "dynamic-badges-action",
|
"name": "dynamic-badges-action",
|
||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"node_modules/@actions/core": {
|
"node_modules/@actions/core": {
|
||||||
@@ -21,6 +21,68 @@
|
|||||||
"tunnel": "^0.0.6"
|
"tunnel": "^0.0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/anafanafo": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/anafanafo/-/anafanafo-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-Nlfq7NC4AOkTJerWRIZcOAiMNtIDVIGWGvQ98O7Jl6Kr2Dk0dX5u4MqN778kSRTy5KRqchpLdF2RtLFEz9FVkQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"char-width-table-consumer": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/badge-maker": {
|
||||||
|
"version": "3.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/badge-maker/-/badge-maker-3.3.1.tgz",
|
||||||
|
"integrity": "sha512-OO/PS7Zg2E6qaUWzHEHt21Q5VjcFBAJVA8ztgT/fIdSZFBUwoyeo0ZhA6V5tUM8Vcjq8DJl6jfGhpjESssyqMQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"anafanafo": "2.0.0",
|
||||||
|
"css-color-converter": "^2.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"badge": "lib/badge-cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10",
|
||||||
|
"npm": ">= 5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/binary-search": {
|
||||||
|
"version": "1.3.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/binary-search/-/binary-search-1.3.6.tgz",
|
||||||
|
"integrity": "sha512-nbE1WxOTTrUWIfsfZ4aHGYu5DOuNkbxGokjV6Z2kxfJK3uaAb8zNK1muzOeipoLHZjInT4Br88BHpzevc681xA=="
|
||||||
|
},
|
||||||
|
"node_modules/char-width-table-consumer": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/char-width-table-consumer/-/char-width-table-consumer-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-Fz4UD0LBpxPgL9i29CJ5O4KANwaMnX/OhhbxzvNa332h+9+nRKyeuLw4wA51lt/ex67+/AdsoBQJF3kgX2feYQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"binary-search": "^1.3.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/color-convert": {
|
||||||
|
"version": "0.5.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-0.5.3.tgz",
|
||||||
|
"integrity": "sha512-RwBeO/B/vZR3dfKL1ye/vx8MHZ40ugzpyfeVG5GsiuGnrlMWe2o8wxBbLCpw9CsxV+wHuzYlCiWnybrIA0ling=="
|
||||||
|
},
|
||||||
|
"node_modules/color-name": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
||||||
|
},
|
||||||
|
"node_modules/css-color-converter": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/css-color-converter/-/css-color-converter-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-oLIG2soZz3wcC3aAl/7Us5RS8Hvvc6I8G8LniF/qfMmrm7fIKQ8RIDDRZeKyGL2SrWfNqYspuLShbnjBMVWm8g==",
|
||||||
|
"dependencies": {
|
||||||
|
"color-convert": "^0.5.2",
|
||||||
|
"color-name": "^1.1.4",
|
||||||
|
"css-unit-converter": "^1.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/css-unit-converter": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/css-unit-converter/-/css-unit-converter-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-IiJwMC8rdZE0+xiEZHeru6YoONC4rfPMqGm2W85jMIbkFvv5nFTwJVFHam2eFrN6txmoUYFAFXiv8ICVeTO0MA=="
|
||||||
|
},
|
||||||
"node_modules/tunnel": {
|
"node_modules/tunnel": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
||||||
|
|||||||
43
node_modules/anafanafo/CHANGELOG.md
generated
vendored
Normal file
43
node_modules/anafanafo/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2.0.0 – Oct 15, 2020
|
||||||
|
|
||||||
|
Same as 2.0.0-beta.1.
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
- Support the font variants used by Shields:
|
||||||
|
- 10px Verdana
|
||||||
|
- bold 10px Verdana
|
||||||
|
- 11px Verdana
|
||||||
|
- bold 11px Helvetica
|
||||||
|
|
||||||
|
## 2.0.0-beta.1 – Oct 11, 2020
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
- Support the font variants used by Shields:
|
||||||
|
- 10px Verdana
|
||||||
|
- bold 10px Verdana
|
||||||
|
- 11px Verdana
|
||||||
|
- bold 11px Helvetica
|
||||||
|
|
||||||
|
## 2.0.0-beta.0 – Oct 11, 2020
|
||||||
|
|
||||||
|
### BREAKING CHANGES
|
||||||
|
|
||||||
|
- Support 10px and 11px Verdana, in normal and bold.
|
||||||
|
|
||||||
|
## 1.0.0 – Apr 12, 2018
|
||||||
|
|
||||||
|
- Update dependencies.
|
||||||
|
- Stable API.
|
||||||
|
|
||||||
|
## 0.1.1 – Nov 15, 2018
|
||||||
|
|
||||||
|
- Require the JSON file (instead of `loadSync`-ing it) to play well with
|
||||||
|
module bundlers.
|
||||||
|
|
||||||
|
## 0.1.0 – Nov 13, 2018
|
||||||
|
|
||||||
|
Initial release.
|
||||||
21
node_modules/anafanafo/LICENSE
generated
vendored
Normal file
21
node_modules/anafanafo/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 Metabolize LLC
|
||||||
|
|
||||||
|
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.
|
||||||
40
node_modules/anafanafo/README.md
generated
vendored
Normal file
40
node_modules/anafanafo/README.md
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# anafanafo
|
||||||
|
|
||||||
|
[][npm]
|
||||||
|
[][npm]
|
||||||
|
[][build]
|
||||||
|
[][bundlephobia]
|
||||||
|
[][prettier]
|
||||||
|
[][lerna]
|
||||||
|
|
||||||
|
[npm]: https://npmjs.com/anafanafo
|
||||||
|
[build]: https://circleci.com/gh/metabolize/anafanafo/tree/main
|
||||||
|
[bundlephobia]: https://bundlephobia.com/result?p=anafanafo
|
||||||
|
[prettier]: https://prettier.io/
|
||||||
|
[lerna]: https://lernajs.io/
|
||||||
|
|
||||||
|
Efficiently compute text width in Verdana and Helvetica using
|
||||||
|
[char-width-table-consumer][] and lookup tables.
|
||||||
|
|
||||||
|
Built with [Shields][] in mind.
|
||||||
|
|
||||||
|
(And because Verdana always makes me think of [this][the name game].)
|
||||||
|
|
||||||
|
[char-width-table-consumer]: https://www.npmjs.com/package/char-width-table-consumer
|
||||||
|
[shields]: https://github.com/badges/shields/
|
||||||
|
[the name game]: https://www.youtube.com/watch?v=5MJLi5_dyn0
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const anafanafo = require('anafanafo')
|
||||||
|
|
||||||
|
// Supports '11px Verdana', '10px Verdana', 'bold 10px Verdana', and 'bold 11px Helvetica'.
|
||||||
|
const width = anafanafo('Shirley Shirley', { font: '11px Verdana' })
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
All rights to Verdana are owned by Microsoft Corp.
|
||||||
|
|
||||||
|
The remainder of this project is licensed under the MIT license.
|
||||||
1
node_modules/anafanafo/data/helvetica-11px-bold.json
generated
vendored
Normal file
1
node_modules/anafanafo/data/helvetica-11px-bold.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/anafanafo/data/verdana-10px-bold.json
generated
vendored
Normal file
1
node_modules/anafanafo/data/verdana-10px-bold.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/anafanafo/data/verdana-10px-normal.json
generated
vendored
Normal file
1
node_modules/anafanafo/data/verdana-10px-normal.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/anafanafo/data/verdana-11px-normal.json
generated
vendored
Normal file
1
node_modules/anafanafo/data/verdana-11px-normal.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
22
node_modules/anafanafo/index.js
generated
vendored
Normal file
22
node_modules/anafanafo/index.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const { createConsumer } = require('char-width-table-consumer')
|
||||||
|
|
||||||
|
const consumers = {
|
||||||
|
'10px Verdana': createConsumer(require('./data/verdana-10px-normal.json')),
|
||||||
|
'bold 10px Verdana': createConsumer(require('./data/verdana-10px-bold.json')),
|
||||||
|
'11px Verdana': createConsumer(require('./data/verdana-11px-normal.json')),
|
||||||
|
'bold 11px Helvetica': createConsumer(
|
||||||
|
require('./data/helvetica-11px-bold.json')
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = function measure(text, { font, ...rest }) {
|
||||||
|
const consumer = consumers[font]
|
||||||
|
if (!consumer) {
|
||||||
|
throw Error(
|
||||||
|
`Unknown font "${font}", expected ${Object.keys(consumers).join(', ')}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return consumer.widthOf(text, { ...rest })
|
||||||
|
}
|
||||||
18
node_modules/anafanafo/package.json
generated
vendored
Normal file
18
node_modules/anafanafo/package.json
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "anafanafo",
|
||||||
|
"version": "2.0.0",
|
||||||
|
"repository": "metabolize/anafanafo",
|
||||||
|
"description": "Compute text width in Verdana",
|
||||||
|
"scripts": {
|
||||||
|
"test": "../../node_modules/.bin/mocha test.js"
|
||||||
|
},
|
||||||
|
"author": "Metabolize",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"char-width-table-consumer": "^1.0.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js",
|
||||||
|
"data/*.json"
|
||||||
|
]
|
||||||
|
}
|
||||||
277
node_modules/badge-maker/CHANGELOG.md
generated
vendored
Normal file
277
node_modules/badge-maker/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 3.3.1
|
||||||
|
|
||||||
|
- Improve font measuring in for-the-badge and social styles
|
||||||
|
- Make for-the-badge letter spacing more predictable
|
||||||
|
|
||||||
|
## 3.3.0
|
||||||
|
|
||||||
|
- Readability improvements: a dark font color is automatically used when the badge's background is too light. For example: 
|
||||||
|
- Better CSS color compliance: thanks to a switch from _is-css-color_ to _[css-color-converter](https://www.npmjs.com/package/css-color-converter)_, you can use a wider range of color formats from the latest CSS specification, for example `rgb(0 255 0)`
|
||||||
|
- Less dependencies: _badge-maker_ no longer depends on _camelcase_
|
||||||
|
|
||||||
|
## 3.2.0
|
||||||
|
|
||||||
|
- Accessibility improvements: Help users of assistive technologies to read the badges when used inline
|
||||||
|
|
||||||
|
## 3.1.0
|
||||||
|
|
||||||
|
- Add TypeScript definitions
|
||||||
|
|
||||||
|
## 3.0.1
|
||||||
|
|
||||||
|
- Fix missing dependency
|
||||||
|
|
||||||
|
## 3.0.0
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
- Dropped support for node < 10
|
||||||
|
- Package name has changed to `badge-maker` and moved to https://www.npmjs.com/package/badge-maker
|
||||||
|
- `BadgeFactory` class is removed and replaced by `makeBadge()` function.
|
||||||
|
- Deprecated parameters have been removed. In version 2.2.0 the `colorA`, `colorB` and `colorscheme` params were deprecated. In version 3.0.0 these have been removed.
|
||||||
|
- Only SVG output format is now provided. JSON format has been dropped and the `format` key has been removed.
|
||||||
|
- The `text` array has been replaced by `label` and `message` keys.
|
||||||
|
- The `template` key has been renamed `style`.
|
||||||
|
To upgrade from v2.1.1, change your code from:
|
||||||
|
```js
|
||||||
|
const { BadgeFactory } = require('gh-badges')
|
||||||
|
const bf = new BadgeFactory()
|
||||||
|
const svg = bf.create({
|
||||||
|
text: ['build', 'passed'],
|
||||||
|
format: 'svg',
|
||||||
|
template: 'flat-square',
|
||||||
|
})
|
||||||
|
```
|
||||||
|
to:
|
||||||
|
```js
|
||||||
|
const { makeBadge } = require('badge-maker')
|
||||||
|
const svg = makeBadge({
|
||||||
|
label: 'build',
|
||||||
|
message: 'passed',
|
||||||
|
style: 'flat-square',
|
||||||
|
})
|
||||||
|
```
|
||||||
|
- `ValidationError` had been added and inputs are now validated. In previous releases, invalid inputs would be discarded and replaced with defaults. For example, in 2.2.1
|
||||||
|
```js
|
||||||
|
const { BadgeFactory } = require('gh-badges')
|
||||||
|
const bf = new BadgeFactory()
|
||||||
|
const svg = bf.create({
|
||||||
|
text: ['build', 'passed'],
|
||||||
|
template: 'some invalid value',
|
||||||
|
})
|
||||||
|
```
|
||||||
|
would generate an SVG badge. In version >=3
|
||||||
|
```js
|
||||||
|
const { makeBadge } = require('badge-maker')
|
||||||
|
const svg = makeBadge({
|
||||||
|
label: 'build',
|
||||||
|
message: 'passed',
|
||||||
|
style: 'some invalid value',
|
||||||
|
})
|
||||||
|
```
|
||||||
|
will throw a `ValidationError`.
|
||||||
|
- Raster support has been removed from the CLI. It will now only output SVG. On the console, the output of `badge` can be piped to a utility like [imagemagick](https://imagemagick.org/script/command-line-processing.php). If you were previously using
|
||||||
|
```sh
|
||||||
|
badge build passed :green .gif
|
||||||
|
```
|
||||||
|
this could be replaced by
|
||||||
|
```sh
|
||||||
|
badge build passed :green | magick svg:- gif:-
|
||||||
|
```
|
||||||
|
|
||||||
|
### Security
|
||||||
|
|
||||||
|
- Removed dependency on doT library which has known vulnerabilities.
|
||||||
|
|
||||||
|
## 2.2.1 - 2019-05-30
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- Escape logos to prevent XSS vulnerability
|
||||||
|
- Update docblock for BadgeFactory.create()
|
||||||
|
|
||||||
|
## 2.2.0 - 2019-05-29
|
||||||
|
|
||||||
|
### Deprecations
|
||||||
|
|
||||||
|
- `labelColor` and `color` are now the recommended attribute names for label color and message color.
|
||||||
|
|
||||||
|
- `colorA` (now an alias for `labelColor`),
|
||||||
|
- `colorB` (now an alias for `color`) and
|
||||||
|
- `colorscheme` (now an alias for `color`)
|
||||||
|
|
||||||
|
are now deprecated and will be removed in some future release.
|
||||||
|
|
||||||
|
### New Features
|
||||||
|
|
||||||
|
- Semantic color aliases. Add support for:
|
||||||
|
- 
|
||||||
|
- 
|
||||||
|
- 
|
||||||
|
- 
|
||||||
|
- 
|
||||||
|
- Add directory field to package.json (to help tools find this package in the repo)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- Prevent bad letter spacing when whitespace surrounds badge text
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
- Bump anafanafo
|
||||||
|
- Use caret instead of tilde for dependencies
|
||||||
|
|
||||||
|
### Internals
|
||||||
|
|
||||||
|
- Generate JSON badges without using a template
|
||||||
|
- Refactoring
|
||||||
|
- Testing improvements
|
||||||
|
|
||||||
|
### Node support
|
||||||
|
|
||||||
|
- Declare support for all currently maintained Node versions
|
||||||
|
- Explicitly test on all supported versions
|
||||||
|
|
||||||
|
## 2.1.0 - 2018-11-18
|
||||||
|
|
||||||
|
gh-badges v2.1.0 implements a new text width measurer which uses a lookup table, removing the dependency
|
||||||
|
on PDFKit. It is no longer necessary to provide a local copy of Verdana for accurate text width computation.
|
||||||
|
|
||||||
|
As such, the `fontPath` and `precomputeWidths` parameters are now deprecated. The recommended call to create an instance of `BadgeFactory` is now
|
||||||
|
|
||||||
|
```js
|
||||||
|
const bf = new BadgeFactory()
|
||||||
|
```
|
||||||
|
|
||||||
|
For backwards compatibility you can still construct an instance of `BadgeFactory` with a call like
|
||||||
|
|
||||||
|
```js
|
||||||
|
const bf = new BadgeFactory({
|
||||||
|
fontPath: '/path/to/Verdana.ttf',
|
||||||
|
precomputeWidths: true,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
However, the function will issue a warning.
|
||||||
|
|
||||||
|
To clear the warning, change the code to:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const bf = new BadgeFactory()
|
||||||
|
```
|
||||||
|
|
||||||
|
These arguments will be removed in a future release.
|
||||||
|
|
||||||
|
To upgrade from v1.3.0, change your code from:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const badge = require('gh-badges')
|
||||||
|
|
||||||
|
const format = {
|
||||||
|
text: ['build', 'passed'],
|
||||||
|
colorscheme: 'green',
|
||||||
|
template: 'flat',
|
||||||
|
}
|
||||||
|
|
||||||
|
badge.loadFont('/path/to/Verdana.ttf', err => {
|
||||||
|
badge(format, (svg, err) => {
|
||||||
|
// svg is a string containing your badge
|
||||||
|
})
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
to:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { BadgeFactory } = require('gh-badges')
|
||||||
|
|
||||||
|
const bf = new BadgeFactory()
|
||||||
|
|
||||||
|
const format = {
|
||||||
|
text: ['build', 'passed'],
|
||||||
|
colorscheme: 'green',
|
||||||
|
template: 'flat',
|
||||||
|
}
|
||||||
|
|
||||||
|
const svg = bf.create(format)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Other changes in this release:
|
||||||
|
|
||||||
|
- Remove unnecessary dependencies
|
||||||
|
- Documentation improvements
|
||||||
|
|
||||||
|
## 2.0.0 - 2018-11-09
|
||||||
|
|
||||||
|
gh-badges v2.0.0 declares a new public interface which is synchronous.
|
||||||
|
If your version 1.3.0 code looked like this:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const badge = require('gh-badges')
|
||||||
|
|
||||||
|
const format = {
|
||||||
|
text: ['build', 'passed'],
|
||||||
|
colorscheme: 'green',
|
||||||
|
template: 'flat',
|
||||||
|
}
|
||||||
|
|
||||||
|
badge.loadFont('/path/to/Verdana.ttf', err => {
|
||||||
|
badge(format, (svg, err) => {
|
||||||
|
// svg is a string containing your badge
|
||||||
|
})
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
To upgrade to version 2.0.0, refactor you code to:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { BadgeFactory } = require('gh-badges')
|
||||||
|
|
||||||
|
const bf = new BadgeFactory({ fontPath: '/path/to/Verdana.ttf' })
|
||||||
|
|
||||||
|
const format = {
|
||||||
|
text: ['build', 'passed'],
|
||||||
|
colorscheme: 'green',
|
||||||
|
template: 'flat',
|
||||||
|
}
|
||||||
|
|
||||||
|
const svg = bf.create(format)
|
||||||
|
```
|
||||||
|
|
||||||
|
You can generate badges without a copy of Verdana, however font width computation is approximate and badges may be distorted.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const bf = new BadgeFactory({ fallbackFontPath: 'Helvetica' })
|
||||||
|
```
|
||||||
|
|
||||||
|
## 1.3.0 - 2016-09-07
|
||||||
|
|
||||||
|
Add support for optionally specifying the path to `Verdana.ttf`. In earlier versions, the file needed to be in the directory containing Shields.
|
||||||
|
|
||||||
|
Without font path:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const badge = require('gh-badges')
|
||||||
|
|
||||||
|
badge({ text: ['build', 'passed'], colorscheme: 'green' }, (svg, err) => {
|
||||||
|
// svg is a string containing your badge
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
With font path:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const badge = require('gh-badges')
|
||||||
|
|
||||||
|
// Optional step, to have accurate text width computation.
|
||||||
|
badge.loadFont('/path/to/Verdana.ttf', err => {
|
||||||
|
badge(
|
||||||
|
{ text: ['build', 'passed'], colorscheme: 'green', template: 'flat' },
|
||||||
|
(svg, err) => {
|
||||||
|
// svg is a string containing your badge
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
```
|
||||||
116
node_modules/badge-maker/LICENSE
generated
vendored
Normal file
116
node_modules/badge-maker/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
CC0 1.0 Universal
|
||||||
|
|
||||||
|
Statement of Purpose
|
||||||
|
|
||||||
|
The laws of most jurisdictions throughout the world automatically confer
|
||||||
|
exclusive Copyright and Related Rights (defined below) upon the creator and
|
||||||
|
subsequent owner(s) (each and all, an "owner") of an original work of
|
||||||
|
authorship and/or a database (each, a "Work").
|
||||||
|
|
||||||
|
Certain owners wish to permanently relinquish those rights to a Work for the
|
||||||
|
purpose of contributing to a commons of creative, cultural and scientific
|
||||||
|
works ("Commons") that the public can reliably and without fear of later
|
||||||
|
claims of infringement build upon, modify, incorporate in other works, reuse
|
||||||
|
and redistribute as freely as possible in any form whatsoever and for any
|
||||||
|
purposes, including without limitation commercial purposes. These owners may
|
||||||
|
contribute to the Commons to promote the ideal of a free culture and the
|
||||||
|
further production of creative, cultural and scientific works, or to gain
|
||||||
|
reputation or greater distribution for their Work in part through the use and
|
||||||
|
efforts of others.
|
||||||
|
|
||||||
|
For these and/or other purposes and motivations, and without any expectation
|
||||||
|
of additional consideration or compensation, the person associating CC0 with a
|
||||||
|
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
||||||
|
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
||||||
|
and publicly distribute the Work under its terms, with knowledge of his or her
|
||||||
|
Copyright and Related Rights in the Work and the meaning and intended legal
|
||||||
|
effect of CC0 on those rights.
|
||||||
|
|
||||||
|
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||||
|
protected by copyright and related or neighboring rights ("Copyright and
|
||||||
|
Related Rights"). Copyright and Related Rights include, but are not limited
|
||||||
|
to, the following:
|
||||||
|
|
||||||
|
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
||||||
|
and translate a Work;
|
||||||
|
|
||||||
|
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||||
|
|
||||||
|
iii. publicity and privacy rights pertaining to a person's image or likeness
|
||||||
|
depicted in a Work;
|
||||||
|
|
||||||
|
iv. rights protecting against unfair competition in regards to a Work,
|
||||||
|
subject to the limitations in paragraph 4(a), below;
|
||||||
|
|
||||||
|
v. rights protecting the extraction, dissemination, use and reuse of data in
|
||||||
|
a Work;
|
||||||
|
|
||||||
|
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||||
|
European Parliament and of the Council of 11 March 1996 on the legal
|
||||||
|
protection of databases, and under any national implementation thereof,
|
||||||
|
including any amended or successor version of such directive); and
|
||||||
|
|
||||||
|
vii. other similar, equivalent or corresponding rights throughout the world
|
||||||
|
based on applicable law or treaty, and any national implementations thereof.
|
||||||
|
|
||||||
|
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
||||||
|
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
||||||
|
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
||||||
|
and Related Rights and associated claims and causes of action, whether now
|
||||||
|
known or unknown (including existing as well as future claims and causes of
|
||||||
|
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
||||||
|
duration provided by applicable law or treaty (including future time
|
||||||
|
extensions), (iii) in any current or future medium and for any number of
|
||||||
|
copies, and (iv) for any purpose whatsoever, including without limitation
|
||||||
|
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
||||||
|
the Waiver for the benefit of each member of the public at large and to the
|
||||||
|
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
||||||
|
shall not be subject to revocation, rescission, cancellation, termination, or
|
||||||
|
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
||||||
|
by the public as contemplated by Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
3. Public License Fallback. Should any part of the Waiver for any reason be
|
||||||
|
judged legally invalid or ineffective under applicable law, then the Waiver
|
||||||
|
shall be preserved to the maximum extent permitted taking into account
|
||||||
|
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
||||||
|
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
||||||
|
non transferable, non sublicensable, non exclusive, irrevocable and
|
||||||
|
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
||||||
|
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
||||||
|
provided by applicable law or treaty (including future time extensions), (iii)
|
||||||
|
in any current or future medium and for any number of copies, and (iv) for any
|
||||||
|
purpose whatsoever, including without limitation commercial, advertising or
|
||||||
|
promotional purposes (the "License"). The License shall be deemed effective as
|
||||||
|
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
||||||
|
License for any reason be judged legally invalid or ineffective under
|
||||||
|
applicable law, such partial invalidity or ineffectiveness shall not
|
||||||
|
invalidate the remainder of the License, and in such case Affirmer hereby
|
||||||
|
affirms that he or she will not (i) exercise any of his or her remaining
|
||||||
|
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
||||||
|
and causes of action with respect to the Work, in either case contrary to
|
||||||
|
Affirmer's express Statement of Purpose.
|
||||||
|
|
||||||
|
4. Limitations and Disclaimers.
|
||||||
|
|
||||||
|
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||||
|
surrendered, licensed or otherwise affected by this document.
|
||||||
|
|
||||||
|
b. Affirmer offers the Work as-is and makes no representations or warranties
|
||||||
|
of any kind concerning the Work, express, implied, statutory or otherwise,
|
||||||
|
including without limitation warranties of title, merchantability, fitness
|
||||||
|
for a particular purpose, non infringement, or the absence of latent or
|
||||||
|
other defects, accuracy, or the present or absence of errors, whether or not
|
||||||
|
discoverable, all to the greatest extent permissible under applicable law.
|
||||||
|
|
||||||
|
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||||
|
that may apply to the Work or any use thereof, including without limitation
|
||||||
|
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
||||||
|
disclaims responsibility for obtaining any necessary consents, permissions
|
||||||
|
or other rights required for any use of the Work.
|
||||||
|
|
||||||
|
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||||
|
party to this document and has no duty or obligation with respect to this
|
||||||
|
CC0 or use of the Work.
|
||||||
|
|
||||||
|
For more information, please see
|
||||||
|
<http://creativecommons.org/publicdomain/zero/1.0/>
|
||||||
142
node_modules/badge-maker/README.md
generated
vendored
Normal file
142
node_modules/badge-maker/README.md
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
# badge-maker
|
||||||
|
|
||||||
|
[](https://npmjs.org/package/badge-maker)
|
||||||
|
[](https://npmjs.org/package/badge-maker)
|
||||||
|
[](https://npmjs.org/package/badge-maker)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install badge-maker
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### On the console
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install -g badge-maker
|
||||||
|
badge build passed :green > mybadge.svg
|
||||||
|
```
|
||||||
|
|
||||||
|
### As a library
|
||||||
|
|
||||||
|
With CommonJS in JavaScript,
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { makeBadge, ValidationError } = require('badge-maker')
|
||||||
|
```
|
||||||
|
|
||||||
|
With ESM or TypeScript,
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { makeBadge, ValidationError } from 'badge-maker'
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
const format = {
|
||||||
|
label: 'build',
|
||||||
|
message: 'passed',
|
||||||
|
color: 'green',
|
||||||
|
}
|
||||||
|
|
||||||
|
const svg = makeBadge(format)
|
||||||
|
console.log(svg) // <svg...
|
||||||
|
|
||||||
|
try {
|
||||||
|
makeBadge({})
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e) // ValidationError: Field `message` is required
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Node version support
|
||||||
|
|
||||||
|
The latest version of badge-maker supports all currently maintained Node
|
||||||
|
versions. See the [Node Release Schedule][].
|
||||||
|
|
||||||
|
[node release schedule]: https://github.com/nodejs/Release#release-schedule
|
||||||
|
|
||||||
|
## Format
|
||||||
|
|
||||||
|
The format is the following:
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
label: 'build', // (Optional) Badge label
|
||||||
|
message: 'passed', // (Required) Badge message
|
||||||
|
labelColor: '#555', // (Optional) Label color
|
||||||
|
color: '#4c1', // (Optional) Message color
|
||||||
|
|
||||||
|
// (Optional) One of: 'plastic', 'flat', 'flat-square', 'for-the-badge' or 'social'
|
||||||
|
// Each offers a different visual design.
|
||||||
|
style: 'flat',
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Colors
|
||||||
|
|
||||||
|
There are three ways to specify `color` and `labelColor`:
|
||||||
|
|
||||||
|
1. One of the [Shields named colors](./lib/color.js):
|
||||||
|
|
||||||
|
- ![][brightgreen]
|
||||||
|
- ![][green]
|
||||||
|
- ![][yellow]
|
||||||
|
- ![][yellowgreen]
|
||||||
|
- ![][orange]
|
||||||
|
- ![][red]
|
||||||
|
- ![][blue]
|
||||||
|
- ![][grey] ![][gray] – the default `labelColor`
|
||||||
|
- ![][lightgrey] ![][lightgray] – the default `color`
|
||||||
|
|
||||||
|
- ![][success]
|
||||||
|
- ![][important]
|
||||||
|
- ![][critical]
|
||||||
|
- ![][informational]
|
||||||
|
- ![][inactive] – the default `color`
|
||||||
|
|
||||||
|
2. A three- or six-character hex color, optionally prefixed with `#`:
|
||||||
|
|
||||||
|
- ![][9cf]
|
||||||
|
- ![][#007fff]
|
||||||
|
- etc.
|
||||||
|
|
||||||
|
3. [Any valid CSS color][css color], e.g.
|
||||||
|
|
||||||
|
- `rgb(...)`, `rgba(...)`
|
||||||
|
- `hsl(...)`, `hsla(...)`
|
||||||
|
- ![][aqua] ![][fuchsia] ![][lightslategray] etc.
|
||||||
|
|
||||||
|
[brightgreen]: https://img.shields.io/badge/brightgreen-brightgreen.svg
|
||||||
|
[success]: https://img.shields.io/badge/success-success.svg
|
||||||
|
[green]: https://img.shields.io/badge/green-green.svg
|
||||||
|
[yellow]: https://img.shields.io/badge/yellow-yellow.svg
|
||||||
|
[yellowgreen]: https://img.shields.io/badge/yellowgreen-yellowgreen.svg
|
||||||
|
[orange]: https://img.shields.io/badge/orange-orange.svg
|
||||||
|
[important]: https://img.shields.io/badge/important-important.svg
|
||||||
|
[red]: https://img.shields.io/badge/red-red.svg
|
||||||
|
[critical]: https://img.shields.io/badge/critical-critical.svg
|
||||||
|
[blue]: https://img.shields.io/badge/blue-blue.svg
|
||||||
|
[informational]: https://img.shields.io/badge/informational-informational.svg
|
||||||
|
[grey]: https://img.shields.io/badge/grey-grey.svg
|
||||||
|
[gray]: https://img.shields.io/badge/gray-gray.svg
|
||||||
|
[lightgrey]: https://img.shields.io/badge/lightgrey-lightgrey.svg
|
||||||
|
[lightgray]: https://img.shields.io/badge/lightgray-lightgray.svg
|
||||||
|
[inactive]: https://img.shields.io/badge/inactive-inactive.svg
|
||||||
|
[9cf]: https://img.shields.io/badge/9cf-9cf.svg
|
||||||
|
[#007fff]: https://img.shields.io/badge/%23007fff-007fff.svg
|
||||||
|
[aqua]: https://img.shields.io/badge/aqua-aqua.svg
|
||||||
|
[fuchsia]: https://img.shields.io/badge/fuchsia-fuchsia.svg
|
||||||
|
[lightslategray]: https://img.shields.io/badge/lightslategray-lightslategray.svg
|
||||||
|
[css color]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
|
||||||
|
[css/svg color]: http://www.w3.org/TR/SVG/types.html#DataTypeColor
|
||||||
|
|
||||||
|
## Raster Formats
|
||||||
|
|
||||||
|
Conversion to raster formats is no longer directly supported. In javascript
|
||||||
|
code, SVG badges can be converted to raster formats using a library like
|
||||||
|
[gm](https://www.npmjs.com/package/gm). On the console, the output of `badge`
|
||||||
|
can be piped to a utility like
|
||||||
|
[imagemagick](https://imagemagick.org/script/command-line-processing.php)
|
||||||
|
e.g: `badge build passed :green | magick svg:- gif:-`.
|
||||||
11
node_modules/badge-maker/index.d.ts
generated
vendored
Normal file
11
node_modules/badge-maker/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
interface Format {
|
||||||
|
label?: string
|
||||||
|
message: string
|
||||||
|
labelColor?: string
|
||||||
|
color?: string
|
||||||
|
style?: 'plastic' | 'flat' | 'flat-square' | 'for-the-badge' | 'social'
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare class ValidationError extends Error {}
|
||||||
|
|
||||||
|
export declare function makeBadge(format: Format): string
|
||||||
65
node_modules/badge-maker/lib/badge-cli.js
generated
vendored
Executable file
65
node_modules/badge-maker/lib/badge-cli.js
generated
vendored
Executable file
@@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const { namedColors } = require('./color')
|
||||||
|
const { makeBadge } = require('./index')
|
||||||
|
|
||||||
|
if (process.argv.length < 4) {
|
||||||
|
console.log('Usage: badge label message [:color] [@style]')
|
||||||
|
console.log('Or: badge label message color [labelColor] [@style]')
|
||||||
|
console.log()
|
||||||
|
console.log(' color, labelColor:')
|
||||||
|
console.log(` one of ${Object.keys(namedColors).join(', ')}.`)
|
||||||
|
console.log(' #xxx (three hex digits)')
|
||||||
|
console.log(' #xxxxxx (six hex digits)')
|
||||||
|
console.log(' color (CSS color)')
|
||||||
|
console.log()
|
||||||
|
console.log('Eg: badge cactus grown :green @flat')
|
||||||
|
console.log()
|
||||||
|
process.exit()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find a format specifier.
|
||||||
|
let style = ''
|
||||||
|
for (let i = 4; i < process.argv.length; i++) {
|
||||||
|
if (process.argv[i][0] === '@') {
|
||||||
|
style = process.argv[i].slice(1)
|
||||||
|
process.argv.splice(i, 1)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const label = process.argv[2]
|
||||||
|
const message = process.argv[3]
|
||||||
|
let color = process.argv[4] || ':green'
|
||||||
|
const labelColor = process.argv[5]
|
||||||
|
|
||||||
|
const badgeData = { label, message }
|
||||||
|
if (style) {
|
||||||
|
badgeData.style = style
|
||||||
|
}
|
||||||
|
|
||||||
|
if (color[0] === ':') {
|
||||||
|
color = color.slice(1)
|
||||||
|
if (namedColors[color] == null) {
|
||||||
|
// Colorscheme not found.
|
||||||
|
console.error('Invalid color scheme.')
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
badgeData.color = color
|
||||||
|
} else {
|
||||||
|
badgeData.color = color
|
||||||
|
if (labelColor) {
|
||||||
|
badgeData.labelColor = labelColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
;(() => {
|
||||||
|
try {
|
||||||
|
console.log(makeBadge(badgeData))
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
})()
|
||||||
807
node_modules/badge-maker/lib/badge-renderers.js
generated
vendored
Normal file
807
node_modules/badge-maker/lib/badge-renderers.js
generated
vendored
Normal file
@@ -0,0 +1,807 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const anafanafo = require('anafanafo')
|
||||||
|
const { brightness } = require('./color')
|
||||||
|
const { XmlElement, escapeXml } = require('./xml')
|
||||||
|
|
||||||
|
// https://github.com/badges/shields/pull/1132
|
||||||
|
const FONT_SCALE_UP_FACTOR = 10
|
||||||
|
const FONT_SCALE_DOWN_VALUE = 'scale(.1)'
|
||||||
|
|
||||||
|
const FONT_FAMILY = 'Verdana,Geneva,DejaVu Sans,sans-serif'
|
||||||
|
const fontFamily = `font-family="${FONT_FAMILY}"`
|
||||||
|
const socialFontFamily =
|
||||||
|
'font-family="Helvetica Neue,Helvetica,Arial,sans-serif"'
|
||||||
|
const brightnessThreshold = 0.69
|
||||||
|
|
||||||
|
function capitalize(s) {
|
||||||
|
return `${s.charAt(0).toUpperCase()}${s.slice(1)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function colorsForBackground(color) {
|
||||||
|
if (brightness(color) <= brightnessThreshold) {
|
||||||
|
return { textColor: '#fff', shadowColor: '#010101' }
|
||||||
|
} else {
|
||||||
|
return { textColor: '#333', shadowColor: '#ccc' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function roundUpToOdd(val) {
|
||||||
|
return val % 2 === 0 ? val + 1 : val
|
||||||
|
}
|
||||||
|
|
||||||
|
function preferredWidthOf(str, options) {
|
||||||
|
// Increase chances of pixel grid alignment.
|
||||||
|
return roundUpToOdd(anafanafo(str, options) | 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAccessibleText({ label, message }) {
|
||||||
|
const labelPrefix = label ? `${label}: ` : ''
|
||||||
|
return labelPrefix + message
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasLinks({ links }) {
|
||||||
|
const [leftLink, rightLink] = links || []
|
||||||
|
const hasLeftLink = leftLink && leftLink.length
|
||||||
|
const hasRightLink = rightLink && rightLink.length
|
||||||
|
const hasLink = hasLeftLink && hasRightLink
|
||||||
|
return { hasLink, hasLeftLink, hasRightLink }
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldWrapBodyWithLink({ links }) {
|
||||||
|
const { hasLeftLink, hasRightLink } = hasLinks({ links })
|
||||||
|
return hasLeftLink && !hasRightLink
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderAriaAttributes({ accessibleText, links }) {
|
||||||
|
const { hasLink } = hasLinks({ links })
|
||||||
|
return hasLink ? '' : `role="img" aria-label="${escapeXml(accessibleText)}"`
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTitle({ accessibleText, links }) {
|
||||||
|
const { hasLink } = hasLinks({ links })
|
||||||
|
return hasLink ? '' : `<title>${escapeXml(accessibleText)}</title>`
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLogo({
|
||||||
|
logo,
|
||||||
|
badgeHeight,
|
||||||
|
horizPadding,
|
||||||
|
logoWidth = 14,
|
||||||
|
logoPadding = 0,
|
||||||
|
}) {
|
||||||
|
if (logo) {
|
||||||
|
const logoHeight = 14
|
||||||
|
const y = (badgeHeight - logoHeight) / 2
|
||||||
|
const x = horizPadding
|
||||||
|
return {
|
||||||
|
hasLogo: true,
|
||||||
|
totalLogoWidth: logoWidth + logoPadding,
|
||||||
|
renderedLogo: `<image x="${x}" y="${y}" width="${logoWidth}" height="${logoHeight}" xlink:href="${escapeXml(
|
||||||
|
logo
|
||||||
|
)}"/>`,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return { hasLogo: false, totalLogoWidth: 0, renderedLogo: '' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLink({
|
||||||
|
link,
|
||||||
|
height,
|
||||||
|
textLength,
|
||||||
|
horizPadding,
|
||||||
|
leftMargin,
|
||||||
|
renderedText,
|
||||||
|
}) {
|
||||||
|
const rectHeight = height
|
||||||
|
const rectWidth = textLength + horizPadding * 2
|
||||||
|
const rectX = leftMargin > 1 ? leftMargin + 1 : 0
|
||||||
|
return `<a target="_blank" xlink:href="${escapeXml(link)}">
|
||||||
|
<rect width="${rectWidth}" x="${rectX}" height="${rectHeight}" fill="rgba(0,0,0,0)" />
|
||||||
|
${renderedText}
|
||||||
|
</a>`
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderText({
|
||||||
|
leftMargin,
|
||||||
|
horizPadding = 0,
|
||||||
|
content,
|
||||||
|
link,
|
||||||
|
height,
|
||||||
|
verticalMargin = 0,
|
||||||
|
shadow = false,
|
||||||
|
color,
|
||||||
|
}) {
|
||||||
|
if (!content.length) {
|
||||||
|
return { renderedText: '', width: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
const textLength = preferredWidthOf(content, { font: '11px Verdana' })
|
||||||
|
const escapedContent = escapeXml(content)
|
||||||
|
|
||||||
|
const shadowMargin = 150 + verticalMargin
|
||||||
|
const textMargin = 140 + verticalMargin
|
||||||
|
|
||||||
|
const outTextLength = 10 * textLength
|
||||||
|
const x = 10 * (leftMargin + 0.5 * textLength + horizPadding)
|
||||||
|
|
||||||
|
let renderedText = ''
|
||||||
|
const { textColor, shadowColor } = colorsForBackground(color)
|
||||||
|
if (shadow) {
|
||||||
|
renderedText = `<text aria-hidden="true" x="${x}" y="${shadowMargin}" fill="${shadowColor}" fill-opacity=".3" transform="scale(.1)" textLength="${outTextLength}">${escapedContent}</text>`
|
||||||
|
}
|
||||||
|
renderedText += `<text x="${x}" y="${textMargin}" transform="scale(.1)" fill="${textColor}" textLength="${outTextLength}">${escapedContent}</text>`
|
||||||
|
|
||||||
|
return {
|
||||||
|
renderedText: link
|
||||||
|
? renderLink({
|
||||||
|
link,
|
||||||
|
height,
|
||||||
|
textLength,
|
||||||
|
horizPadding,
|
||||||
|
leftMargin,
|
||||||
|
renderedText,
|
||||||
|
})
|
||||||
|
: renderedText,
|
||||||
|
width: textLength,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderBadge(
|
||||||
|
{ links, leftWidth, rightWidth, height, accessibleText },
|
||||||
|
main
|
||||||
|
) {
|
||||||
|
const width = leftWidth + rightWidth
|
||||||
|
const leftLink = escapeXml(links[0])
|
||||||
|
|
||||||
|
return `
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${width}" height="${height}" ${renderAriaAttributes(
|
||||||
|
{ links, accessibleText }
|
||||||
|
)}>
|
||||||
|
|
||||||
|
${renderTitle({ accessibleText, links })}
|
||||||
|
${
|
||||||
|
shouldWrapBodyWithLink({ links })
|
||||||
|
? `<a target="_blank" xlink:href="${leftLink}">${main}</a>`
|
||||||
|
: main
|
||||||
|
}
|
||||||
|
</svg>`
|
||||||
|
}
|
||||||
|
|
||||||
|
class Badge {
|
||||||
|
static get fontFamily() {
|
||||||
|
throw new Error('Not implemented')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get height() {
|
||||||
|
throw new Error('Not implemented')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get verticalMargin() {
|
||||||
|
throw new Error('Not implemented')
|
||||||
|
}
|
||||||
|
|
||||||
|
static get shadow() {
|
||||||
|
throw new Error('Not implemented')
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor({
|
||||||
|
label,
|
||||||
|
message,
|
||||||
|
links,
|
||||||
|
logo,
|
||||||
|
logoWidth,
|
||||||
|
logoPadding,
|
||||||
|
color = '#4c1',
|
||||||
|
labelColor,
|
||||||
|
}) {
|
||||||
|
const horizPadding = 5
|
||||||
|
const { hasLogo, totalLogoWidth, renderedLogo } = renderLogo({
|
||||||
|
logo,
|
||||||
|
badgeHeight: this.constructor.height,
|
||||||
|
horizPadding,
|
||||||
|
logoWidth,
|
||||||
|
logoPadding,
|
||||||
|
})
|
||||||
|
const hasLabel = label.length || labelColor
|
||||||
|
if (labelColor == null) {
|
||||||
|
labelColor = '#555'
|
||||||
|
}
|
||||||
|
|
||||||
|
const [leftLink, rightLink] = links
|
||||||
|
|
||||||
|
labelColor = hasLabel || hasLogo ? labelColor : color
|
||||||
|
labelColor = escapeXml(labelColor)
|
||||||
|
color = escapeXml(color)
|
||||||
|
|
||||||
|
const labelMargin = totalLogoWidth + 1
|
||||||
|
|
||||||
|
const { renderedText: renderedLabel, width: labelWidth } = renderText({
|
||||||
|
leftMargin: labelMargin,
|
||||||
|
horizPadding,
|
||||||
|
content: label,
|
||||||
|
link: !shouldWrapBodyWithLink({ links }) && leftLink,
|
||||||
|
height: this.constructor.height,
|
||||||
|
verticalMargin: this.constructor.verticalMargin,
|
||||||
|
shadow: this.constructor.shadow,
|
||||||
|
color: labelColor,
|
||||||
|
})
|
||||||
|
|
||||||
|
const leftWidth = hasLabel
|
||||||
|
? labelWidth + 2 * horizPadding + totalLogoWidth
|
||||||
|
: 0
|
||||||
|
|
||||||
|
let messageMargin = leftWidth - (message.length ? 1 : 0)
|
||||||
|
if (!hasLabel) {
|
||||||
|
if (hasLogo) {
|
||||||
|
messageMargin = messageMargin + totalLogoWidth + horizPadding
|
||||||
|
} else {
|
||||||
|
messageMargin = messageMargin + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const { renderedText: renderedMessage, width: messageWidth } = renderText({
|
||||||
|
leftMargin: messageMargin,
|
||||||
|
horizPadding,
|
||||||
|
content: message,
|
||||||
|
link: rightLink,
|
||||||
|
height: this.constructor.height,
|
||||||
|
verticalMargin: this.constructor.verticalMargin,
|
||||||
|
shadow: this.constructor.shadow,
|
||||||
|
color,
|
||||||
|
})
|
||||||
|
|
||||||
|
let rightWidth = messageWidth + 2 * horizPadding
|
||||||
|
if (hasLogo && !hasLabel) {
|
||||||
|
rightWidth += totalLogoWidth + horizPadding - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
const width = leftWidth + rightWidth
|
||||||
|
|
||||||
|
const accessibleText = createAccessibleText({ label, message })
|
||||||
|
|
||||||
|
this.links = links
|
||||||
|
this.leftWidth = leftWidth
|
||||||
|
this.rightWidth = rightWidth
|
||||||
|
this.width = width
|
||||||
|
this.labelColor = labelColor
|
||||||
|
this.color = color
|
||||||
|
this.label = label
|
||||||
|
this.message = message
|
||||||
|
this.accessibleText = accessibleText
|
||||||
|
this.renderedLogo = renderedLogo
|
||||||
|
this.renderedLabel = renderedLabel
|
||||||
|
this.renderedMessage = renderedMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
static render(params) {
|
||||||
|
return new this(params).render()
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
throw new Error('Not implemented')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Plastic extends Badge {
|
||||||
|
static get fontFamily() {
|
||||||
|
return fontFamily
|
||||||
|
}
|
||||||
|
|
||||||
|
static get height() {
|
||||||
|
return 18
|
||||||
|
}
|
||||||
|
|
||||||
|
static get verticalMargin() {
|
||||||
|
return -10
|
||||||
|
}
|
||||||
|
|
||||||
|
static get shadow() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return renderBadge(
|
||||||
|
{
|
||||||
|
links: this.links,
|
||||||
|
leftWidth: this.leftWidth,
|
||||||
|
rightWidth: this.rightWidth,
|
||||||
|
accessibleText: this.accessibleText,
|
||||||
|
height: this.constructor.height,
|
||||||
|
},
|
||||||
|
`
|
||||||
|
<linearGradient id="s" x2="0" y2="100%">
|
||||||
|
<stop offset="0" stop-color="#fff" stop-opacity=".7"/>
|
||||||
|
<stop offset=".1" stop-color="#aaa" stop-opacity=".1"/>
|
||||||
|
<stop offset=".9" stop-color="#000" stop-opacity=".3"/>
|
||||||
|
<stop offset="1" stop-color="#000" stop-opacity=".5"/>
|
||||||
|
</linearGradient>
|
||||||
|
|
||||||
|
<clipPath id="r">
|
||||||
|
<rect width="${this.width}" height="${this.constructor.height}" rx="4" fill="#fff"/>
|
||||||
|
</clipPath>
|
||||||
|
|
||||||
|
<g clip-path="url(#r)">
|
||||||
|
<rect width="${this.leftWidth}" height="${this.constructor.height}" fill="${this.labelColor}"/>
|
||||||
|
<rect x="${this.leftWidth}" width="${this.rightWidth}" height="${this.constructor.height}" fill="${this.color}"/>
|
||||||
|
<rect width="${this.width}" height="${this.constructor.height}" fill="url(#s)"/>
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<g fill="#fff" text-anchor="middle" ${this.constructor.fontFamily} text-rendering="geometricPrecision" font-size="110">
|
||||||
|
${this.renderedLogo}
|
||||||
|
${this.renderedLabel}
|
||||||
|
${this.renderedMessage}
|
||||||
|
</g>`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Flat extends Badge {
|
||||||
|
static get fontFamily() {
|
||||||
|
return fontFamily
|
||||||
|
}
|
||||||
|
|
||||||
|
static get height() {
|
||||||
|
return 20
|
||||||
|
}
|
||||||
|
|
||||||
|
static get verticalMargin() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
static get shadow() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return renderBadge(
|
||||||
|
{
|
||||||
|
links: this.links,
|
||||||
|
leftWidth: this.leftWidth,
|
||||||
|
rightWidth: this.rightWidth,
|
||||||
|
accessibleText: this.accessibleText,
|
||||||
|
height: this.constructor.height,
|
||||||
|
},
|
||||||
|
`
|
||||||
|
<linearGradient id="s" x2="0" y2="100%">
|
||||||
|
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
||||||
|
<stop offset="1" stop-opacity=".1"/>
|
||||||
|
</linearGradient>
|
||||||
|
|
||||||
|
<clipPath id="r">
|
||||||
|
<rect width="${this.width}" height="${this.constructor.height}" rx="3" fill="#fff"/>
|
||||||
|
</clipPath>
|
||||||
|
|
||||||
|
<g clip-path="url(#r)">
|
||||||
|
<rect width="${this.leftWidth}" height="${this.constructor.height}" fill="${this.labelColor}"/>
|
||||||
|
<rect x="${this.leftWidth}" width="${this.rightWidth}" height="${this.constructor.height}" fill="${this.color}"/>
|
||||||
|
<rect width="${this.width}" height="${this.constructor.height}" fill="url(#s)"/>
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<g fill="#fff" text-anchor="middle" ${this.constructor.fontFamily} text-rendering="geometricPrecision" font-size="110">
|
||||||
|
${this.renderedLogo}
|
||||||
|
${this.renderedLabel}
|
||||||
|
${this.renderedMessage}
|
||||||
|
</g>`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FlatSquare extends Badge {
|
||||||
|
static get fontFamily() {
|
||||||
|
return fontFamily
|
||||||
|
}
|
||||||
|
|
||||||
|
static get height() {
|
||||||
|
return 20
|
||||||
|
}
|
||||||
|
|
||||||
|
static get verticalMargin() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
static get shadow() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return renderBadge(
|
||||||
|
{
|
||||||
|
links: this.links,
|
||||||
|
leftWidth: this.leftWidth,
|
||||||
|
rightWidth: this.rightWidth,
|
||||||
|
accessibleText: this.accessibleText,
|
||||||
|
height: this.constructor.height,
|
||||||
|
},
|
||||||
|
`
|
||||||
|
<g shape-rendering="crispEdges">
|
||||||
|
<rect width="${this.leftWidth}" height="${this.constructor.height}" fill="${this.labelColor}"/>
|
||||||
|
<rect x="${this.leftWidth}" width="${this.rightWidth}" height="${this.constructor.height}" fill="${this.color}"/>
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<g fill="#fff" text-anchor="middle" ${this.constructor.fontFamily} text-rendering="geometricPrecision" font-size="110">
|
||||||
|
${this.renderedLogo}
|
||||||
|
${this.renderedLabel}
|
||||||
|
${this.renderedMessage}
|
||||||
|
</g>`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function social({
|
||||||
|
label,
|
||||||
|
message,
|
||||||
|
links = [],
|
||||||
|
logo,
|
||||||
|
logoWidth,
|
||||||
|
logoPadding,
|
||||||
|
color = '#4c1',
|
||||||
|
labelColor = '#555',
|
||||||
|
}) {
|
||||||
|
// Social label is styled with a leading capital. Convert to caps here so
|
||||||
|
// width can be measured using the correct characters.
|
||||||
|
label = capitalize(label)
|
||||||
|
|
||||||
|
const externalHeight = 20
|
||||||
|
const internalHeight = 19
|
||||||
|
const labelHorizPadding = 5
|
||||||
|
const messageHorizPadding = 4
|
||||||
|
const horizGutter = 6
|
||||||
|
const { totalLogoWidth, renderedLogo } = renderLogo({
|
||||||
|
logo,
|
||||||
|
badgeHeight: externalHeight,
|
||||||
|
horizPadding: labelHorizPadding,
|
||||||
|
logoWidth,
|
||||||
|
logoPadding,
|
||||||
|
})
|
||||||
|
const hasMessage = message.length
|
||||||
|
|
||||||
|
const font = 'bold 11px Helvetica'
|
||||||
|
const labelTextWidth = preferredWidthOf(label, { font })
|
||||||
|
const messageTextWidth = preferredWidthOf(message, { font })
|
||||||
|
const labelRectWidth = labelTextWidth + totalLogoWidth + 2 * labelHorizPadding
|
||||||
|
const messageRectWidth = messageTextWidth + 2 * messageHorizPadding
|
||||||
|
|
||||||
|
let [leftLink, rightLink] = links
|
||||||
|
leftLink = escapeXml(leftLink)
|
||||||
|
rightLink = escapeXml(rightLink)
|
||||||
|
const { hasLeftLink, hasRightLink, hasLink } = hasLinks({ links })
|
||||||
|
|
||||||
|
const accessibleText = createAccessibleText({ label, message })
|
||||||
|
|
||||||
|
function renderMessageBubble() {
|
||||||
|
const messageBubbleMainX = labelRectWidth + horizGutter + 0.5
|
||||||
|
const messageBubbleNotchX = labelRectWidth + horizGutter
|
||||||
|
return `
|
||||||
|
<rect x="${messageBubbleMainX}" y="0.5" width="${messageRectWidth}" height="${internalHeight}" rx="2" fill="#fafafa"/>
|
||||||
|
<rect x="${messageBubbleNotchX}" y="7.5" width="0.5" height="5" stroke="#fafafa"/>
|
||||||
|
<path d="M${messageBubbleMainX} 6.5 l-3 3v1 l3 3" stroke="d5d5d5" fill="#fafafa"/>
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderLabelText() {
|
||||||
|
const labelTextX =
|
||||||
|
10 * (totalLogoWidth + labelTextWidth / 2 + labelHorizPadding)
|
||||||
|
const labelTextLength = 10 * labelTextWidth
|
||||||
|
const escapedLabel = escapeXml(label)
|
||||||
|
const shouldWrapWithLink = hasLeftLink && !shouldWrapBodyWithLink({ links })
|
||||||
|
|
||||||
|
const rect = `<rect id="llink" stroke="#d5d5d5" fill="url(#a)" x=".5" y=".5" width="${labelRectWidth}" height="${internalHeight}" rx="2" />`
|
||||||
|
const shadow = `<text aria-hidden="true" x="${labelTextX}" y="150" fill="#fff" transform="scale(.1)" textLength="${labelTextLength}">${escapedLabel}</text>`
|
||||||
|
const text = `<text x="${labelTextX}" y="140" transform="scale(.1)" textLength="${labelTextLength}">${escapedLabel}</text>`
|
||||||
|
|
||||||
|
return shouldWrapWithLink
|
||||||
|
? `
|
||||||
|
<a target="_blank" xlink:href="${leftLink}">
|
||||||
|
${shadow}
|
||||||
|
${text}
|
||||||
|
${rect}
|
||||||
|
</a>
|
||||||
|
`
|
||||||
|
: `
|
||||||
|
${rect}
|
||||||
|
${shadow}
|
||||||
|
${text}
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderMessageText() {
|
||||||
|
const messageTextX =
|
||||||
|
10 * (labelRectWidth + horizGutter + messageRectWidth / 2)
|
||||||
|
const messageTextLength = 10 * messageTextWidth
|
||||||
|
const escapedMessage = escapeXml(message)
|
||||||
|
|
||||||
|
const rect = `<rect width="${messageRectWidth + 1}" x="${
|
||||||
|
labelRectWidth + horizGutter
|
||||||
|
}" height="${internalHeight + 1}" fill="rgba(0,0,0,0)" />`
|
||||||
|
const shadow = `<text aria-hidden="true" x="${messageTextX}" y="150" fill="#fff" transform="scale(.1)" textLength="${messageTextLength}">${escapedMessage}</text>`
|
||||||
|
const text = `<text id="rlink" x="${messageTextX}" y="140" transform="scale(.1)" textLength="${messageTextLength}">${escapedMessage}</text>`
|
||||||
|
|
||||||
|
return hasRightLink
|
||||||
|
? `
|
||||||
|
<a target="_blank" xlink:href="${rightLink}">
|
||||||
|
${rect}
|
||||||
|
${shadow}
|
||||||
|
${text}
|
||||||
|
</a>
|
||||||
|
`
|
||||||
|
: `
|
||||||
|
${shadow}
|
||||||
|
${text}
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
return renderBadge(
|
||||||
|
{
|
||||||
|
links,
|
||||||
|
leftWidth: labelRectWidth + 1,
|
||||||
|
rightWidth: hasMessage ? horizGutter + messageRectWidth : 0,
|
||||||
|
accessibleText,
|
||||||
|
height: externalHeight,
|
||||||
|
},
|
||||||
|
`
|
||||||
|
<style>a:hover #llink{fill:url(#b);stroke:#ccc}a:hover #rlink{fill:#4183c4}</style>
|
||||||
|
<linearGradient id="a" x2="0" y2="100%">
|
||||||
|
<stop offset="0" stop-color="#fcfcfc" stop-opacity="0"/>
|
||||||
|
<stop offset="1" stop-opacity=".1"/>
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient id="b" x2="0" y2="100%">
|
||||||
|
<stop offset="0" stop-color="#ccc" stop-opacity=".1"/>
|
||||||
|
<stop offset="1" stop-opacity=".1"/>
|
||||||
|
</linearGradient>
|
||||||
|
<g stroke="#d5d5d5">
|
||||||
|
<rect stroke="none" fill="#fcfcfc" x="0.5" y="0.5" width="${labelRectWidth}" height="${internalHeight}" rx="2"/>
|
||||||
|
${hasMessage ? renderMessageBubble() : ''}
|
||||||
|
</g>
|
||||||
|
${renderedLogo}
|
||||||
|
<g aria-hidden="${!hasLink}" fill="#333" text-anchor="middle" ${socialFontFamily} text-rendering="geometricPrecision" font-weight="700" font-size="110px" line-height="14px">
|
||||||
|
${renderLabelText()}
|
||||||
|
${hasMessage ? renderMessageText() : ''}
|
||||||
|
</g>
|
||||||
|
`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function forTheBadge({
|
||||||
|
label,
|
||||||
|
message,
|
||||||
|
links,
|
||||||
|
logo,
|
||||||
|
logoWidth,
|
||||||
|
color = '#4c1',
|
||||||
|
labelColor,
|
||||||
|
}) {
|
||||||
|
const FONT_SIZE = 10
|
||||||
|
const BADGE_HEIGHT = 28
|
||||||
|
const LOGO_HEIGHT = 14
|
||||||
|
const TEXT_MARGIN = 12
|
||||||
|
const LOGO_MARGIN = 9
|
||||||
|
const LOGO_TEXT_GUTTER = 6
|
||||||
|
const LETTER_SPACING = 1.25
|
||||||
|
|
||||||
|
// Prepare content. For the Badge is styled in all caps. It's important to to
|
||||||
|
// convert to uppercase first so the widths can be measured using the correct
|
||||||
|
// symbols.
|
||||||
|
label = label.toUpperCase()
|
||||||
|
message = message.toUpperCase()
|
||||||
|
|
||||||
|
const [leftLink, rightLink] = links
|
||||||
|
const { hasLeftLink, hasRightLink } = hasLinks({ links })
|
||||||
|
|
||||||
|
const outLabelColor = labelColor || '#555'
|
||||||
|
|
||||||
|
// Compute text width.
|
||||||
|
// TODO: This really should count the symbols rather than just using `.length`.
|
||||||
|
// https://mathiasbynens.be/notes/javascript-unicode
|
||||||
|
// This is not using `preferredWidthOf()` as it tends to produce larger
|
||||||
|
// inconsistencies in the letter spacing. The badges look fine, however if you
|
||||||
|
// replace `textLength` with `letterSpacing` in the rendered SVG, you can see
|
||||||
|
// the discrepancy. Ideally, swapping out `textLength` for `letterSpacing`
|
||||||
|
// should not affect the appearance.
|
||||||
|
const labelTextWidth = label.length
|
||||||
|
? (anafanafo(label, { font: `${FONT_SIZE}px Verdana` }) | 0) +
|
||||||
|
LETTER_SPACING * label.length
|
||||||
|
: 0
|
||||||
|
const messageTextWidth = message.length
|
||||||
|
? (anafanafo(message, { font: `bold ${FONT_SIZE}px Verdana` }) | 0) +
|
||||||
|
LETTER_SPACING * message.length
|
||||||
|
: 0
|
||||||
|
|
||||||
|
// Compute horizontal layout.
|
||||||
|
// If a `labelColor` is set, the logo is always set against it, even when
|
||||||
|
// there is no label. When `needsLabelRect` is true, render a label rect and a
|
||||||
|
// message rect; when false, only a message rect.
|
||||||
|
const hasLabel = Boolean(label.length)
|
||||||
|
const needsLabelRect = hasLabel || (logo && labelColor)
|
||||||
|
let logoMinX, labelTextMinX
|
||||||
|
if (logo) {
|
||||||
|
logoMinX = LOGO_MARGIN
|
||||||
|
labelTextMinX = logoMinX + logoWidth + LOGO_TEXT_GUTTER
|
||||||
|
} else {
|
||||||
|
labelTextMinX = TEXT_MARGIN
|
||||||
|
}
|
||||||
|
let labelRectWidth, messageTextMinX, messageRectWidth
|
||||||
|
if (needsLabelRect) {
|
||||||
|
if (hasLabel) {
|
||||||
|
labelRectWidth = labelTextMinX + labelTextWidth + TEXT_MARGIN
|
||||||
|
} else {
|
||||||
|
labelRectWidth = 2 * LOGO_MARGIN + logoWidth
|
||||||
|
}
|
||||||
|
messageTextMinX = labelRectWidth + TEXT_MARGIN
|
||||||
|
messageRectWidth = 2 * TEXT_MARGIN + messageTextWidth
|
||||||
|
} else {
|
||||||
|
if (logo) {
|
||||||
|
messageTextMinX = TEXT_MARGIN + logoWidth + LOGO_TEXT_GUTTER
|
||||||
|
messageRectWidth =
|
||||||
|
2 * TEXT_MARGIN + logoWidth + LOGO_TEXT_GUTTER + messageTextWidth
|
||||||
|
} else {
|
||||||
|
messageTextMinX = TEXT_MARGIN
|
||||||
|
messageRectWidth = 2 * TEXT_MARGIN + messageTextWidth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const logoElement = new XmlElement({
|
||||||
|
name: 'image',
|
||||||
|
attrs: {
|
||||||
|
x: logoMinX,
|
||||||
|
y: 0.5 * (BADGE_HEIGHT - LOGO_HEIGHT),
|
||||||
|
width: logoWidth,
|
||||||
|
height: LOGO_HEIGHT,
|
||||||
|
'xlink:href': logo,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function getLabelElement() {
|
||||||
|
const { textColor } = colorsForBackground(outLabelColor)
|
||||||
|
const midX = labelTextMinX + 0.5 * labelTextWidth
|
||||||
|
const text = new XmlElement({
|
||||||
|
name: 'text',
|
||||||
|
content: [label],
|
||||||
|
attrs: {
|
||||||
|
transform: FONT_SCALE_DOWN_VALUE,
|
||||||
|
x: FONT_SCALE_UP_FACTOR * midX,
|
||||||
|
y: 175,
|
||||||
|
textLength: FONT_SCALE_UP_FACTOR * labelTextWidth,
|
||||||
|
fill: textColor,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (hasLeftLink && !shouldWrapBodyWithLink({ links })) {
|
||||||
|
const rect = new XmlElement({
|
||||||
|
name: 'rect',
|
||||||
|
attrs: {
|
||||||
|
width: labelRectWidth,
|
||||||
|
height: BADGE_HEIGHT,
|
||||||
|
fill: 'rgba(0,0,0,0)',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return new XmlElement({
|
||||||
|
name: 'a',
|
||||||
|
content: [rect, text],
|
||||||
|
attrs: {
|
||||||
|
target: '_blank',
|
||||||
|
'xlink:href': leftLink,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMessageElement() {
|
||||||
|
const { textColor } = colorsForBackground(color)
|
||||||
|
const midX = messageTextMinX + 0.5 * messageTextWidth
|
||||||
|
const text = new XmlElement({
|
||||||
|
name: 'text',
|
||||||
|
content: [message],
|
||||||
|
attrs: {
|
||||||
|
transform: FONT_SCALE_DOWN_VALUE,
|
||||||
|
x: FONT_SCALE_UP_FACTOR * midX,
|
||||||
|
y: 175,
|
||||||
|
textLength: FONT_SCALE_UP_FACTOR * messageTextWidth,
|
||||||
|
fill: textColor,
|
||||||
|
'font-weight': 'bold',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (hasRightLink) {
|
||||||
|
const rect = new XmlElement({
|
||||||
|
name: 'rect',
|
||||||
|
attrs: {
|
||||||
|
width: messageRectWidth,
|
||||||
|
height: BADGE_HEIGHT,
|
||||||
|
x: labelRectWidth || 0,
|
||||||
|
fill: 'rgba(0,0,0,0)',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return new XmlElement({
|
||||||
|
name: 'a',
|
||||||
|
content: [rect, text],
|
||||||
|
attrs: {
|
||||||
|
target: '_blank',
|
||||||
|
'xlink:href': rightLink,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let backgroundContent
|
||||||
|
if (needsLabelRect) {
|
||||||
|
backgroundContent = [
|
||||||
|
new XmlElement({
|
||||||
|
name: 'rect',
|
||||||
|
attrs: {
|
||||||
|
width: labelRectWidth,
|
||||||
|
height: BADGE_HEIGHT,
|
||||||
|
fill: outLabelColor,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new XmlElement({
|
||||||
|
name: 'rect',
|
||||||
|
attrs: {
|
||||||
|
x: labelRectWidth,
|
||||||
|
width: messageRectWidth,
|
||||||
|
height: BADGE_HEIGHT,
|
||||||
|
fill: color,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
backgroundContent = [
|
||||||
|
new XmlElement({
|
||||||
|
name: 'rect',
|
||||||
|
attrs: {
|
||||||
|
width: messageRectWidth,
|
||||||
|
height: BADGE_HEIGHT,
|
||||||
|
fill: color,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const backgroundGroup = new XmlElement({
|
||||||
|
name: 'g',
|
||||||
|
content: backgroundContent,
|
||||||
|
attrs: {
|
||||||
|
'shape-rendering': 'crispEdges',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const foregroundGroup = new XmlElement({
|
||||||
|
name: 'g',
|
||||||
|
content: [
|
||||||
|
logo ? logoElement : '',
|
||||||
|
hasLabel ? getLabelElement() : '',
|
||||||
|
getMessageElement(),
|
||||||
|
],
|
||||||
|
attrs: {
|
||||||
|
fill: '#fff',
|
||||||
|
'text-anchor': 'middle',
|
||||||
|
'font-family': FONT_FAMILY,
|
||||||
|
'text-rendering': 'geometricPrecision',
|
||||||
|
'font-size': FONT_SCALE_UP_FACTOR * FONT_SIZE,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
// Render.
|
||||||
|
return renderBadge(
|
||||||
|
{
|
||||||
|
links,
|
||||||
|
leftWidth: labelRectWidth || 0,
|
||||||
|
rightWidth: messageRectWidth,
|
||||||
|
accessibleText: createAccessibleText({ label, message }),
|
||||||
|
height: BADGE_HEIGHT,
|
||||||
|
},
|
||||||
|
[backgroundGroup.render(), foregroundGroup.render()].join('')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
plastic: params => Plastic.render(params),
|
||||||
|
flat: params => Flat.render(params),
|
||||||
|
'flat-square': params => FlatSquare.render(params),
|
||||||
|
social,
|
||||||
|
'for-the-badge': forTheBadge,
|
||||||
|
}
|
||||||
88
node_modules/badge-maker/lib/color.js
generated
vendored
Normal file
88
node_modules/badge-maker/lib/color.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const { fromString } = require('css-color-converter')
|
||||||
|
|
||||||
|
// When updating these, be sure also to update the list in `badge-maker/README.md`.
|
||||||
|
const namedColors = {
|
||||||
|
brightgreen: '#4c1',
|
||||||
|
green: '#97ca00',
|
||||||
|
yellow: '#dfb317',
|
||||||
|
yellowgreen: '#a4a61d',
|
||||||
|
orange: '#fe7d37',
|
||||||
|
red: '#e05d44',
|
||||||
|
blue: '#007ec6',
|
||||||
|
grey: '#555',
|
||||||
|
lightgrey: '#9f9f9f',
|
||||||
|
}
|
||||||
|
|
||||||
|
const aliases = {
|
||||||
|
gray: 'grey',
|
||||||
|
lightgray: 'lightgrey',
|
||||||
|
critical: 'red',
|
||||||
|
important: 'orange',
|
||||||
|
success: 'brightgreen',
|
||||||
|
informational: 'blue',
|
||||||
|
inactive: 'lightgrey',
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolvedAliases = {}
|
||||||
|
Object.entries(aliases).forEach(([alias, original]) => {
|
||||||
|
resolvedAliases[alias] = namedColors[original]
|
||||||
|
})
|
||||||
|
|
||||||
|
// This function returns false for `#ccc`. However `isCSSColor('#ccc')` is
|
||||||
|
// true.
|
||||||
|
const hexColorRegex = /^([\da-f]{3}){1,2}$/i
|
||||||
|
function isHexColor(s = '') {
|
||||||
|
return hexColorRegex.test(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
function isCSSColor(color) {
|
||||||
|
return typeof color === 'string' && fromString(color.trim())
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeColor(color) {
|
||||||
|
if (color === undefined) {
|
||||||
|
return undefined
|
||||||
|
} else if (color in namedColors) {
|
||||||
|
return color
|
||||||
|
} else if (color in aliases) {
|
||||||
|
return aliases[color]
|
||||||
|
} else if (isHexColor(color)) {
|
||||||
|
return `#${color.toLowerCase()}`
|
||||||
|
} else if (isCSSColor(color)) {
|
||||||
|
return color.toLowerCase()
|
||||||
|
} else {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toSvgColor(color) {
|
||||||
|
const normalized = normalizeColor(color)
|
||||||
|
if (normalized in namedColors) {
|
||||||
|
return namedColors[normalized]
|
||||||
|
} else if (normalized in resolvedAliases) {
|
||||||
|
return resolvedAliases[normalized]
|
||||||
|
} else {
|
||||||
|
return normalized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function brightness(color) {
|
||||||
|
if (color) {
|
||||||
|
const cssColor = fromString(color)
|
||||||
|
if (cssColor) {
|
||||||
|
const rgb = cssColor.toRgbaArray()
|
||||||
|
return +((rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 255000).toFixed(2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
namedColors,
|
||||||
|
isHexColor,
|
||||||
|
normalizeColor,
|
||||||
|
toSvgColor,
|
||||||
|
brightness,
|
||||||
|
}
|
||||||
81
node_modules/badge-maker/lib/index.js
generated
vendored
Normal file
81
node_modules/badge-maker/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
'use strict'
|
||||||
|
/**
|
||||||
|
* @module badge-maker
|
||||||
|
*/
|
||||||
|
|
||||||
|
const _makeBadge = require('./make-badge')
|
||||||
|
|
||||||
|
class ValidationError extends Error {}
|
||||||
|
|
||||||
|
function _validate(format) {
|
||||||
|
if (format !== Object(format)) {
|
||||||
|
throw new ValidationError('makeBadge takes an argument of type object')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!('message' in format)) {
|
||||||
|
throw new ValidationError('Field `message` is required')
|
||||||
|
}
|
||||||
|
|
||||||
|
const stringFields = ['labelColor', 'color', 'message', 'label']
|
||||||
|
stringFields.forEach(function (field) {
|
||||||
|
if (field in format && typeof format[field] !== 'string') {
|
||||||
|
throw new ValidationError(`Field \`${field}\` must be of type string`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const styleValues = [
|
||||||
|
'plastic',
|
||||||
|
'flat',
|
||||||
|
'flat-square',
|
||||||
|
'for-the-badge',
|
||||||
|
'social',
|
||||||
|
]
|
||||||
|
if ('style' in format && !styleValues.includes(format.style)) {
|
||||||
|
throw new ValidationError(
|
||||||
|
`Field \`style\` must be one of (${styleValues.toString()})`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function _clean(format) {
|
||||||
|
const expectedKeys = ['label', 'message', 'labelColor', 'color', 'style']
|
||||||
|
|
||||||
|
const cleaned = {}
|
||||||
|
Object.keys(format).forEach(key => {
|
||||||
|
if (format[key] != null && expectedKeys.includes(key)) {
|
||||||
|
cleaned[key] = format[key]
|
||||||
|
} else {
|
||||||
|
throw new ValidationError(
|
||||||
|
`Unexpected field '${key}'. Allowed values are (${expectedKeys.toString()})`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Legacy.
|
||||||
|
cleaned.label = cleaned.label || ''
|
||||||
|
|
||||||
|
return cleaned
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a badge
|
||||||
|
*
|
||||||
|
* @param {object} format Object specifying badge data
|
||||||
|
* @param {string} format.label (Optional) Badge label (e.g: 'build')
|
||||||
|
* @param {string} format.message (Required) Badge message (e.g: 'passing')
|
||||||
|
* @param {string} format.labelColor (Optional) Label color
|
||||||
|
* @param {string} format.color (Optional) Message color
|
||||||
|
* @param {string} format.style (Optional) Visual style e.g: 'flat'
|
||||||
|
* @returns {string} Badge in SVG format
|
||||||
|
* @see https://github.com/badges/shields/tree/master/badge-maker/README.md
|
||||||
|
*/
|
||||||
|
function makeBadge(format) {
|
||||||
|
_validate(format)
|
||||||
|
const cleanedFormat = _clean(format)
|
||||||
|
return _makeBadge(cleanedFormat)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
makeBadge,
|
||||||
|
ValidationError,
|
||||||
|
}
|
||||||
63
node_modules/badge-maker/lib/make-badge.js
generated
vendored
Normal file
63
node_modules/badge-maker/lib/make-badge.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const { normalizeColor, toSvgColor } = require('./color')
|
||||||
|
const badgeRenderers = require('./badge-renderers')
|
||||||
|
const { stripXmlWhitespace } = require('./xml')
|
||||||
|
|
||||||
|
/*
|
||||||
|
note: makeBadge() is fairly thinly wrapped so if we are making changes here
|
||||||
|
it is likely this will impact on the package's public interface in index.js
|
||||||
|
*/
|
||||||
|
module.exports = function makeBadge({
|
||||||
|
format,
|
||||||
|
style = 'flat',
|
||||||
|
label,
|
||||||
|
message,
|
||||||
|
color,
|
||||||
|
labelColor,
|
||||||
|
logo,
|
||||||
|
logoPosition,
|
||||||
|
logoWidth,
|
||||||
|
links = ['', ''],
|
||||||
|
}) {
|
||||||
|
// String coercion and whitespace removal.
|
||||||
|
label = `${label}`.trim()
|
||||||
|
message = `${message}`.trim()
|
||||||
|
|
||||||
|
// This ought to be the responsibility of the server, not `makeBadge`.
|
||||||
|
if (format === 'json') {
|
||||||
|
return JSON.stringify({
|
||||||
|
label,
|
||||||
|
message,
|
||||||
|
logoWidth,
|
||||||
|
// Only call normalizeColor for the JSON case: this is handled
|
||||||
|
// internally by toSvgColor in the SVG case.
|
||||||
|
color: normalizeColor(color),
|
||||||
|
labelColor: normalizeColor(labelColor),
|
||||||
|
link: links,
|
||||||
|
name: label,
|
||||||
|
value: message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const render = badgeRenderers[style]
|
||||||
|
if (!render) {
|
||||||
|
throw new Error(`Unknown badge style: '${style}'`)
|
||||||
|
}
|
||||||
|
|
||||||
|
logoWidth = +logoWidth || (logo ? 14 : 0)
|
||||||
|
|
||||||
|
return stripXmlWhitespace(
|
||||||
|
render({
|
||||||
|
label,
|
||||||
|
message,
|
||||||
|
links,
|
||||||
|
logo,
|
||||||
|
logoPosition,
|
||||||
|
logoWidth,
|
||||||
|
logoPadding: logo && label.length ? 3 : 0,
|
||||||
|
color: toSvgColor(color),
|
||||||
|
labelColor: toSvgColor(labelColor),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
76
node_modules/badge-maker/lib/xml.js
generated
vendored
Normal file
76
node_modules/badge-maker/lib/xml.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/**
|
||||||
|
* @module
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
function stripXmlWhitespace(xml) {
|
||||||
|
return xml.replace(/>\s+/g, '>').replace(/<\s+/g, '<').trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeXml(s) {
|
||||||
|
if (typeof s === 'number') {
|
||||||
|
return s
|
||||||
|
} else if (s === undefined || typeof s !== 'string') {
|
||||||
|
return undefined
|
||||||
|
} else {
|
||||||
|
return s
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Representation of an XML element
|
||||||
|
*/
|
||||||
|
class XmlElement {
|
||||||
|
/**
|
||||||
|
* Xml Element Constructor
|
||||||
|
*
|
||||||
|
* @param {object} attrs Refer to individual attrs
|
||||||
|
* @param {string} attrs.name
|
||||||
|
* Name of the XML tag
|
||||||
|
* @param {Array.<string|module:badge-maker/lib/xml-element~XmlElement>} [attrs.content=[]]
|
||||||
|
* Array of objects to render inside the tag. content may contain a mix of
|
||||||
|
* string and XmlElement objects. If content is `[]` or ommitted the
|
||||||
|
* element will be rendered as a self-closing element.
|
||||||
|
* @param {object} [attrs.attrs={}]
|
||||||
|
* Object representing the tag's attributes as name/value pairs
|
||||||
|
*/
|
||||||
|
constructor({ name, content = [], attrs = {} }) {
|
||||||
|
this.name = name
|
||||||
|
this.content = content
|
||||||
|
this.attrs = attrs
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the XML element to a string, applying appropriate escaping
|
||||||
|
*
|
||||||
|
* @returns {string} String representation of the XML element
|
||||||
|
*/
|
||||||
|
render() {
|
||||||
|
const attrsStr = Object.entries(this.attrs)
|
||||||
|
.map(([k, v]) => ` ${k}="${escapeXml(v)}"`)
|
||||||
|
.join('')
|
||||||
|
if (this.content.length > 0) {
|
||||||
|
const content = this.content
|
||||||
|
.map(function (el) {
|
||||||
|
if (el instanceof XmlElement) {
|
||||||
|
return el.render()
|
||||||
|
} else {
|
||||||
|
return escapeXml(el)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.join(' ')
|
||||||
|
return stripXmlWhitespace(
|
||||||
|
`<${this.name}${attrsStr}>${content}</${this.name}>`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return stripXmlWhitespace(`<${this.name}${attrsStr}/>`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { escapeXml, stripXmlWhitespace, XmlElement }
|
||||||
44
node_modules/badge-maker/package.json
generated
vendored
Normal file
44
node_modules/badge-maker/package.json
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"name": "badge-maker",
|
||||||
|
"version": "3.3.1",
|
||||||
|
"description": "Shields.io badge library",
|
||||||
|
"keywords": [
|
||||||
|
"GitHub",
|
||||||
|
"badge",
|
||||||
|
"SVG",
|
||||||
|
"image",
|
||||||
|
"shields.io"
|
||||||
|
],
|
||||||
|
"types": "index.d.ts",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/badges/shields.git",
|
||||||
|
"directory": "badge-maker"
|
||||||
|
},
|
||||||
|
"author": "Thaddée Tyl <thaddee.tyl@gmail.com>",
|
||||||
|
"license": "CC0-1.0",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/badges/shields/issues"
|
||||||
|
},
|
||||||
|
"homepage": "http://shields.io",
|
||||||
|
"bin": {
|
||||||
|
"badge": "lib/badge-cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10",
|
||||||
|
"npm": ">= 5"
|
||||||
|
},
|
||||||
|
"collective": {
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/shields",
|
||||||
|
"logo": "https://opencollective.com/opencollective/logo.txt"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"anafanafo": "2.0.0",
|
||||||
|
"css-color-converter": "^2.0.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo 'Run tests from parent dir'; false"
|
||||||
|
}
|
||||||
|
}
|
||||||
6
node_modules/binary-search/.travis.yml
generated
vendored
Normal file
6
node_modules/binary-search/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- '6'
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- node_modules
|
||||||
46
node_modules/binary-search/README.md
generated
vendored
Normal file
46
node_modules/binary-search/README.md
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
binary-search
|
||||||
|
=============
|
||||||
|
|
||||||
|
This is a really tiny, stupid, simple binary search library for Node.JS. We
|
||||||
|
wrote it because existing solutions were bloated and incorrect.
|
||||||
|
|
||||||
|
This version is a straight port of the Java version mentioned by Joshua Bloch
|
||||||
|
in his article, [Nearly All Binary Searches and Merge Sorts are Broken](http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html).
|
||||||
|
|
||||||
|
Thanks to [Conrad Irwin](https://github.com/ConradIrwin) and [Michael
|
||||||
|
Marino](https://github.com/mgmarino) for, ironically, pointing out bugs.
|
||||||
|
|
||||||
|
Example
|
||||||
|
-------
|
||||||
|
|
||||||
|
```js
|
||||||
|
var bs = require("binary-search");
|
||||||
|
|
||||||
|
bs([1, 2, 3, 4], 3, function(element, needle) { return element - needle; });
|
||||||
|
// => 2
|
||||||
|
|
||||||
|
bs([1, 2, 4, 5], 3, function(element, needle) { return element - needle; });
|
||||||
|
// => -3
|
||||||
|
```
|
||||||
|
|
||||||
|
Be advised that passing in a comparator function is *required*. Since you're
|
||||||
|
probably using one for your sort function anyway, this isn't a big deal.
|
||||||
|
|
||||||
|
The comparator takes a 1st and 2nd argument of element and needle, respectively.
|
||||||
|
|
||||||
|
The comparator also takes a 3rd and 4th argument, the current index and array,
|
||||||
|
respectively. You shouldn't normally need the index or array to compare values,
|
||||||
|
but it's there if you do.
|
||||||
|
|
||||||
|
You may also, optionally, specify an input range as the final two parameters,
|
||||||
|
in case you want to limit the search to a particular range of inputs. However,
|
||||||
|
be advised that this is generally a bad idea (but sometimes bad ideas are
|
||||||
|
necessary).
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
To the extent possible by law, The Dark Sky Company, LLC has [waived all
|
||||||
|
copyright and related or neighboring rights][cc0] to this library.
|
||||||
|
|
||||||
|
[cc0]: http://creativecommons.org/publicdomain/zero/1.0/
|
||||||
22
node_modules/binary-search/binary-search.d.ts
generated
vendored
Normal file
22
node_modules/binary-search/binary-search.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
//Typescript type definition for:
|
||||||
|
//https://github.com/darkskyapp/binary-search
|
||||||
|
declare module 'binary-search' {
|
||||||
|
|
||||||
|
function binarySearch<A, B>(
|
||||||
|
haystack: ArrayLike<A>,
|
||||||
|
needle: B,
|
||||||
|
comparator: (a: A, b: B, index?: number, haystack?: A[]) => any,
|
||||||
|
// Notes about comparator return value:
|
||||||
|
// * when a<b the comparator's returned value should be:
|
||||||
|
// * negative number or a value such that `+value` is a negative number
|
||||||
|
// * examples: `-1` or the string `"-1"`
|
||||||
|
// * when a>b the comparator's returned value should be:
|
||||||
|
// * positive number or a value such that `+value` is a positive number
|
||||||
|
// * examples: `1` or the string `"1"`
|
||||||
|
// * when a===b
|
||||||
|
// * any value other than the return cases for a<b and a>b
|
||||||
|
// * examples: undefined, NaN, 'abc'
|
||||||
|
low?: number,
|
||||||
|
high?: number): number; //returns index of found result or number < 0 if not found
|
||||||
|
export = binarySearch;
|
||||||
|
}
|
||||||
45
node_modules/binary-search/index.js
generated
vendored
Normal file
45
node_modules/binary-search/index.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
module.exports = function(haystack, needle, comparator, low, high) {
|
||||||
|
var mid, cmp;
|
||||||
|
|
||||||
|
if(low === undefined)
|
||||||
|
low = 0;
|
||||||
|
|
||||||
|
else {
|
||||||
|
low = low|0;
|
||||||
|
if(low < 0 || low >= haystack.length)
|
||||||
|
throw new RangeError("invalid lower bound");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(high === undefined)
|
||||||
|
high = haystack.length - 1;
|
||||||
|
|
||||||
|
else {
|
||||||
|
high = high|0;
|
||||||
|
if(high < low || high >= haystack.length)
|
||||||
|
throw new RangeError("invalid upper bound");
|
||||||
|
}
|
||||||
|
|
||||||
|
while(low <= high) {
|
||||||
|
// The naive `low + high >>> 1` could fail for array lengths > 2**31
|
||||||
|
// because `>>>` converts its operands to int32. `low + (high - low >>> 1)`
|
||||||
|
// works for array lengths <= 2**32-1 which is also Javascript's max array
|
||||||
|
// length.
|
||||||
|
mid = low + ((high - low) >>> 1);
|
||||||
|
cmp = +comparator(haystack[mid], needle, mid, haystack);
|
||||||
|
|
||||||
|
// Too low.
|
||||||
|
if(cmp < 0.0)
|
||||||
|
low = mid + 1;
|
||||||
|
|
||||||
|
// Too high.
|
||||||
|
else if(cmp > 0.0)
|
||||||
|
high = mid - 1;
|
||||||
|
|
||||||
|
// Key found.
|
||||||
|
else
|
||||||
|
return mid;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Key not found.
|
||||||
|
return ~low;
|
||||||
|
}
|
||||||
28
node_modules/binary-search/package.json
generated
vendored
Normal file
28
node_modules/binary-search/package.json
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "binary-search",
|
||||||
|
"version": "1.3.6",
|
||||||
|
"description": "tiny binary search function with comparators",
|
||||||
|
"license": "CC0-1.0",
|
||||||
|
"typings": "./binary-search.d.ts",
|
||||||
|
"author": {
|
||||||
|
"name": "The Dark Sky Company, LLC",
|
||||||
|
"email": "support@darkskyapp.com"
|
||||||
|
},
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "Darcy Parker",
|
||||||
|
"web": "https://github.com/darcyparker"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/darkskyapp/binary-search.git"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"chai": "^4.2.0",
|
||||||
|
"mocha": "^5.2.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "mocha"
|
||||||
|
}
|
||||||
|
}
|
||||||
46
node_modules/binary-search/test.js
generated
vendored
Normal file
46
node_modules/binary-search/test.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
var expect = require("chai").expect;
|
||||||
|
|
||||||
|
describe("binarysearch", function() {
|
||||||
|
var bs = require("./"),
|
||||||
|
arr = [1, 2, 2, 2, 3, 5, 9],
|
||||||
|
cmp = function(a, b) { return a - b; };
|
||||||
|
|
||||||
|
it("should bail if not passed an array", function() {
|
||||||
|
expect(function() { bs(undefined, 3, cmp); }).to.throw(TypeError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should bail if not passed a comparator", function() {
|
||||||
|
expect(function() { bs(arr, 3, undefined); }).to.throw(TypeError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return the index of an item in a sorted array", function() {
|
||||||
|
expect(bs(arr, 3, cmp)).to.equal(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return the index of where the item would go plus one, negated, if the item is not found", function() {
|
||||||
|
expect(bs(arr, 4, cmp)).to.equal(-6);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return any valid index if an item exists multiple times in the array", function() {
|
||||||
|
expect(bs(arr, 2, cmp)).to.equal(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should work even on empty arrays", function() {
|
||||||
|
expect(bs([], 42, cmp)).to.equal(-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should work even on arrays of doubles", function() {
|
||||||
|
expect(bs([0.0, 0.1, 0.2, 0.3, 0.4], 0.25, cmp)).to.equal(-4);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should pass the index and array parameters to the comparator", function() {
|
||||||
|
var indexes = [],
|
||||||
|
indexCmp = function(a, b, i, array) {
|
||||||
|
expect(array).to.equal(arr);
|
||||||
|
indexes.push(i);
|
||||||
|
return cmp(a, b);
|
||||||
|
};
|
||||||
|
bs(arr, 3, indexCmp);
|
||||||
|
expect(indexes).to.deep.equal([3, 5, 4])
|
||||||
|
});
|
||||||
|
});
|
||||||
18
node_modules/char-width-table-consumer/CHANGELOG.md
generated
vendored
Normal file
18
node_modules/char-width-table-consumer/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 1.0.0 – Apr 12, 2019
|
||||||
|
|
||||||
|
- Update dependencies.
|
||||||
|
- Same API as previous release.
|
||||||
|
|
||||||
|
## 0.2.1 – Nov 15, 2018
|
||||||
|
|
||||||
|
No external changes.
|
||||||
|
|
||||||
|
## 0.2.0 – Nov 13, 2018
|
||||||
|
|
||||||
|
- Add `loadConsumerSync()` function.
|
||||||
|
|
||||||
|
## 0.1.0 – Nov 13, 2018
|
||||||
|
|
||||||
|
Initial release.
|
||||||
21
node_modules/char-width-table-consumer/LICENSE
generated
vendored
Normal file
21
node_modules/char-width-table-consumer/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2018 Metabolize LLC
|
||||||
|
|
||||||
|
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.
|
||||||
32
node_modules/char-width-table-consumer/README.md
generated
vendored
Normal file
32
node_modules/char-width-table-consumer/README.md
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# char-width-table-consumer
|
||||||
|
|
||||||
|
[][npm]
|
||||||
|
[][npm]
|
||||||
|
[][build]
|
||||||
|
[][prettier]
|
||||||
|
[][lerna]
|
||||||
|
|
||||||
|
[npm]: https://npmjs.com/char-width-table-consumer
|
||||||
|
[build]: https://circleci.com/gh/metabolize/anafanafo/tree/master
|
||||||
|
[prettier]: https://prettier.io/
|
||||||
|
[lerna]: https://lernajs.io/
|
||||||
|
|
||||||
|
Measure text using a character width table.
|
||||||
|
|
||||||
|
[puppeteer]: https://pptr.dev/
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
This library allows efficient text measuring using a character width table.
|
||||||
|
Create the tables using companion package [char-width-table-builder][].
|
||||||
|
|
||||||
|
This performs a simple lookup, without considering kerning.
|
||||||
|
|
||||||
|
Built with [Shields][] in mind.
|
||||||
|
|
||||||
|
[char-width-table-builder]: https://www.npmjs.com/package/char-width-table-builder
|
||||||
|
[shields]: https://github.com/badges/shields/
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is licensed under the MIT license.
|
||||||
16
node_modules/char-width-table-consumer/package.json
generated
vendored
Normal file
16
node_modules/char-width-table-consumer/package.json
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "char-width-table-consumer",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"repository": "metabolize/anafanafo",
|
||||||
|
"description": "Measure text using a character width table",
|
||||||
|
"main": "src",
|
||||||
|
"scripts": {
|
||||||
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"author": "Metabolize",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"binary-search": "^1.3.5"
|
||||||
|
},
|
||||||
|
"gitHead": "4bd230d372ffe93cd9bf7f036b83be6ef5dab75e"
|
||||||
|
}
|
||||||
79
node_modules/char-width-table-consumer/src/consumer.js
generated
vendored
Normal file
79
node_modules/char-width-table-consumer/src/consumer.js
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const fs = require('fs')
|
||||||
|
const bs = require('binary-search')
|
||||||
|
const { promisify } = require('util')
|
||||||
|
const readFile = promisify(fs.readFile)
|
||||||
|
|
||||||
|
module.exports = class CharWidthTableConsumer {
|
||||||
|
constructor(data) {
|
||||||
|
this.data = data
|
||||||
|
this.emWidth = this.widthOf('m')
|
||||||
|
}
|
||||||
|
|
||||||
|
static create(data) {
|
||||||
|
return new CharWidthTableConsumer(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
static async load(path) {
|
||||||
|
const json = await readFile(path)
|
||||||
|
const data = JSON.parse(json)
|
||||||
|
return new CharWidthTableConsumer(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
static loadSync(path) {
|
||||||
|
const json = fs.readFileSync(path)
|
||||||
|
const data = JSON.parse(json)
|
||||||
|
return new CharWidthTableConsumer(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
static isControlChar(charCode) {
|
||||||
|
return charCode <= 31 || charCode === 127
|
||||||
|
}
|
||||||
|
|
||||||
|
widthOfCharCode(charCode) {
|
||||||
|
if (this.constructor.isControlChar(charCode)) {
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://github.com/darkskyapp/binary-search/pull/18
|
||||||
|
const index = bs(this.data, charCode, ([lower], needle) => lower - needle)
|
||||||
|
if (index >= 0) {
|
||||||
|
// The index matches the beginning of a range.
|
||||||
|
const [, , width] = this.data[index]
|
||||||
|
return width
|
||||||
|
} else {
|
||||||
|
// The index does not match the beginning of a range, which means it
|
||||||
|
// should be in the preceeding range A return value of `-x` means the
|
||||||
|
// needle would be at `x - 1`, and we want to check the element before
|
||||||
|
// that.
|
||||||
|
const candidateIndex = -index - 2
|
||||||
|
const [lower, upper, width] = this.data[candidateIndex]
|
||||||
|
if (charCode >= lower && charCode <= upper) {
|
||||||
|
return width
|
||||||
|
} else {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
widthOf(text, { guess = true } = {}) {
|
||||||
|
// Array.from() will split a string into an array of strings, each of
|
||||||
|
// which contains a single code point.
|
||||||
|
// https://stackoverflow.com/a/42596897/893113
|
||||||
|
return Array.from(text).reduce((accumWidth, char) => {
|
||||||
|
const charWidth = this.widthOfCharCode(char.codePointAt(0))
|
||||||
|
if (charWidth === undefined) {
|
||||||
|
if (guess) {
|
||||||
|
return accumWidth + this.emWidth
|
||||||
|
} else {
|
||||||
|
throw Error(
|
||||||
|
`No width available for character code ${char.codePointAt(0)}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return accumWidth + charWidth
|
||||||
|
}
|
||||||
|
}, 0.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
16
node_modules/char-width-table-consumer/src/index.js
generated
vendored
Normal file
16
node_modules/char-width-table-consumer/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const CharWidthTableConsumer = require('./consumer')
|
||||||
|
|
||||||
|
const {
|
||||||
|
create: createConsumer,
|
||||||
|
load: loadConsumer,
|
||||||
|
loadSync: loadConsumerSync,
|
||||||
|
} = CharWidthTableConsumer
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
createConsumer,
|
||||||
|
loadConsumer,
|
||||||
|
loadConsumerSync,
|
||||||
|
CharWidthTableConsumer,
|
||||||
|
}
|
||||||
1
node_modules/color-convert/.travis.yml
generated
vendored
Normal file
1
node_modules/color-convert/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
language: node_js
|
||||||
4
node_modules/color-convert/CHANGELOG.md
generated
vendored
Normal file
4
node_modules/color-convert/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# 0.5.3 - 2015-06-02
|
||||||
|
|
||||||
|
- Fixed: hsl2hsv does not return `NaN` anymore when using `[0,0,0]`
|
||||||
|
([#15](https://github.com/harthur/color-convert/issues/15))
|
||||||
21
node_modules/color-convert/LICENSE
generated
vendored
Normal file
21
node_modules/color-convert/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
Copyright (c) 2011 Heather Arthur <fayearthur@gmail.com>
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
57
node_modules/color-convert/README.md
generated
vendored
Normal file
57
node_modules/color-convert/README.md
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# color-convert [](https://travis-ci.org/harthur/color-convert)
|
||||||
|
Color-convert is a color conversion library for JavaScript and node. It converts all ways between `rgb`, `hsl`, `hsv`, `hwb`, `cmyk`, and CSS keywords:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var converter = require("color-convert")();
|
||||||
|
|
||||||
|
converter.rgb(140, 200, 100).hsl() // [96, 48, 59]
|
||||||
|
|
||||||
|
converter.keyword("blue").rgb() // [0, 0, 255]
|
||||||
|
```
|
||||||
|
|
||||||
|
# Install
|
||||||
|
|
||||||
|
```console
|
||||||
|
npm install color-convert
|
||||||
|
```
|
||||||
|
|
||||||
|
# API
|
||||||
|
|
||||||
|
Color-convert exports a converter object with getter/setter methods for each color space. It caches conversions:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var converter = require("color-convert")();
|
||||||
|
|
||||||
|
converter.rgb(140, 200, 100).hsl() // [96, 48, 59]
|
||||||
|
|
||||||
|
converter.rgb([140, 200, 100]) // args can be an array
|
||||||
|
```
|
||||||
|
|
||||||
|
### Plain functions
|
||||||
|
Get direct conversion functions with no fancy objects:
|
||||||
|
|
||||||
|
```js
|
||||||
|
require("color-convert").rgb2hsl([140, 200, 100]); // [96, 48, 59]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Unrounded
|
||||||
|
To get the unrounded conversion, append `Raw` to the function name:
|
||||||
|
|
||||||
|
```js
|
||||||
|
convert.rgb2hslRaw([140, 200, 100]); // [95.99999999999999, 47.619047619047606, 58.82352941176471]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hash
|
||||||
|
There's also a hash of the conversion functions keyed first by the "from" color space, then by the "to" color space:
|
||||||
|
|
||||||
|
```js
|
||||||
|
convert["hsl"]["hsv"]([160, 0, 20]) == convert.hsl2hsv([160, 0, 20])
|
||||||
|
```
|
||||||
|
|
||||||
|
### Other spaces
|
||||||
|
|
||||||
|
There are some conversions from rgb (sRGB) to XYZ and LAB too, available as `rgb2xyz()`, `rgb2lab()`, `xyz2rgb()`, and `xyz2lab()`.
|
||||||
|
|
||||||
|
# Contribute
|
||||||
|
|
||||||
|
Please fork, add conversions, figure out color profile stuff for XYZ, LAB, etc. This is meant to be a basic library that can be used by other libraries to wrap color calculations in some cool way.
|
||||||
9
node_modules/color-convert/component.json
generated
vendored
Normal file
9
node_modules/color-convert/component.json
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"name": "color-convert",
|
||||||
|
"description": "Plain color conversion functions",
|
||||||
|
"version": "0.5.3",
|
||||||
|
"author": "Heather Arthur <fayearthur@gmail.com>",
|
||||||
|
"repository": "harthur/color-convert",
|
||||||
|
"keywords": ["color", "colour", "rgb"],
|
||||||
|
"scripts": ["index.js", "conversions.js"]
|
||||||
|
}
|
||||||
698
node_modules/color-convert/conversions.js
generated
vendored
Normal file
698
node_modules/color-convert/conversions.js
generated
vendored
Normal file
@@ -0,0 +1,698 @@
|
|||||||
|
/* MIT license */
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
rgb2hsl: rgb2hsl,
|
||||||
|
rgb2hsv: rgb2hsv,
|
||||||
|
rgb2hwb: rgb2hwb,
|
||||||
|
rgb2cmyk: rgb2cmyk,
|
||||||
|
rgb2keyword: rgb2keyword,
|
||||||
|
rgb2xyz: rgb2xyz,
|
||||||
|
rgb2lab: rgb2lab,
|
||||||
|
rgb2lch: rgb2lch,
|
||||||
|
|
||||||
|
hsl2rgb: hsl2rgb,
|
||||||
|
hsl2hsv: hsl2hsv,
|
||||||
|
hsl2hwb: hsl2hwb,
|
||||||
|
hsl2cmyk: hsl2cmyk,
|
||||||
|
hsl2keyword: hsl2keyword,
|
||||||
|
|
||||||
|
hsv2rgb: hsv2rgb,
|
||||||
|
hsv2hsl: hsv2hsl,
|
||||||
|
hsv2hwb: hsv2hwb,
|
||||||
|
hsv2cmyk: hsv2cmyk,
|
||||||
|
hsv2keyword: hsv2keyword,
|
||||||
|
|
||||||
|
hwb2rgb: hwb2rgb,
|
||||||
|
hwb2hsl: hwb2hsl,
|
||||||
|
hwb2hsv: hwb2hsv,
|
||||||
|
hwb2cmyk: hwb2cmyk,
|
||||||
|
hwb2keyword: hwb2keyword,
|
||||||
|
|
||||||
|
cmyk2rgb: cmyk2rgb,
|
||||||
|
cmyk2hsl: cmyk2hsl,
|
||||||
|
cmyk2hsv: cmyk2hsv,
|
||||||
|
cmyk2hwb: cmyk2hwb,
|
||||||
|
cmyk2keyword: cmyk2keyword,
|
||||||
|
|
||||||
|
keyword2rgb: keyword2rgb,
|
||||||
|
keyword2hsl: keyword2hsl,
|
||||||
|
keyword2hsv: keyword2hsv,
|
||||||
|
keyword2hwb: keyword2hwb,
|
||||||
|
keyword2cmyk: keyword2cmyk,
|
||||||
|
keyword2lab: keyword2lab,
|
||||||
|
keyword2xyz: keyword2xyz,
|
||||||
|
|
||||||
|
xyz2rgb: xyz2rgb,
|
||||||
|
xyz2lab: xyz2lab,
|
||||||
|
xyz2lch: xyz2lch,
|
||||||
|
|
||||||
|
lab2xyz: lab2xyz,
|
||||||
|
lab2rgb: lab2rgb,
|
||||||
|
lab2lch: lab2lch,
|
||||||
|
|
||||||
|
lch2lab: lch2lab,
|
||||||
|
lch2xyz: lch2xyz,
|
||||||
|
lch2rgb: lch2rgb
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function rgb2hsl(rgb) {
|
||||||
|
var r = rgb[0]/255,
|
||||||
|
g = rgb[1]/255,
|
||||||
|
b = rgb[2]/255,
|
||||||
|
min = Math.min(r, g, b),
|
||||||
|
max = Math.max(r, g, b),
|
||||||
|
delta = max - min,
|
||||||
|
h, s, l;
|
||||||
|
|
||||||
|
if (max == min)
|
||||||
|
h = 0;
|
||||||
|
else if (r == max)
|
||||||
|
h = (g - b) / delta;
|
||||||
|
else if (g == max)
|
||||||
|
h = 2 + (b - r) / delta;
|
||||||
|
else if (b == max)
|
||||||
|
h = 4 + (r - g)/ delta;
|
||||||
|
|
||||||
|
h = Math.min(h * 60, 360);
|
||||||
|
|
||||||
|
if (h < 0)
|
||||||
|
h += 360;
|
||||||
|
|
||||||
|
l = (min + max) / 2;
|
||||||
|
|
||||||
|
if (max == min)
|
||||||
|
s = 0;
|
||||||
|
else if (l <= 0.5)
|
||||||
|
s = delta / (max + min);
|
||||||
|
else
|
||||||
|
s = delta / (2 - max - min);
|
||||||
|
|
||||||
|
return [h, s * 100, l * 100];
|
||||||
|
}
|
||||||
|
|
||||||
|
function rgb2hsv(rgb) {
|
||||||
|
var r = rgb[0],
|
||||||
|
g = rgb[1],
|
||||||
|
b = rgb[2],
|
||||||
|
min = Math.min(r, g, b),
|
||||||
|
max = Math.max(r, g, b),
|
||||||
|
delta = max - min,
|
||||||
|
h, s, v;
|
||||||
|
|
||||||
|
if (max == 0)
|
||||||
|
s = 0;
|
||||||
|
else
|
||||||
|
s = (delta/max * 1000)/10;
|
||||||
|
|
||||||
|
if (max == min)
|
||||||
|
h = 0;
|
||||||
|
else if (r == max)
|
||||||
|
h = (g - b) / delta;
|
||||||
|
else if (g == max)
|
||||||
|
h = 2 + (b - r) / delta;
|
||||||
|
else if (b == max)
|
||||||
|
h = 4 + (r - g) / delta;
|
||||||
|
|
||||||
|
h = Math.min(h * 60, 360);
|
||||||
|
|
||||||
|
if (h < 0)
|
||||||
|
h += 360;
|
||||||
|
|
||||||
|
v = ((max / 255) * 1000) / 10;
|
||||||
|
|
||||||
|
return [h, s, v];
|
||||||
|
}
|
||||||
|
|
||||||
|
function rgb2hwb(rgb) {
|
||||||
|
var r = rgb[0],
|
||||||
|
g = rgb[1],
|
||||||
|
b = rgb[2],
|
||||||
|
h = rgb2hsl(rgb)[0],
|
||||||
|
w = 1/255 * Math.min(r, Math.min(g, b)),
|
||||||
|
b = 1 - 1/255 * Math.max(r, Math.max(g, b));
|
||||||
|
|
||||||
|
return [h, w * 100, b * 100];
|
||||||
|
}
|
||||||
|
|
||||||
|
function rgb2cmyk(rgb) {
|
||||||
|
var r = rgb[0] / 255,
|
||||||
|
g = rgb[1] / 255,
|
||||||
|
b = rgb[2] / 255,
|
||||||
|
c, m, y, k;
|
||||||
|
|
||||||
|
k = Math.min(1 - r, 1 - g, 1 - b);
|
||||||
|
c = (1 - r - k) / (1 - k) || 0;
|
||||||
|
m = (1 - g - k) / (1 - k) || 0;
|
||||||
|
y = (1 - b - k) / (1 - k) || 0;
|
||||||
|
return [c * 100, m * 100, y * 100, k * 100];
|
||||||
|
}
|
||||||
|
|
||||||
|
function rgb2keyword(rgb) {
|
||||||
|
return reverseKeywords[JSON.stringify(rgb)];
|
||||||
|
}
|
||||||
|
|
||||||
|
function rgb2xyz(rgb) {
|
||||||
|
var r = rgb[0] / 255,
|
||||||
|
g = rgb[1] / 255,
|
||||||
|
b = rgb[2] / 255;
|
||||||
|
|
||||||
|
// assume sRGB
|
||||||
|
r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
|
||||||
|
g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
|
||||||
|
b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
|
||||||
|
|
||||||
|
var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
|
||||||
|
var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
|
||||||
|
var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
|
||||||
|
|
||||||
|
return [x * 100, y *100, z * 100];
|
||||||
|
}
|
||||||
|
|
||||||
|
function rgb2lab(rgb) {
|
||||||
|
var xyz = rgb2xyz(rgb),
|
||||||
|
x = xyz[0],
|
||||||
|
y = xyz[1],
|
||||||
|
z = xyz[2],
|
||||||
|
l, a, b;
|
||||||
|
|
||||||
|
x /= 95.047;
|
||||||
|
y /= 100;
|
||||||
|
z /= 108.883;
|
||||||
|
|
||||||
|
x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
|
||||||
|
y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
|
||||||
|
z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
|
||||||
|
|
||||||
|
l = (116 * y) - 16;
|
||||||
|
a = 500 * (x - y);
|
||||||
|
b = 200 * (y - z);
|
||||||
|
|
||||||
|
return [l, a, b];
|
||||||
|
}
|
||||||
|
|
||||||
|
function rgb2lch(args) {
|
||||||
|
return lab2lch(rgb2lab(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function hsl2rgb(hsl) {
|
||||||
|
var h = hsl[0] / 360,
|
||||||
|
s = hsl[1] / 100,
|
||||||
|
l = hsl[2] / 100,
|
||||||
|
t1, t2, t3, rgb, val;
|
||||||
|
|
||||||
|
if (s == 0) {
|
||||||
|
val = l * 255;
|
||||||
|
return [val, val, val];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l < 0.5)
|
||||||
|
t2 = l * (1 + s);
|
||||||
|
else
|
||||||
|
t2 = l + s - l * s;
|
||||||
|
t1 = 2 * l - t2;
|
||||||
|
|
||||||
|
rgb = [0, 0, 0];
|
||||||
|
for (var i = 0; i < 3; i++) {
|
||||||
|
t3 = h + 1 / 3 * - (i - 1);
|
||||||
|
t3 < 0 && t3++;
|
||||||
|
t3 > 1 && t3--;
|
||||||
|
|
||||||
|
if (6 * t3 < 1)
|
||||||
|
val = t1 + (t2 - t1) * 6 * t3;
|
||||||
|
else if (2 * t3 < 1)
|
||||||
|
val = t2;
|
||||||
|
else if (3 * t3 < 2)
|
||||||
|
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
||||||
|
else
|
||||||
|
val = t1;
|
||||||
|
|
||||||
|
rgb[i] = val * 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
function hsl2hsv(hsl) {
|
||||||
|
var h = hsl[0],
|
||||||
|
s = hsl[1] / 100,
|
||||||
|
l = hsl[2] / 100,
|
||||||
|
sv, v;
|
||||||
|
|
||||||
|
if(l === 0) {
|
||||||
|
// no need to do calc on black
|
||||||
|
// also avoids divide by 0 error
|
||||||
|
return [0, 0, 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
l *= 2;
|
||||||
|
s *= (l <= 1) ? l : 2 - l;
|
||||||
|
v = (l + s) / 2;
|
||||||
|
sv = (2 * s) / (l + s);
|
||||||
|
return [h, sv * 100, v * 100];
|
||||||
|
}
|
||||||
|
|
||||||
|
function hsl2hwb(args) {
|
||||||
|
return rgb2hwb(hsl2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function hsl2cmyk(args) {
|
||||||
|
return rgb2cmyk(hsl2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function hsl2keyword(args) {
|
||||||
|
return rgb2keyword(hsl2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function hsv2rgb(hsv) {
|
||||||
|
var h = hsv[0] / 60,
|
||||||
|
s = hsv[1] / 100,
|
||||||
|
v = hsv[2] / 100,
|
||||||
|
hi = Math.floor(h) % 6;
|
||||||
|
|
||||||
|
var f = h - Math.floor(h),
|
||||||
|
p = 255 * v * (1 - s),
|
||||||
|
q = 255 * v * (1 - (s * f)),
|
||||||
|
t = 255 * v * (1 - (s * (1 - f))),
|
||||||
|
v = 255 * v;
|
||||||
|
|
||||||
|
switch(hi) {
|
||||||
|
case 0:
|
||||||
|
return [v, t, p];
|
||||||
|
case 1:
|
||||||
|
return [q, v, p];
|
||||||
|
case 2:
|
||||||
|
return [p, v, t];
|
||||||
|
case 3:
|
||||||
|
return [p, q, v];
|
||||||
|
case 4:
|
||||||
|
return [t, p, v];
|
||||||
|
case 5:
|
||||||
|
return [v, p, q];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hsv2hsl(hsv) {
|
||||||
|
var h = hsv[0],
|
||||||
|
s = hsv[1] / 100,
|
||||||
|
v = hsv[2] / 100,
|
||||||
|
sl, l;
|
||||||
|
|
||||||
|
l = (2 - s) * v;
|
||||||
|
sl = s * v;
|
||||||
|
sl /= (l <= 1) ? l : 2 - l;
|
||||||
|
sl = sl || 0;
|
||||||
|
l /= 2;
|
||||||
|
return [h, sl * 100, l * 100];
|
||||||
|
}
|
||||||
|
|
||||||
|
function hsv2hwb(args) {
|
||||||
|
return rgb2hwb(hsv2rgb(args))
|
||||||
|
}
|
||||||
|
|
||||||
|
function hsv2cmyk(args) {
|
||||||
|
return rgb2cmyk(hsv2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function hsv2keyword(args) {
|
||||||
|
return rgb2keyword(hsv2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
|
||||||
|
function hwb2rgb(hwb) {
|
||||||
|
var h = hwb[0] / 360,
|
||||||
|
wh = hwb[1] / 100,
|
||||||
|
bl = hwb[2] / 100,
|
||||||
|
ratio = wh + bl,
|
||||||
|
i, v, f, n;
|
||||||
|
|
||||||
|
// wh + bl cant be > 1
|
||||||
|
if (ratio > 1) {
|
||||||
|
wh /= ratio;
|
||||||
|
bl /= ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
i = Math.floor(6 * h);
|
||||||
|
v = 1 - bl;
|
||||||
|
f = 6 * h - i;
|
||||||
|
if ((i & 0x01) != 0) {
|
||||||
|
f = 1 - f;
|
||||||
|
}
|
||||||
|
n = wh + f * (v - wh); // linear interpolation
|
||||||
|
|
||||||
|
switch (i) {
|
||||||
|
default:
|
||||||
|
case 6:
|
||||||
|
case 0: r = v; g = n; b = wh; break;
|
||||||
|
case 1: r = n; g = v; b = wh; break;
|
||||||
|
case 2: r = wh; g = v; b = n; break;
|
||||||
|
case 3: r = wh; g = n; b = v; break;
|
||||||
|
case 4: r = n; g = wh; b = v; break;
|
||||||
|
case 5: r = v; g = wh; b = n; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [r * 255, g * 255, b * 255];
|
||||||
|
}
|
||||||
|
|
||||||
|
function hwb2hsl(args) {
|
||||||
|
return rgb2hsl(hwb2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function hwb2hsv(args) {
|
||||||
|
return rgb2hsv(hwb2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function hwb2cmyk(args) {
|
||||||
|
return rgb2cmyk(hwb2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function hwb2keyword(args) {
|
||||||
|
return rgb2keyword(hwb2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function cmyk2rgb(cmyk) {
|
||||||
|
var c = cmyk[0] / 100,
|
||||||
|
m = cmyk[1] / 100,
|
||||||
|
y = cmyk[2] / 100,
|
||||||
|
k = cmyk[3] / 100,
|
||||||
|
r, g, b;
|
||||||
|
|
||||||
|
r = 1 - Math.min(1, c * (1 - k) + k);
|
||||||
|
g = 1 - Math.min(1, m * (1 - k) + k);
|
||||||
|
b = 1 - Math.min(1, y * (1 - k) + k);
|
||||||
|
return [r * 255, g * 255, b * 255];
|
||||||
|
}
|
||||||
|
|
||||||
|
function cmyk2hsl(args) {
|
||||||
|
return rgb2hsl(cmyk2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function cmyk2hsv(args) {
|
||||||
|
return rgb2hsv(cmyk2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function cmyk2hwb(args) {
|
||||||
|
return rgb2hwb(cmyk2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function cmyk2keyword(args) {
|
||||||
|
return rgb2keyword(cmyk2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function xyz2rgb(xyz) {
|
||||||
|
var x = xyz[0] / 100,
|
||||||
|
y = xyz[1] / 100,
|
||||||
|
z = xyz[2] / 100,
|
||||||
|
r, g, b;
|
||||||
|
|
||||||
|
r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
|
||||||
|
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
|
||||||
|
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
|
||||||
|
|
||||||
|
// assume sRGB
|
||||||
|
r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
|
||||||
|
: r = (r * 12.92);
|
||||||
|
|
||||||
|
g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
|
||||||
|
: g = (g * 12.92);
|
||||||
|
|
||||||
|
b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
|
||||||
|
: b = (b * 12.92);
|
||||||
|
|
||||||
|
r = Math.min(Math.max(0, r), 1);
|
||||||
|
g = Math.min(Math.max(0, g), 1);
|
||||||
|
b = Math.min(Math.max(0, b), 1);
|
||||||
|
|
||||||
|
return [r * 255, g * 255, b * 255];
|
||||||
|
}
|
||||||
|
|
||||||
|
function xyz2lab(xyz) {
|
||||||
|
var x = xyz[0],
|
||||||
|
y = xyz[1],
|
||||||
|
z = xyz[2],
|
||||||
|
l, a, b;
|
||||||
|
|
||||||
|
x /= 95.047;
|
||||||
|
y /= 100;
|
||||||
|
z /= 108.883;
|
||||||
|
|
||||||
|
x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
|
||||||
|
y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
|
||||||
|
z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
|
||||||
|
|
||||||
|
l = (116 * y) - 16;
|
||||||
|
a = 500 * (x - y);
|
||||||
|
b = 200 * (y - z);
|
||||||
|
|
||||||
|
return [l, a, b];
|
||||||
|
}
|
||||||
|
|
||||||
|
function xyz2lch(args) {
|
||||||
|
return lab2lch(xyz2lab(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function lab2xyz(lab) {
|
||||||
|
var l = lab[0],
|
||||||
|
a = lab[1],
|
||||||
|
b = lab[2],
|
||||||
|
x, y, z, y2;
|
||||||
|
|
||||||
|
if (l <= 8) {
|
||||||
|
y = (l * 100) / 903.3;
|
||||||
|
y2 = (7.787 * (y / 100)) + (16 / 116);
|
||||||
|
} else {
|
||||||
|
y = 100 * Math.pow((l + 16) / 116, 3);
|
||||||
|
y2 = Math.pow(y / 100, 1/3);
|
||||||
|
}
|
||||||
|
|
||||||
|
x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
|
||||||
|
|
||||||
|
z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
|
||||||
|
|
||||||
|
return [x, y, z];
|
||||||
|
}
|
||||||
|
|
||||||
|
function lab2lch(lab) {
|
||||||
|
var l = lab[0],
|
||||||
|
a = lab[1],
|
||||||
|
b = lab[2],
|
||||||
|
hr, h, c;
|
||||||
|
|
||||||
|
hr = Math.atan2(b, a);
|
||||||
|
h = hr * 360 / 2 / Math.PI;
|
||||||
|
if (h < 0) {
|
||||||
|
h += 360;
|
||||||
|
}
|
||||||
|
c = Math.sqrt(a * a + b * b);
|
||||||
|
return [l, c, h];
|
||||||
|
}
|
||||||
|
|
||||||
|
function lab2rgb(args) {
|
||||||
|
return xyz2rgb(lab2xyz(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function lch2lab(lch) {
|
||||||
|
var l = lch[0],
|
||||||
|
c = lch[1],
|
||||||
|
h = lch[2],
|
||||||
|
a, b, hr;
|
||||||
|
|
||||||
|
hr = h / 360 * 2 * Math.PI;
|
||||||
|
a = c * Math.cos(hr);
|
||||||
|
b = c * Math.sin(hr);
|
||||||
|
return [l, a, b];
|
||||||
|
}
|
||||||
|
|
||||||
|
function lch2xyz(args) {
|
||||||
|
return lab2xyz(lch2lab(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function lch2rgb(args) {
|
||||||
|
return lab2rgb(lch2lab(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyword2rgb(keyword) {
|
||||||
|
return cssKeywords[keyword];
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyword2hsl(args) {
|
||||||
|
return rgb2hsl(keyword2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyword2hsv(args) {
|
||||||
|
return rgb2hsv(keyword2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyword2hwb(args) {
|
||||||
|
return rgb2hwb(keyword2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyword2cmyk(args) {
|
||||||
|
return rgb2cmyk(keyword2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyword2lab(args) {
|
||||||
|
return rgb2lab(keyword2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyword2xyz(args) {
|
||||||
|
return rgb2xyz(keyword2rgb(args));
|
||||||
|
}
|
||||||
|
|
||||||
|
var cssKeywords = {
|
||||||
|
aliceblue: [240,248,255],
|
||||||
|
antiquewhite: [250,235,215],
|
||||||
|
aqua: [0,255,255],
|
||||||
|
aquamarine: [127,255,212],
|
||||||
|
azure: [240,255,255],
|
||||||
|
beige: [245,245,220],
|
||||||
|
bisque: [255,228,196],
|
||||||
|
black: [0,0,0],
|
||||||
|
blanchedalmond: [255,235,205],
|
||||||
|
blue: [0,0,255],
|
||||||
|
blueviolet: [138,43,226],
|
||||||
|
brown: [165,42,42],
|
||||||
|
burlywood: [222,184,135],
|
||||||
|
cadetblue: [95,158,160],
|
||||||
|
chartreuse: [127,255,0],
|
||||||
|
chocolate: [210,105,30],
|
||||||
|
coral: [255,127,80],
|
||||||
|
cornflowerblue: [100,149,237],
|
||||||
|
cornsilk: [255,248,220],
|
||||||
|
crimson: [220,20,60],
|
||||||
|
cyan: [0,255,255],
|
||||||
|
darkblue: [0,0,139],
|
||||||
|
darkcyan: [0,139,139],
|
||||||
|
darkgoldenrod: [184,134,11],
|
||||||
|
darkgray: [169,169,169],
|
||||||
|
darkgreen: [0,100,0],
|
||||||
|
darkgrey: [169,169,169],
|
||||||
|
darkkhaki: [189,183,107],
|
||||||
|
darkmagenta: [139,0,139],
|
||||||
|
darkolivegreen: [85,107,47],
|
||||||
|
darkorange: [255,140,0],
|
||||||
|
darkorchid: [153,50,204],
|
||||||
|
darkred: [139,0,0],
|
||||||
|
darksalmon: [233,150,122],
|
||||||
|
darkseagreen: [143,188,143],
|
||||||
|
darkslateblue: [72,61,139],
|
||||||
|
darkslategray: [47,79,79],
|
||||||
|
darkslategrey: [47,79,79],
|
||||||
|
darkturquoise: [0,206,209],
|
||||||
|
darkviolet: [148,0,211],
|
||||||
|
deeppink: [255,20,147],
|
||||||
|
deepskyblue: [0,191,255],
|
||||||
|
dimgray: [105,105,105],
|
||||||
|
dimgrey: [105,105,105],
|
||||||
|
dodgerblue: [30,144,255],
|
||||||
|
firebrick: [178,34,34],
|
||||||
|
floralwhite: [255,250,240],
|
||||||
|
forestgreen: [34,139,34],
|
||||||
|
fuchsia: [255,0,255],
|
||||||
|
gainsboro: [220,220,220],
|
||||||
|
ghostwhite: [248,248,255],
|
||||||
|
gold: [255,215,0],
|
||||||
|
goldenrod: [218,165,32],
|
||||||
|
gray: [128,128,128],
|
||||||
|
green: [0,128,0],
|
||||||
|
greenyellow: [173,255,47],
|
||||||
|
grey: [128,128,128],
|
||||||
|
honeydew: [240,255,240],
|
||||||
|
hotpink: [255,105,180],
|
||||||
|
indianred: [205,92,92],
|
||||||
|
indigo: [75,0,130],
|
||||||
|
ivory: [255,255,240],
|
||||||
|
khaki: [240,230,140],
|
||||||
|
lavender: [230,230,250],
|
||||||
|
lavenderblush: [255,240,245],
|
||||||
|
lawngreen: [124,252,0],
|
||||||
|
lemonchiffon: [255,250,205],
|
||||||
|
lightblue: [173,216,230],
|
||||||
|
lightcoral: [240,128,128],
|
||||||
|
lightcyan: [224,255,255],
|
||||||
|
lightgoldenrodyellow: [250,250,210],
|
||||||
|
lightgray: [211,211,211],
|
||||||
|
lightgreen: [144,238,144],
|
||||||
|
lightgrey: [211,211,211],
|
||||||
|
lightpink: [255,182,193],
|
||||||
|
lightsalmon: [255,160,122],
|
||||||
|
lightseagreen: [32,178,170],
|
||||||
|
lightskyblue: [135,206,250],
|
||||||
|
lightslategray: [119,136,153],
|
||||||
|
lightslategrey: [119,136,153],
|
||||||
|
lightsteelblue: [176,196,222],
|
||||||
|
lightyellow: [255,255,224],
|
||||||
|
lime: [0,255,0],
|
||||||
|
limegreen: [50,205,50],
|
||||||
|
linen: [250,240,230],
|
||||||
|
magenta: [255,0,255],
|
||||||
|
maroon: [128,0,0],
|
||||||
|
mediumaquamarine: [102,205,170],
|
||||||
|
mediumblue: [0,0,205],
|
||||||
|
mediumorchid: [186,85,211],
|
||||||
|
mediumpurple: [147,112,219],
|
||||||
|
mediumseagreen: [60,179,113],
|
||||||
|
mediumslateblue: [123,104,238],
|
||||||
|
mediumspringgreen: [0,250,154],
|
||||||
|
mediumturquoise: [72,209,204],
|
||||||
|
mediumvioletred: [199,21,133],
|
||||||
|
midnightblue: [25,25,112],
|
||||||
|
mintcream: [245,255,250],
|
||||||
|
mistyrose: [255,228,225],
|
||||||
|
moccasin: [255,228,181],
|
||||||
|
navajowhite: [255,222,173],
|
||||||
|
navy: [0,0,128],
|
||||||
|
oldlace: [253,245,230],
|
||||||
|
olive: [128,128,0],
|
||||||
|
olivedrab: [107,142,35],
|
||||||
|
orange: [255,165,0],
|
||||||
|
orangered: [255,69,0],
|
||||||
|
orchid: [218,112,214],
|
||||||
|
palegoldenrod: [238,232,170],
|
||||||
|
palegreen: [152,251,152],
|
||||||
|
paleturquoise: [175,238,238],
|
||||||
|
palevioletred: [219,112,147],
|
||||||
|
papayawhip: [255,239,213],
|
||||||
|
peachpuff: [255,218,185],
|
||||||
|
peru: [205,133,63],
|
||||||
|
pink: [255,192,203],
|
||||||
|
plum: [221,160,221],
|
||||||
|
powderblue: [176,224,230],
|
||||||
|
purple: [128,0,128],
|
||||||
|
rebeccapurple: [102, 51, 153],
|
||||||
|
red: [255,0,0],
|
||||||
|
rosybrown: [188,143,143],
|
||||||
|
royalblue: [65,105,225],
|
||||||
|
saddlebrown: [139,69,19],
|
||||||
|
salmon: [250,128,114],
|
||||||
|
sandybrown: [244,164,96],
|
||||||
|
seagreen: [46,139,87],
|
||||||
|
seashell: [255,245,238],
|
||||||
|
sienna: [160,82,45],
|
||||||
|
silver: [192,192,192],
|
||||||
|
skyblue: [135,206,235],
|
||||||
|
slateblue: [106,90,205],
|
||||||
|
slategray: [112,128,144],
|
||||||
|
slategrey: [112,128,144],
|
||||||
|
snow: [255,250,250],
|
||||||
|
springgreen: [0,255,127],
|
||||||
|
steelblue: [70,130,180],
|
||||||
|
tan: [210,180,140],
|
||||||
|
teal: [0,128,128],
|
||||||
|
thistle: [216,191,216],
|
||||||
|
tomato: [255,99,71],
|
||||||
|
turquoise: [64,224,208],
|
||||||
|
violet: [238,130,238],
|
||||||
|
wheat: [245,222,179],
|
||||||
|
white: [255,255,255],
|
||||||
|
whitesmoke: [245,245,245],
|
||||||
|
yellow: [255,255,0],
|
||||||
|
yellowgreen: [154,205,50]
|
||||||
|
};
|
||||||
|
|
||||||
|
var reverseKeywords = {};
|
||||||
|
for (var key in cssKeywords) {
|
||||||
|
reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
|
||||||
|
}
|
||||||
92
node_modules/color-convert/index.js
generated
vendored
Normal file
92
node_modules/color-convert/index.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
var conversions = require("./conversions");
|
||||||
|
|
||||||
|
var convert = function() {
|
||||||
|
return new Converter();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var func in conversions) {
|
||||||
|
// export Raw versions
|
||||||
|
convert[func + "Raw"] = (function(func) {
|
||||||
|
// accept array or plain args
|
||||||
|
return function(arg) {
|
||||||
|
if (typeof arg == "number")
|
||||||
|
arg = Array.prototype.slice.call(arguments);
|
||||||
|
return conversions[func](arg);
|
||||||
|
}
|
||||||
|
})(func);
|
||||||
|
|
||||||
|
var pair = /(\w+)2(\w+)/.exec(func),
|
||||||
|
from = pair[1],
|
||||||
|
to = pair[2];
|
||||||
|
|
||||||
|
// export rgb2hsl and ["rgb"]["hsl"]
|
||||||
|
convert[from] = convert[from] || {};
|
||||||
|
|
||||||
|
convert[from][to] = convert[func] = (function(func) {
|
||||||
|
return function(arg) {
|
||||||
|
if (typeof arg == "number")
|
||||||
|
arg = Array.prototype.slice.call(arguments);
|
||||||
|
|
||||||
|
var val = conversions[func](arg);
|
||||||
|
if (typeof val == "string" || val === undefined)
|
||||||
|
return val; // keyword
|
||||||
|
|
||||||
|
for (var i = 0; i < val.length; i++)
|
||||||
|
val[i] = Math.round(val[i]);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
})(func);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Converter does lazy conversion and caching */
|
||||||
|
var Converter = function() {
|
||||||
|
this.convs = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Either get the values for a space or
|
||||||
|
set the values for a space, depending on args */
|
||||||
|
Converter.prototype.routeSpace = function(space, args) {
|
||||||
|
var values = args[0];
|
||||||
|
if (values === undefined) {
|
||||||
|
// color.rgb()
|
||||||
|
return this.getValues(space);
|
||||||
|
}
|
||||||
|
// color.rgb(10, 10, 10)
|
||||||
|
if (typeof values == "number") {
|
||||||
|
values = Array.prototype.slice.call(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.setValues(space, values);
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Set the values for a space, invalidating cache */
|
||||||
|
Converter.prototype.setValues = function(space, values) {
|
||||||
|
this.space = space;
|
||||||
|
this.convs = {};
|
||||||
|
this.convs[space] = values;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Get the values for a space. If there's already
|
||||||
|
a conversion for the space, fetch it, otherwise
|
||||||
|
compute it */
|
||||||
|
Converter.prototype.getValues = function(space) {
|
||||||
|
var vals = this.convs[space];
|
||||||
|
if (!vals) {
|
||||||
|
var fspace = this.space,
|
||||||
|
from = this.convs[fspace];
|
||||||
|
vals = convert[fspace][space](from);
|
||||||
|
|
||||||
|
this.convs[space] = vals;
|
||||||
|
}
|
||||||
|
return vals;
|
||||||
|
};
|
||||||
|
|
||||||
|
["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
|
||||||
|
Converter.prototype[space] = function(vals) {
|
||||||
|
return this.routeSpace(space, arguments);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = convert;
|
||||||
20
node_modules/color-convert/package.json
generated
vendored
Normal file
20
node_modules/color-convert/package.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "color-convert",
|
||||||
|
"description": "Plain color conversion functions",
|
||||||
|
"version": "0.5.3",
|
||||||
|
"author": "Heather Arthur <fayearthur@gmail.com>",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "http://github.com/harthur/color-convert.git"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "node test/basic.js"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"color",
|
||||||
|
"colour",
|
||||||
|
"rgb"
|
||||||
|
]
|
||||||
|
}
|
||||||
187
node_modules/color-convert/test/basic.js
generated
vendored
Normal file
187
node_modules/color-convert/test/basic.js
generated
vendored
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
var convert = require("../index"),
|
||||||
|
assert = require("assert");
|
||||||
|
|
||||||
|
assert.deepEqual(convert.rgb2hsl([140, 200, 100]), [96, 48, 59]);
|
||||||
|
assert.deepEqual(convert.rgb2hsv([140, 200, 100]), [96, 50, 78]);
|
||||||
|
assert.deepEqual(convert.rgb2hwb([140, 200, 100]), [96, 39, 22]);
|
||||||
|
assert.deepEqual(convert.rgb2cmyk([140, 200, 100]), [30, 0, 50, 22]);
|
||||||
|
assert.deepEqual(convert.rgb2cmyk([0,0,0,1]), [0,0,0,100]);
|
||||||
|
assert.deepEqual(convert.rgb2keyword([255, 228, 196]), "bisque");
|
||||||
|
assert.deepEqual(convert.rgb2xyz([92, 191, 84]), [25, 40, 15]);
|
||||||
|
assert.deepEqual(convert.rgb2lab([92, 191, 84]), [70, -50, 45]);
|
||||||
|
assert.deepEqual(convert.rgb2lch([92, 191, 84]), [70, 67, 138]);
|
||||||
|
|
||||||
|
assert.deepEqual(convert.hsl2rgb([96, 48, 59]), [140, 201, 100]);
|
||||||
|
assert.deepEqual(convert.hsl2hsv([96, 48, 59]), [96, 50, 79]); // colorpicker says [96,50,79]
|
||||||
|
assert.deepEqual(convert.hsl2hwb([96, 48, 59]), [96, 39, 21]); // computer round to 21, should be 22
|
||||||
|
assert.deepEqual(convert.hsl2cmyk([96, 48, 59]), [30, 0, 50, 21]);
|
||||||
|
assert.deepEqual(convert.hsl2keyword([240, 100, 50]), "blue");
|
||||||
|
|
||||||
|
assert.deepEqual(convert.hsv2rgb([96, 50, 78]), [139, 199, 99]);
|
||||||
|
assert.deepEqual(convert.hsv2hsl([96, 50, 78]), [96, 47, 59]);
|
||||||
|
assert.deepEqual(convert.hsv2hsl([0,0,0]), [0,0,0]);
|
||||||
|
assert.deepEqual(convert.hsv2hwb([96, 50, 78]), [96, 39, 22]);
|
||||||
|
assert.deepEqual(convert.hsv2cmyk([96, 50, 78]), [30, 0, 50, 22]);
|
||||||
|
assert.deepEqual(convert.hsv2keyword([240, 100, 100]), "blue");
|
||||||
|
|
||||||
|
assert.deepEqual(convert.cmyk2rgb([30, 0, 50, 22]), [139, 199, 99]);
|
||||||
|
assert.deepEqual(convert.cmyk2hsl([30, 0, 50, 22]), [96, 47, 59]);
|
||||||
|
assert.deepEqual(convert.cmyk2hsv([30, 0, 50, 22]), [96, 50, 78]);
|
||||||
|
assert.deepEqual(convert.cmyk2hwb([30, 0, 50, 22]), [96, 39, 22]);
|
||||||
|
assert.deepEqual(convert.cmyk2keyword([100, 100, 0, 0]), "blue");
|
||||||
|
|
||||||
|
assert.deepEqual(convert.keyword2rgb("blue"), [0, 0, 255]);
|
||||||
|
assert.deepEqual(convert.keyword2hsl("blue"), [240, 100, 50]);
|
||||||
|
assert.deepEqual(convert.keyword2hsv("blue"), [240, 100, 100]);
|
||||||
|
assert.deepEqual(convert.keyword2hwb("blue"), [240, 0, 0]);
|
||||||
|
assert.deepEqual(convert.keyword2cmyk("blue"), [100, 100, 0, 0]);
|
||||||
|
assert.deepEqual(convert.keyword2lab("blue"), [32, 79, -108]);
|
||||||
|
assert.deepEqual(convert.keyword2xyz("blue"), [18, 7, 95]);
|
||||||
|
|
||||||
|
assert.deepEqual(convert.xyz2rgb([25, 40, 15]), [97, 190, 85]);
|
||||||
|
assert.deepEqual(convert.xyz2rgb([50, 100, 100]), [0, 255, 241]);
|
||||||
|
assert.deepEqual(convert.xyz2lab([25, 40, 15]), [69, -48, 44]);
|
||||||
|
assert.deepEqual(convert.xyz2lch([25, 40, 15]), [69, 65, 137]);
|
||||||
|
|
||||||
|
assert.deepEqual(convert.lab2xyz([69, -48, 44]), [25, 39, 15]);
|
||||||
|
assert.deepEqual(convert.lab2rgb([75, 20, -30]), [194, 175, 240]);
|
||||||
|
assert.deepEqual(convert.lab2lch([69, -48, 44]), [69, 65, 137]);
|
||||||
|
|
||||||
|
assert.deepEqual(convert.lch2lab([69, 65, 137]), [69, -48, 44]);
|
||||||
|
assert.deepEqual(convert.lch2xyz([69, 65, 137]), [25, 39, 15]);
|
||||||
|
assert.deepEqual(convert.lch2rgb([69, 65, 137]), [98, 188, 83]);
|
||||||
|
|
||||||
|
// non-array arguments
|
||||||
|
assert.deepEqual(convert.hsl2rgb(96, 48, 59), [140, 201, 100]);
|
||||||
|
|
||||||
|
// raw functions
|
||||||
|
function round(vals) {
|
||||||
|
for (var i = 0; i < vals.length; i++)
|
||||||
|
vals[i] = vals[i].toFixed(1);
|
||||||
|
return vals;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.deepEqual(round(convert.hsl2rgbRaw([96, 48, 59])), [140.4, 200.6, 100.3]);
|
||||||
|
assert.deepEqual(round(convert.rgb2hslRaw([140, 200, 100])), [96, 47.6, 58.8]);
|
||||||
|
|
||||||
|
assert.deepEqual(round(convert.hsv2rgbRaw([96, 50, 78])), [139.2, 198.9, 99.5]);
|
||||||
|
assert.deepEqual(round(convert.rgb2hsvRaw([140, 200, 100])), [96, 50, 78.4]);
|
||||||
|
|
||||||
|
assert.deepEqual(round(convert.hwb2rgbRaw([96, 39, 22])), [139.2, 198.9, 99.5]);
|
||||||
|
assert.deepEqual(round(convert.rgb2hwbRaw([140, 200, 100])), [96, 39.2, 21.6]);
|
||||||
|
|
||||||
|
assert.deepEqual(round(convert.cmyk2rgbRaw([30, 0, 50, 22])), [139.2, 198.9, 99.5]);
|
||||||
|
assert.deepEqual(round(convert.rgb2cmykRaw([140, 200, 100])), [30, 0, 50, 21.6]);
|
||||||
|
|
||||||
|
assert.deepEqual(round(convert.keyword2rgbRaw("blue")), [0, 0, 255]);
|
||||||
|
assert.deepEqual(convert.rgb2keywordRaw([255, 228, 196]), "bisque");
|
||||||
|
|
||||||
|
assert.deepEqual(round(convert.hsv2hslRaw([96, 50, 78])), [96, 47, 58.5]);
|
||||||
|
assert.deepEqual(round(convert.hsl2hsvRaw([96, 48, 59])), [96, 50, 78.7]);
|
||||||
|
|
||||||
|
assert.deepEqual(round(convert.hsl2hsvRaw([96, 48, 59])), [96, 50, 78.7]);
|
||||||
|
|
||||||
|
assert.deepEqual(round(convert.xyz2rgbRaw([25, 40, 15])), [97.4, 189.9, 85]);
|
||||||
|
assert.deepEqual(round(convert.rgb2xyzRaw([92, 191, 84])), [24.6, 40.2, 14.8]);
|
||||||
|
|
||||||
|
assert.deepEqual(round(convert.rgb2labRaw([92, 191, 84])), [69.6, -50.1, 44.6]);
|
||||||
|
|
||||||
|
// hashed
|
||||||
|
var val = [140, 200, 100];
|
||||||
|
assert.deepEqual(convert["rgb"]["hsl"](val), convert.rgb2hsl(val));
|
||||||
|
assert.deepEqual(convert["rgb"]["hsv"](val), convert.rgb2hsv(val));
|
||||||
|
assert.deepEqual(convert["rgb"]["hwb"](val), convert.rgb2hwb(val));
|
||||||
|
assert.deepEqual(convert["rgb"]["cmyk"](val), convert.rgb2cmyk(val));
|
||||||
|
assert.deepEqual(convert["rgb"]["xyz"](val), convert.rgb2xyz(val));
|
||||||
|
assert.deepEqual(convert["rgb"]["lab"](val), convert.rgb2lab(val));
|
||||||
|
assert.deepEqual(convert["rgb"]["keyword"]([255, 228, 196]), "bisque");
|
||||||
|
|
||||||
|
val = [96, 48, 59];
|
||||||
|
assert.deepEqual(convert["hsl"]["rgb"](val), convert.hsl2rgb(val));
|
||||||
|
assert.deepEqual(convert["hsl"]["hsv"](val), convert.hsl2hsv(val));
|
||||||
|
assert.deepEqual(convert["hsl"]["hwb"](val), convert.hsl2hwb(val));
|
||||||
|
assert.deepEqual(convert["hsl"]["cmyk"](val), convert.hsl2cmyk(val));
|
||||||
|
assert.deepEqual(convert["hsl"]["keyword"](val), convert.hsl2keyword(val ));
|
||||||
|
|
||||||
|
val = [96, 50, 78];
|
||||||
|
assert.deepEqual(convert["hsv"]["rgb"](val), convert.hsv2rgb(val));
|
||||||
|
assert.deepEqual(convert["hsv"]["hsl"](val), convert.hsv2hsl(val));
|
||||||
|
assert.deepEqual(convert["hsv"]["hwb"](val), convert.hsv2hwb(val));
|
||||||
|
assert.deepEqual(convert["hsv"]["cmyk"](val), convert.hsv2cmyk(val));
|
||||||
|
assert.deepEqual(convert["hsv"]["keyword"](val), convert.hsv2keyword(val));
|
||||||
|
|
||||||
|
val = [30, 0, 50, 22];
|
||||||
|
assert.deepEqual(convert["cmyk"]["rgb"](val), convert.cmyk2rgb(val));
|
||||||
|
assert.deepEqual(convert["cmyk"]["hsl"](val), convert.cmyk2hsl(val));
|
||||||
|
assert.deepEqual(convert["cmyk"]["hsv"](val), convert.cmyk2hsv(val));
|
||||||
|
assert.deepEqual(convert["cmyk"]["hwb"](val), convert.cmyk2hwb(val));
|
||||||
|
assert.deepEqual(convert["cmyk"]["keyword"](val), convert.cmyk2keyword(val));
|
||||||
|
|
||||||
|
val = "blue";
|
||||||
|
assert.deepEqual(convert["keyword"]["rgb"](val), convert.keyword2rgb(val));
|
||||||
|
assert.deepEqual(convert["keyword"]["hsl"](val), convert.keyword2hsl(val));
|
||||||
|
assert.deepEqual(convert["keyword"]["hsv"](val), convert.keyword2hsv(val));
|
||||||
|
assert.deepEqual(convert["keyword"]["hwb"](val), convert.keyword2hwb(val));
|
||||||
|
assert.deepEqual(convert["keyword"]["cmyk"](val), convert.keyword2cmyk(val));
|
||||||
|
assert.deepEqual(convert["keyword"]["lab"](val), convert.keyword2lab(val));
|
||||||
|
assert.deepEqual(convert["keyword"]["xyz"](val), convert.keyword2xyz(val));
|
||||||
|
|
||||||
|
val = [25, 40, 15]
|
||||||
|
assert.deepEqual(convert["xyz"]["rgb"](val), convert.xyz2rgb(val));
|
||||||
|
assert.deepEqual(convert["xyz"]["lab"](val), convert.xyz2lab(val));
|
||||||
|
|
||||||
|
val = [69, -48, 44];
|
||||||
|
assert.deepEqual(convert["lab"]["xyz"](val), [25, 39, 15]);
|
||||||
|
|
||||||
|
|
||||||
|
// converter
|
||||||
|
var converter = convert();
|
||||||
|
|
||||||
|
var vals = [140, 200, 100];
|
||||||
|
converter.rgb(140, 200, 100);
|
||||||
|
|
||||||
|
assert.deepEqual(converter.hsl(), convert.rgb2hsl(vals));
|
||||||
|
assert.deepEqual(converter.hsv(), convert.rgb2hsv(vals));
|
||||||
|
assert.deepEqual(converter.cmyk(), convert.rgb2cmyk(vals));
|
||||||
|
assert.deepEqual(converter.rgb(), vals);
|
||||||
|
assert.deepEqual(converter.rgb([255, 228, 196]).keyword(), "bisque");
|
||||||
|
|
||||||
|
vals = [96, 48, 59];
|
||||||
|
converter.hsl(vals);
|
||||||
|
assert.deepEqual(converter.rgb(), convert.hsl2rgb(vals));
|
||||||
|
assert.deepEqual(converter.hsv(), convert.hsl2hsv(vals));
|
||||||
|
assert.deepEqual(converter.cmyk(), convert.hsl2cmyk(vals));
|
||||||
|
assert.deepEqual(converter.keyword(), convert.hsl2keyword(vals));
|
||||||
|
|
||||||
|
// hwb
|
||||||
|
// http://dev.w3.org/csswg/css-color/#hwb-examples
|
||||||
|
|
||||||
|
// all extrem value should give black, white or grey
|
||||||
|
for(var angle = 0; angle <= 360; angle ++) {
|
||||||
|
assert.deepEqual(convert.hwb2rgb([angle, 0, 100]), [0, 0, 0]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([angle, 100, 0]), [255, 255, 255]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([angle, 100, 100]), [128, 128, 128]);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.deepEqual(convert.hwb2rgb([0, 0, 0]), [255,0,0]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([0, 20, 40]), [153, 51, 51]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([0, 40, 40]), [153, 102, 102]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([0, 40, 20]), [204, 102, 102]);
|
||||||
|
|
||||||
|
assert.deepEqual(convert.hwb2rgb([120, 0, 0]), [0,255,0]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([120, 20, 40]), [51, 153, 51]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([120, 40, 40]), [102, 153, 102]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([120, 40, 20]), [102, 204, 102]);
|
||||||
|
|
||||||
|
assert.deepEqual(convert.hwb2rgb([240, 0, 0]), [0,0,255]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([240, 20, 40]), [51, 51, 153]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([240, 40, 40]), [102, 102, 153]);
|
||||||
|
assert.deepEqual(convert.hwb2rgb([240, 40, 20]), [102, 102, 204]);
|
||||||
|
|
||||||
|
|
||||||
|
// black should always stay black
|
||||||
|
val = [0, 0, 0];
|
||||||
|
assert.deepEqual(convert.hsl2hsv(val), val);
|
||||||
|
assert.deepEqual(convert.hsl2rgb(val), val);
|
||||||
|
assert.deepEqual(convert.hsl2hwb(val), [0, 0, 100]);
|
||||||
|
assert.deepEqual(convert.hsl2cmyk(val), [0, 0, 0, 100]);
|
||||||
23
node_modules/color-convert/test/speed.js
generated
vendored
Normal file
23
node_modules/color-convert/test/speed.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
var convert = require("../index");
|
||||||
|
|
||||||
|
var converter = convert();
|
||||||
|
|
||||||
|
var times = 10000;
|
||||||
|
|
||||||
|
console.time("cached");
|
||||||
|
converter.rgb(10, 2, 30);
|
||||||
|
for(var i = 0; i < times; i++) {
|
||||||
|
converter.hsv();
|
||||||
|
converter.hsl();
|
||||||
|
converter.cmyk();
|
||||||
|
}
|
||||||
|
console.timeEnd("cached");
|
||||||
|
|
||||||
|
console.time("uncached");
|
||||||
|
for(var i = 0; i < times; i++) {
|
||||||
|
convert.rgb2hsl(10, 2, 30);
|
||||||
|
convert.rgb2hsv(10, 2, 30);
|
||||||
|
convert.rgb2cmyk(10, 2, 30);
|
||||||
|
}
|
||||||
|
console.timeEnd("uncached");
|
||||||
|
|
||||||
8
node_modules/color-name/LICENSE
generated
vendored
Normal file
8
node_modules/color-name/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
Copyright (c) 2015 Dmitry Ivanov
|
||||||
|
|
||||||
|
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.
|
||||||
11
node_modules/color-name/README.md
generated
vendored
Normal file
11
node_modules/color-name/README.md
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
A JSON with color names and its values. Based on http://dev.w3.org/csswg/css-color/#named-colors.
|
||||||
|
|
||||||
|
[](https://nodei.co/npm/color-name/)
|
||||||
|
|
||||||
|
|
||||||
|
```js
|
||||||
|
var colors = require('color-name');
|
||||||
|
colors.red //[255,0,0]
|
||||||
|
```
|
||||||
|
|
||||||
|
<a href="LICENSE"><img src="https://upload.wikimedia.org/wikipedia/commons/0/0c/MIT_logo.svg" width="120"/></a>
|
||||||
152
node_modules/color-name/index.js
generated
vendored
Normal file
152
node_modules/color-name/index.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
"aliceblue": [240, 248, 255],
|
||||||
|
"antiquewhite": [250, 235, 215],
|
||||||
|
"aqua": [0, 255, 255],
|
||||||
|
"aquamarine": [127, 255, 212],
|
||||||
|
"azure": [240, 255, 255],
|
||||||
|
"beige": [245, 245, 220],
|
||||||
|
"bisque": [255, 228, 196],
|
||||||
|
"black": [0, 0, 0],
|
||||||
|
"blanchedalmond": [255, 235, 205],
|
||||||
|
"blue": [0, 0, 255],
|
||||||
|
"blueviolet": [138, 43, 226],
|
||||||
|
"brown": [165, 42, 42],
|
||||||
|
"burlywood": [222, 184, 135],
|
||||||
|
"cadetblue": [95, 158, 160],
|
||||||
|
"chartreuse": [127, 255, 0],
|
||||||
|
"chocolate": [210, 105, 30],
|
||||||
|
"coral": [255, 127, 80],
|
||||||
|
"cornflowerblue": [100, 149, 237],
|
||||||
|
"cornsilk": [255, 248, 220],
|
||||||
|
"crimson": [220, 20, 60],
|
||||||
|
"cyan": [0, 255, 255],
|
||||||
|
"darkblue": [0, 0, 139],
|
||||||
|
"darkcyan": [0, 139, 139],
|
||||||
|
"darkgoldenrod": [184, 134, 11],
|
||||||
|
"darkgray": [169, 169, 169],
|
||||||
|
"darkgreen": [0, 100, 0],
|
||||||
|
"darkgrey": [169, 169, 169],
|
||||||
|
"darkkhaki": [189, 183, 107],
|
||||||
|
"darkmagenta": [139, 0, 139],
|
||||||
|
"darkolivegreen": [85, 107, 47],
|
||||||
|
"darkorange": [255, 140, 0],
|
||||||
|
"darkorchid": [153, 50, 204],
|
||||||
|
"darkred": [139, 0, 0],
|
||||||
|
"darksalmon": [233, 150, 122],
|
||||||
|
"darkseagreen": [143, 188, 143],
|
||||||
|
"darkslateblue": [72, 61, 139],
|
||||||
|
"darkslategray": [47, 79, 79],
|
||||||
|
"darkslategrey": [47, 79, 79],
|
||||||
|
"darkturquoise": [0, 206, 209],
|
||||||
|
"darkviolet": [148, 0, 211],
|
||||||
|
"deeppink": [255, 20, 147],
|
||||||
|
"deepskyblue": [0, 191, 255],
|
||||||
|
"dimgray": [105, 105, 105],
|
||||||
|
"dimgrey": [105, 105, 105],
|
||||||
|
"dodgerblue": [30, 144, 255],
|
||||||
|
"firebrick": [178, 34, 34],
|
||||||
|
"floralwhite": [255, 250, 240],
|
||||||
|
"forestgreen": [34, 139, 34],
|
||||||
|
"fuchsia": [255, 0, 255],
|
||||||
|
"gainsboro": [220, 220, 220],
|
||||||
|
"ghostwhite": [248, 248, 255],
|
||||||
|
"gold": [255, 215, 0],
|
||||||
|
"goldenrod": [218, 165, 32],
|
||||||
|
"gray": [128, 128, 128],
|
||||||
|
"green": [0, 128, 0],
|
||||||
|
"greenyellow": [173, 255, 47],
|
||||||
|
"grey": [128, 128, 128],
|
||||||
|
"honeydew": [240, 255, 240],
|
||||||
|
"hotpink": [255, 105, 180],
|
||||||
|
"indianred": [205, 92, 92],
|
||||||
|
"indigo": [75, 0, 130],
|
||||||
|
"ivory": [255, 255, 240],
|
||||||
|
"khaki": [240, 230, 140],
|
||||||
|
"lavender": [230, 230, 250],
|
||||||
|
"lavenderblush": [255, 240, 245],
|
||||||
|
"lawngreen": [124, 252, 0],
|
||||||
|
"lemonchiffon": [255, 250, 205],
|
||||||
|
"lightblue": [173, 216, 230],
|
||||||
|
"lightcoral": [240, 128, 128],
|
||||||
|
"lightcyan": [224, 255, 255],
|
||||||
|
"lightgoldenrodyellow": [250, 250, 210],
|
||||||
|
"lightgray": [211, 211, 211],
|
||||||
|
"lightgreen": [144, 238, 144],
|
||||||
|
"lightgrey": [211, 211, 211],
|
||||||
|
"lightpink": [255, 182, 193],
|
||||||
|
"lightsalmon": [255, 160, 122],
|
||||||
|
"lightseagreen": [32, 178, 170],
|
||||||
|
"lightskyblue": [135, 206, 250],
|
||||||
|
"lightslategray": [119, 136, 153],
|
||||||
|
"lightslategrey": [119, 136, 153],
|
||||||
|
"lightsteelblue": [176, 196, 222],
|
||||||
|
"lightyellow": [255, 255, 224],
|
||||||
|
"lime": [0, 255, 0],
|
||||||
|
"limegreen": [50, 205, 50],
|
||||||
|
"linen": [250, 240, 230],
|
||||||
|
"magenta": [255, 0, 255],
|
||||||
|
"maroon": [128, 0, 0],
|
||||||
|
"mediumaquamarine": [102, 205, 170],
|
||||||
|
"mediumblue": [0, 0, 205],
|
||||||
|
"mediumorchid": [186, 85, 211],
|
||||||
|
"mediumpurple": [147, 112, 219],
|
||||||
|
"mediumseagreen": [60, 179, 113],
|
||||||
|
"mediumslateblue": [123, 104, 238],
|
||||||
|
"mediumspringgreen": [0, 250, 154],
|
||||||
|
"mediumturquoise": [72, 209, 204],
|
||||||
|
"mediumvioletred": [199, 21, 133],
|
||||||
|
"midnightblue": [25, 25, 112],
|
||||||
|
"mintcream": [245, 255, 250],
|
||||||
|
"mistyrose": [255, 228, 225],
|
||||||
|
"moccasin": [255, 228, 181],
|
||||||
|
"navajowhite": [255, 222, 173],
|
||||||
|
"navy": [0, 0, 128],
|
||||||
|
"oldlace": [253, 245, 230],
|
||||||
|
"olive": [128, 128, 0],
|
||||||
|
"olivedrab": [107, 142, 35],
|
||||||
|
"orange": [255, 165, 0],
|
||||||
|
"orangered": [255, 69, 0],
|
||||||
|
"orchid": [218, 112, 214],
|
||||||
|
"palegoldenrod": [238, 232, 170],
|
||||||
|
"palegreen": [152, 251, 152],
|
||||||
|
"paleturquoise": [175, 238, 238],
|
||||||
|
"palevioletred": [219, 112, 147],
|
||||||
|
"papayawhip": [255, 239, 213],
|
||||||
|
"peachpuff": [255, 218, 185],
|
||||||
|
"peru": [205, 133, 63],
|
||||||
|
"pink": [255, 192, 203],
|
||||||
|
"plum": [221, 160, 221],
|
||||||
|
"powderblue": [176, 224, 230],
|
||||||
|
"purple": [128, 0, 128],
|
||||||
|
"rebeccapurple": [102, 51, 153],
|
||||||
|
"red": [255, 0, 0],
|
||||||
|
"rosybrown": [188, 143, 143],
|
||||||
|
"royalblue": [65, 105, 225],
|
||||||
|
"saddlebrown": [139, 69, 19],
|
||||||
|
"salmon": [250, 128, 114],
|
||||||
|
"sandybrown": [244, 164, 96],
|
||||||
|
"seagreen": [46, 139, 87],
|
||||||
|
"seashell": [255, 245, 238],
|
||||||
|
"sienna": [160, 82, 45],
|
||||||
|
"silver": [192, 192, 192],
|
||||||
|
"skyblue": [135, 206, 235],
|
||||||
|
"slateblue": [106, 90, 205],
|
||||||
|
"slategray": [112, 128, 144],
|
||||||
|
"slategrey": [112, 128, 144],
|
||||||
|
"snow": [255, 250, 250],
|
||||||
|
"springgreen": [0, 255, 127],
|
||||||
|
"steelblue": [70, 130, 180],
|
||||||
|
"tan": [210, 180, 140],
|
||||||
|
"teal": [0, 128, 128],
|
||||||
|
"thistle": [216, 191, 216],
|
||||||
|
"tomato": [255, 99, 71],
|
||||||
|
"turquoise": [64, 224, 208],
|
||||||
|
"violet": [238, 130, 238],
|
||||||
|
"wheat": [245, 222, 179],
|
||||||
|
"white": [255, 255, 255],
|
||||||
|
"whitesmoke": [245, 245, 245],
|
||||||
|
"yellow": [255, 255, 0],
|
||||||
|
"yellowgreen": [154, 205, 50]
|
||||||
|
};
|
||||||
28
node_modules/color-name/package.json
generated
vendored
Normal file
28
node_modules/color-name/package.json
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "color-name",
|
||||||
|
"version": "1.1.4",
|
||||||
|
"description": "A list of color names and its values",
|
||||||
|
"main": "index.js",
|
||||||
|
"files": [
|
||||||
|
"index.js"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"test": "node test.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git@github.com:colorjs/color-name.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"color-name",
|
||||||
|
"color",
|
||||||
|
"color-keyword",
|
||||||
|
"keyword"
|
||||||
|
],
|
||||||
|
"author": "DY <dfcreative@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/colorjs/color-name/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/colorjs/color-name"
|
||||||
|
}
|
||||||
22
node_modules/css-color-converter/CHANGELOG.md
generated
vendored
Normal file
22
node_modules/css-color-converter/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# 2.0.0 - 2020-09-24
|
||||||
|
* Rewrite as ES module. Some breaking changes to the API surface has been made as a result.
|
||||||
|
* Better adhere to CSS specification (#4).
|
||||||
|
* Add support for CSS Color Module Level 4 syntax.
|
||||||
|
* Update dependencies.
|
||||||
|
* Add eslint.
|
||||||
|
* Add babel.
|
||||||
|
|
||||||
|
# 1.1.1 - 2020-03-20
|
||||||
|
* Fix alpha 0 incorrectly defaulting to 1 (#2). Thanks to jedwards1211.
|
||||||
|
|
||||||
|
# 1.1.0 - 2016-08-13
|
||||||
|
* Add `toHslaArray` method.
|
||||||
|
|
||||||
|
# 1.0.2 - 2015-05-27
|
||||||
|
* Fix typo causing `rgba()` to return incorrect results.
|
||||||
|
|
||||||
|
# 1.0.1 - 2015-05-27
|
||||||
|
* Fix `toHexString()` not padding values.
|
||||||
|
|
||||||
|
# 1.0.0 - 2015-05-27
|
||||||
|
* Initial release.
|
||||||
20
node_modules/css-color-converter/LICENSE
generated
vendored
Normal file
20
node_modules/css-color-converter/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright 2015 Andy Jansson <andyjansson@users.noreply.github.com>
|
||||||
|
|
||||||
|
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.
|
||||||
92
node_modules/css-color-converter/README.md
generated
vendored
Normal file
92
node_modules/css-color-converter/README.md
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
# css-color-converter [![Build Status][ci-img]][ci]
|
||||||
|
|
||||||
|
Converts CSS colors from one representation to another
|
||||||
|
|
||||||
|
[ci-img]: https://travis-ci.org/andyjansson/css-color-converter.svg
|
||||||
|
[ci]: https://travis-ci.org/andyjansson/css-color-converter
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```js
|
||||||
|
npm install css-color-converter
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
**Example usage**:
|
||||||
|
```js
|
||||||
|
import { fromString } from 'css-color-converter';
|
||||||
|
|
||||||
|
fromString('rgb(255, 255, 255)').toHslString(); // hsl(0, 0%, 100%)
|
||||||
|
fromString('rgba(255, 255, 255, 0.5)').toHslString(); // hsla(0, 0%, 100%, 0.5)
|
||||||
|
fromString('blue').toRgbString(); // rgb(0, 0, 255)
|
||||||
|
fromString('red').toHexString(); // #ff0000
|
||||||
|
```
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
### `fromString(str)`
|
||||||
|
| parameter | type | description |
|
||||||
|
| --------- | ------ | ---------------------------------------------- |
|
||||||
|
| `str` | string | Supports named colors, hex, rgb/rgba, hsl/hsla |
|
||||||
|
|
||||||
|
**Returns** [`instance`](#Methods) if valid, `null` if invalid.
|
||||||
|
|
||||||
|
### `fromRgb([r, g, b])`
|
||||||
|
|
||||||
|
| parameter | type | description |
|
||||||
|
| --------- | ------ | ------------- |
|
||||||
|
| `r` | int | red (0-255) |
|
||||||
|
| `g` | int | green (0-255) |
|
||||||
|
| `b` | int | blue (0-255) |
|
||||||
|
|
||||||
|
**Returns** [`instance`](#Methods)
|
||||||
|
|
||||||
|
### `fromRgba([r, g, b, a])`
|
||||||
|
|
||||||
|
| parameter | type | description |
|
||||||
|
| --------- | ------ | ------------- |
|
||||||
|
| `r` | int | red (0-255) |
|
||||||
|
| `g` | int | green (0-255) |
|
||||||
|
| `b` | int | blue (0-255) |
|
||||||
|
| `a` | float | alpha (0-1) |
|
||||||
|
|
||||||
|
**Returns** [`instance`](#Methods)
|
||||||
|
|
||||||
|
### `fromHsl([h, s, l])`
|
||||||
|
|
||||||
|
| parameter | type | description |
|
||||||
|
| --------- | ------ | ------------------ |
|
||||||
|
| `h` | int | hue (0-360) |
|
||||||
|
| `s` | int | saturation (0-100) |
|
||||||
|
| `l` | int | luminosity (0-100) |
|
||||||
|
|
||||||
|
**Returns** [`instance`](#Methods)
|
||||||
|
|
||||||
|
### `fromHsla([h, s, l, a])`
|
||||||
|
|
||||||
|
| parameter | type | description |
|
||||||
|
| --------- | ------ | ------------------ |
|
||||||
|
| `h` | int | hue (0-360) |
|
||||||
|
| `s` | int | saturation (0-100) |
|
||||||
|
| `l` | int | luminosity (0-100) |
|
||||||
|
| `a` | float | alpha (0-1) |
|
||||||
|
|
||||||
|
**Returns** [`instance`](#Methods)
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
### `toRgbString()`
|
||||||
|
|
||||||
|
**Returns** `rgb()` or `rgba()`, depending on the alpha.
|
||||||
|
|
||||||
|
### `toHslString()`
|
||||||
|
|
||||||
|
**Returns** `hsl()` or `hsla()`, depending on the alpha.
|
||||||
|
|
||||||
|
### `toHexString()`
|
||||||
|
|
||||||
|
**Returns** 6-digit or 8-digit `hex`, depending on the alpha.
|
||||||
|
|
||||||
|
### `toRgbaArray()`
|
||||||
|
|
||||||
|
**Returns** `[r, g, b, a]` array.
|
||||||
314
node_modules/css-color-converter/lib/index.js
generated
vendored
Normal file
314
node_modules/css-color-converter/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,314 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.fromRgba = fromRgba;
|
||||||
|
exports.fromRgb = fromRgb;
|
||||||
|
exports.fromHsla = fromHsla;
|
||||||
|
exports.fromHsl = fromHsl;
|
||||||
|
exports.fromString = fromString;
|
||||||
|
exports["default"] = void 0;
|
||||||
|
|
||||||
|
var _colorName = _interopRequireDefault(require("color-name"));
|
||||||
|
|
||||||
|
var _cssUnitConverter = _interopRequireDefault(require("css-unit-converter"));
|
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||||
|
|
||||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||||
|
|
||||||
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||||
|
|
||||||
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
||||||
|
|
||||||
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||||
|
|
||||||
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||||
|
|
||||||
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
||||||
|
|
||||||
|
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
||||||
|
|
||||||
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||||
|
|
||||||
|
var hex = /^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})?$/;
|
||||||
|
var shortHex = /^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])?$/;
|
||||||
|
var rgb = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(?:\s*,\s*(0|1|0?\.\d+|\d+%))?\s*\)$/;
|
||||||
|
var rgbfn = /^rgba?\(\s*(\d+)\s+(\d+)\s+(\d+)(?:\s*\/\s*(0|1|0?\.\d+|\d+%))?\s*\)$/;
|
||||||
|
var rgbperc = /^rgba?\(\s*(\d+%)\s*,\s*(\d+%)\s*,\s*(\d+%)(?:\s*,\s*(0|1|0?\.\d+|\d+%))?\s*\)$/;
|
||||||
|
var rgbpercfn = /^rgba?\(\s*(\d+%)\s+(\d+%)\s+(\d+%)(?:\s*\/\s*(0|1|0?\.\d+|\d+%))?\s*\)$/;
|
||||||
|
var hsl = /^hsla?\(\s*(\d+)(deg|rad|grad|turn)?\s*,\s*(\d+)%\s*,\s*(\d+)%(?:\s*,\s*(0|1|0?\.\d+|\d+%))?\s*\)$/;
|
||||||
|
|
||||||
|
function contains(haystack, needle) {
|
||||||
|
return haystack.indexOf(needle) > -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rgbToHsl(r, g, b) {
|
||||||
|
var rprim = r / 255;
|
||||||
|
var gprim = g / 255;
|
||||||
|
var bprim = b / 255;
|
||||||
|
var cmax = Math.max(rprim, gprim, bprim);
|
||||||
|
var cmin = Math.min(rprim, gprim, bprim);
|
||||||
|
var delta = cmax - cmin;
|
||||||
|
var l = (cmax + cmin) / 2;
|
||||||
|
|
||||||
|
if (delta === 0) {
|
||||||
|
return [0, 0, l * 100];
|
||||||
|
}
|
||||||
|
|
||||||
|
var s = delta / (1 - Math.abs(2 * l - 1));
|
||||||
|
|
||||||
|
var h = function () {
|
||||||
|
switch (cmax) {
|
||||||
|
case rprim:
|
||||||
|
{
|
||||||
|
return (gprim - bprim) / delta % 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
case gprim:
|
||||||
|
{
|
||||||
|
return (bprim - rprim) / delta + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return (rprim - gprim) / delta + 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
|
return [h * 60, s * 100, l * 100];
|
||||||
|
}
|
||||||
|
|
||||||
|
function hslToRgb(h, s, l) {
|
||||||
|
var hprim = h / 60;
|
||||||
|
var sprim = s / 100;
|
||||||
|
var lprim = l / 100;
|
||||||
|
var c = (1 - Math.abs(2 * lprim - 1)) * sprim;
|
||||||
|
var x = c * (1 - Math.abs(hprim % 2 - 1));
|
||||||
|
var m = lprim - c / 2;
|
||||||
|
|
||||||
|
var _ref = function () {
|
||||||
|
if (hprim < 1) return [c, x, 0];
|
||||||
|
if (hprim < 2) return [x, c, 0];
|
||||||
|
if (hprim < 3) return [0, c, x];
|
||||||
|
if (hprim < 4) return [0, x, c];
|
||||||
|
if (hprim < 5) return [x, 0, c];
|
||||||
|
return [c, 0, x];
|
||||||
|
}(),
|
||||||
|
_ref2 = _slicedToArray(_ref, 3),
|
||||||
|
rprim = _ref2[0],
|
||||||
|
gprim = _ref2[1],
|
||||||
|
bprim = _ref2[2];
|
||||||
|
|
||||||
|
return [(rprim + m) * 255, (gprim + m) * 255, (bprim + m) * 255];
|
||||||
|
}
|
||||||
|
|
||||||
|
var Color = /*#__PURE__*/function () {
|
||||||
|
function Color(_ref3) {
|
||||||
|
var _ref4 = _slicedToArray(_ref3, 4),
|
||||||
|
r = _ref4[0],
|
||||||
|
g = _ref4[1],
|
||||||
|
b = _ref4[2],
|
||||||
|
a = _ref4[3];
|
||||||
|
|
||||||
|
_classCallCheck(this, Color);
|
||||||
|
|
||||||
|
this.values = [Math.max(Math.min(parseInt(r, 10), 255), 0), Math.max(Math.min(parseInt(g, 10), 255), 0), Math.max(Math.min(parseInt(b, 10), 255), 0), a == null ? 1 : Math.max(Math.min(parseFloat(a), 255), 0)];
|
||||||
|
}
|
||||||
|
|
||||||
|
_createClass(Color, [{
|
||||||
|
key: "toRgbString",
|
||||||
|
value: function toRgbString() {
|
||||||
|
var _this$values = _slicedToArray(this.values, 4),
|
||||||
|
r = _this$values[0],
|
||||||
|
g = _this$values[1],
|
||||||
|
b = _this$values[2],
|
||||||
|
a = _this$values[3];
|
||||||
|
|
||||||
|
if (a === 1) {
|
||||||
|
return "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(a, ")");
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: "toHslString",
|
||||||
|
value: function toHslString() {
|
||||||
|
var _this$toHslaArray = this.toHslaArray(),
|
||||||
|
_this$toHslaArray2 = _slicedToArray(_this$toHslaArray, 4),
|
||||||
|
h = _this$toHslaArray2[0],
|
||||||
|
s = _this$toHslaArray2[1],
|
||||||
|
l = _this$toHslaArray2[2],
|
||||||
|
a = _this$toHslaArray2[3];
|
||||||
|
|
||||||
|
if (a === 1) {
|
||||||
|
return "hsl(".concat(h, ", ").concat(s, "%, ").concat(l, "%)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return "hsla(".concat(h, ", ").concat(s, "%, ").concat(l, "%, ").concat(a, ")");
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: "toHexString",
|
||||||
|
value: function toHexString() {
|
||||||
|
var _this$values2 = _slicedToArray(this.values, 4),
|
||||||
|
r = _this$values2[0],
|
||||||
|
g = _this$values2[1],
|
||||||
|
b = _this$values2[2],
|
||||||
|
a = _this$values2[3];
|
||||||
|
|
||||||
|
r = Number(r).toString(16).padStart(2, '0');
|
||||||
|
g = Number(g).toString(16).padStart(2, '0');
|
||||||
|
b = Number(b).toString(16).padStart(2, '0');
|
||||||
|
a = a < 1 ? parseInt(a * 255, 10).toString(16).padStart(2, '0') : '';
|
||||||
|
return "#".concat(r).concat(g).concat(b).concat(a);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: "toRgbaArray",
|
||||||
|
value: function toRgbaArray() {
|
||||||
|
return this.values;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
key: "toHslaArray",
|
||||||
|
value: function toHslaArray() {
|
||||||
|
var _this$values3 = _slicedToArray(this.values, 4),
|
||||||
|
r = _this$values3[0],
|
||||||
|
g = _this$values3[1],
|
||||||
|
b = _this$values3[2],
|
||||||
|
a = _this$values3[3];
|
||||||
|
|
||||||
|
var _rgbToHsl = rgbToHsl(r, g, b),
|
||||||
|
_rgbToHsl2 = _slicedToArray(_rgbToHsl, 3),
|
||||||
|
h = _rgbToHsl2[0],
|
||||||
|
s = _rgbToHsl2[1],
|
||||||
|
l = _rgbToHsl2[2];
|
||||||
|
|
||||||
|
return [h, s, l, a];
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
|
||||||
|
return Color;
|
||||||
|
}();
|
||||||
|
|
||||||
|
function fromRgba(_ref5) {
|
||||||
|
var _ref6 = _slicedToArray(_ref5, 4),
|
||||||
|
r = _ref6[0],
|
||||||
|
g = _ref6[1],
|
||||||
|
b = _ref6[2],
|
||||||
|
a = _ref6[3];
|
||||||
|
|
||||||
|
return new Color([r, g, b, a]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fromRgb(_ref7) {
|
||||||
|
var _ref8 = _slicedToArray(_ref7, 3),
|
||||||
|
r = _ref8[0],
|
||||||
|
g = _ref8[1],
|
||||||
|
b = _ref8[2];
|
||||||
|
|
||||||
|
return fromRgba([r, g, b, 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fromHsla(_ref9) {
|
||||||
|
var _ref10 = _slicedToArray(_ref9, 4),
|
||||||
|
h = _ref10[0],
|
||||||
|
s = _ref10[1],
|
||||||
|
l = _ref10[2],
|
||||||
|
a = _ref10[3];
|
||||||
|
|
||||||
|
var _hslToRgb = hslToRgb(h, s, l),
|
||||||
|
_hslToRgb2 = _slicedToArray(_hslToRgb, 3),
|
||||||
|
r = _hslToRgb2[0],
|
||||||
|
g = _hslToRgb2[1],
|
||||||
|
b = _hslToRgb2[2];
|
||||||
|
|
||||||
|
return fromRgba([r, g, b, a]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fromHsl(_ref11) {
|
||||||
|
var _ref12 = _slicedToArray(_ref11, 3),
|
||||||
|
h = _ref12[0],
|
||||||
|
s = _ref12[1],
|
||||||
|
l = _ref12[2];
|
||||||
|
|
||||||
|
return fromHsla([h, s, l, 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fromHexString(str) {
|
||||||
|
var _ref13 = hex.exec(str) || shortHex.exec(str),
|
||||||
|
_ref14 = _slicedToArray(_ref13, 5),
|
||||||
|
r = _ref14[1],
|
||||||
|
g = _ref14[2],
|
||||||
|
b = _ref14[3],
|
||||||
|
a = _ref14[4];
|
||||||
|
|
||||||
|
r = parseInt(r.length < 2 ? r.repeat(2) : r, 16);
|
||||||
|
g = parseInt(g.length < 2 ? g.repeat(2) : g, 16);
|
||||||
|
b = parseInt(b.length < 2 ? b.repeat(2) : b, 16);
|
||||||
|
a = a && (parseInt(a.length < 2 ? a.repeat(2) : a, 16) / 255).toPrecision(1) || 1;
|
||||||
|
return fromRgba([r, g, b, a]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fromRgbString(str) {
|
||||||
|
var _ref15 = rgb.exec(str) || rgbperc.exec(str) || rgbfn.exec(str) || rgbpercfn.exec(str),
|
||||||
|
_ref16 = _slicedToArray(_ref15, 5),
|
||||||
|
r = _ref16[1],
|
||||||
|
g = _ref16[2],
|
||||||
|
b = _ref16[3],
|
||||||
|
a = _ref16[4];
|
||||||
|
|
||||||
|
r = contains(r, '%') ? parseInt(r, 10) * 255 / 100 : parseInt(r, 10);
|
||||||
|
g = contains(g, '%') ? parseInt(g, 10) * 255 / 100 : parseInt(g, 10);
|
||||||
|
b = contains(b, '%') > 0 ? parseInt(b, 10) * 255 / 100 : parseInt(b, 10);
|
||||||
|
a = a === undefined ? 1 : parseFloat(a) / (contains(a, '%') ? 100 : 1);
|
||||||
|
return fromRgba([r, g, b, a]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fromHslString(str) {
|
||||||
|
var _hsl$exec = hsl.exec(str),
|
||||||
|
_hsl$exec2 = _slicedToArray(_hsl$exec, 6),
|
||||||
|
h = _hsl$exec2[1],
|
||||||
|
unit = _hsl$exec2[2],
|
||||||
|
s = _hsl$exec2[3],
|
||||||
|
l = _hsl$exec2[4],
|
||||||
|
a = _hsl$exec2[5];
|
||||||
|
|
||||||
|
unit = unit || 'deg';
|
||||||
|
h = (0, _cssUnitConverter["default"])(parseFloat(h), unit, 'deg');
|
||||||
|
s = parseFloat(s);
|
||||||
|
l = parseFloat(l);
|
||||||
|
a = a === undefined ? 1 : parseFloat(a) / (contains(a, '%') ? 100 : 1);
|
||||||
|
return fromHsla([h, s, l, a]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fromString(str) {
|
||||||
|
if (_colorName["default"][str]) {
|
||||||
|
return fromRgb(_colorName["default"][str]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hex.test(str) || shortHex.test(str)) {
|
||||||
|
return fromHexString(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rgb.test(str) || rgbperc.test(str) || rgbfn.test(str) || rgbpercfn.test(str)) {
|
||||||
|
return fromRgbString(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hsl.test(str)) {
|
||||||
|
return fromHslString(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var _default = {
|
||||||
|
fromString: fromString,
|
||||||
|
fromRgb: fromRgb,
|
||||||
|
fromRgba: fromRgba,
|
||||||
|
fromHsl: fromHsl,
|
||||||
|
fromHsla: fromHsla
|
||||||
|
};
|
||||||
|
exports["default"] = _default;
|
||||||
42
node_modules/css-color-converter/package.json
generated
vendored
Normal file
42
node_modules/css-color-converter/package.json
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"name": "css-color-converter",
|
||||||
|
"version": "2.0.0",
|
||||||
|
"description": "Converts CSS colors from one representation to another",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"prepublish": "npm run lint && npm run build",
|
||||||
|
"lint": "eslint --ext .mjs src",
|
||||||
|
"build": "babel src -d lib",
|
||||||
|
"pretest": "npm run lint",
|
||||||
|
"test": "node src/__tests__/test.mjs"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/andyjansson/css-color-converter.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"css",
|
||||||
|
"color",
|
||||||
|
"conversions",
|
||||||
|
"converter"
|
||||||
|
],
|
||||||
|
"author": "Andy Jansson",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/andyjansson/css-color-converter/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/andyjansson/css-color-converter",
|
||||||
|
"dependencies": {
|
||||||
|
"color-convert": "^0.5.2",
|
||||||
|
"color-name": "^1.1.4",
|
||||||
|
"css-unit-converter": "^1.1.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/cli": "^7.11.6",
|
||||||
|
"@babel/core": "^7.11.6",
|
||||||
|
"@babel/preset-env": "^7.11.5",
|
||||||
|
"eslint": "^7.9.0",
|
||||||
|
"eslint-config-airbnb-base": "^14.2.0",
|
||||||
|
"eslint-plugin-import": "^2.22.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
15
node_modules/css-unit-converter/CHANGELOG.md
generated
vendored
Normal file
15
node_modules/css-unit-converter/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# 1.1.2 - 2020-05-16
|
||||||
|
|
||||||
|
* Add TypeScript definitions (thanks to @seaneking)
|
||||||
|
|
||||||
|
# 1.1.1 - 2017-01-25
|
||||||
|
|
||||||
|
* Change decimal rounding technique
|
||||||
|
|
||||||
|
# 1.1 - 2017-01-24
|
||||||
|
|
||||||
|
* Add optional precision argument
|
||||||
|
|
||||||
|
# 1.0 - 2015-05-18
|
||||||
|
|
||||||
|
* Initial release
|
||||||
20
node_modules/css-unit-converter/LICENSE
generated
vendored
Normal file
20
node_modules/css-unit-converter/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright 2015 Andy Jansson <andyjansson@users.noreply.github.com>
|
||||||
|
|
||||||
|
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.
|
||||||
26
node_modules/css-unit-converter/README.md
generated
vendored
Normal file
26
node_modules/css-unit-converter/README.md
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# css-unit-converter [![Build Status][ci-img]][ci]
|
||||||
|
|
||||||
|
Converts CSS values from one unit to another
|
||||||
|
|
||||||
|
[PostCSS]: https://github.com/postcss/css-unit-converter
|
||||||
|
[ci-img]: https://travis-ci.org/andyjansson/css-unit-converter.svg
|
||||||
|
[ci]: https://travis-ci.org/andyjansson/css-unit-converter
|
||||||
|
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```js
|
||||||
|
npm install css-unit-converter
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
|
||||||
|
```js
|
||||||
|
var convert = require('css-unit-converter');
|
||||||
|
//convert 1 inch to pc
|
||||||
|
convert(1, 'in', 'pc'); // 6
|
||||||
|
|
||||||
|
//convert 10px to cm with a maximum of 10 decimals
|
||||||
|
convert(10, 'px', 'cm', 10); // 0.2645833333
|
||||||
|
```
|
||||||
10
node_modules/css-unit-converter/index.d.ts
generated
vendored
Normal file
10
node_modules/css-unit-converter/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
declare module 'css-unit-converter' {
|
||||||
|
export type CSSUnits = 'px' | 'cm' | 'mm' | 'in' | 'pt' | 'pc' | 'deg' | 'grad' | 'rad' | 'turn' | 's' | 'ms' | 'Hz' | 'kHz' | 'dpi' | 'dpcm' | 'dppx';
|
||||||
|
|
||||||
|
export default function (
|
||||||
|
value: number,
|
||||||
|
sourceUnit: CSSUnits,
|
||||||
|
targetUnit: CSSUnits,
|
||||||
|
precision?: number
|
||||||
|
): number;
|
||||||
|
}
|
||||||
127
node_modules/css-unit-converter/index.js
generated
vendored
Normal file
127
node_modules/css-unit-converter/index.js
generated
vendored
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
var conversions = {
|
||||||
|
// length
|
||||||
|
'px': {
|
||||||
|
'px': 1,
|
||||||
|
'cm': 96.0/2.54,
|
||||||
|
'mm': 96.0/25.4,
|
||||||
|
'in': 96,
|
||||||
|
'pt': 96.0/72.0,
|
||||||
|
'pc': 16
|
||||||
|
},
|
||||||
|
'cm': {
|
||||||
|
'px': 2.54/96.0,
|
||||||
|
'cm': 1,
|
||||||
|
'mm': 0.1,
|
||||||
|
'in': 2.54,
|
||||||
|
'pt': 2.54/72.0,
|
||||||
|
'pc': 2.54/6.0
|
||||||
|
},
|
||||||
|
'mm': {
|
||||||
|
'px': 25.4/96.0,
|
||||||
|
'cm': 10,
|
||||||
|
'mm': 1,
|
||||||
|
'in': 25.4,
|
||||||
|
'pt': 25.4/72.0,
|
||||||
|
'pc': 25.4/6.0
|
||||||
|
},
|
||||||
|
'in': {
|
||||||
|
'px': 1.0/96.0,
|
||||||
|
'cm': 1.0/2.54,
|
||||||
|
'mm': 1.0/25.4,
|
||||||
|
'in': 1,
|
||||||
|
'pt': 1.0/72.0,
|
||||||
|
'pc': 1.0/6.0
|
||||||
|
},
|
||||||
|
'pt': {
|
||||||
|
'px': 0.75,
|
||||||
|
'cm': 72.0/2.54,
|
||||||
|
'mm': 72.0/25.4,
|
||||||
|
'in': 72,
|
||||||
|
'pt': 1,
|
||||||
|
'pc': 12
|
||||||
|
},
|
||||||
|
'pc': {
|
||||||
|
'px': 6.0/96.0,
|
||||||
|
'cm': 6.0/2.54,
|
||||||
|
'mm': 6.0/25.4,
|
||||||
|
'in': 6,
|
||||||
|
'pt': 6.0/72.0,
|
||||||
|
'pc': 1
|
||||||
|
},
|
||||||
|
// angle
|
||||||
|
'deg': {
|
||||||
|
'deg': 1,
|
||||||
|
'grad': 0.9,
|
||||||
|
'rad': 180/Math.PI,
|
||||||
|
'turn': 360
|
||||||
|
},
|
||||||
|
'grad': {
|
||||||
|
'deg': 400/360,
|
||||||
|
'grad': 1,
|
||||||
|
'rad': 200/Math.PI,
|
||||||
|
'turn': 400
|
||||||
|
},
|
||||||
|
'rad': {
|
||||||
|
'deg': Math.PI/180,
|
||||||
|
'grad': Math.PI/200,
|
||||||
|
'rad': 1,
|
||||||
|
'turn': Math.PI*2
|
||||||
|
},
|
||||||
|
'turn': {
|
||||||
|
'deg': 1/360,
|
||||||
|
'grad': 1/400,
|
||||||
|
'rad': 0.5/Math.PI,
|
||||||
|
'turn': 1
|
||||||
|
},
|
||||||
|
// time
|
||||||
|
's': {
|
||||||
|
's': 1,
|
||||||
|
'ms': 1/1000
|
||||||
|
},
|
||||||
|
'ms': {
|
||||||
|
's': 1000,
|
||||||
|
'ms': 1
|
||||||
|
},
|
||||||
|
// frequency
|
||||||
|
'Hz': {
|
||||||
|
'Hz': 1,
|
||||||
|
'kHz': 1000
|
||||||
|
},
|
||||||
|
'kHz': {
|
||||||
|
'Hz': 1/1000,
|
||||||
|
'kHz': 1
|
||||||
|
},
|
||||||
|
// resolution
|
||||||
|
'dpi': {
|
||||||
|
'dpi': 1,
|
||||||
|
'dpcm': 1.0/2.54,
|
||||||
|
'dppx': 1/96
|
||||||
|
},
|
||||||
|
'dpcm': {
|
||||||
|
'dpi': 2.54,
|
||||||
|
'dpcm': 1,
|
||||||
|
'dppx': 2.54/96.0
|
||||||
|
},
|
||||||
|
'dppx': {
|
||||||
|
'dpi': 96,
|
||||||
|
'dpcm': 96.0/2.54,
|
||||||
|
'dppx': 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = function (value, sourceUnit, targetUnit, precision) {
|
||||||
|
if (!conversions.hasOwnProperty(targetUnit))
|
||||||
|
throw new Error("Cannot convert to " + targetUnit);
|
||||||
|
|
||||||
|
if (!conversions[targetUnit].hasOwnProperty(sourceUnit))
|
||||||
|
throw new Error("Cannot convert from " + sourceUnit + " to " + targetUnit);
|
||||||
|
|
||||||
|
var converted = conversions[targetUnit][sourceUnit] * value;
|
||||||
|
|
||||||
|
if (precision !== false) {
|
||||||
|
precision = Math.pow(10, parseInt(precision) || 5);
|
||||||
|
return Math.round(converted * precision) / precision;
|
||||||
|
}
|
||||||
|
|
||||||
|
return converted;
|
||||||
|
};
|
||||||
29
node_modules/css-unit-converter/package.json
generated
vendored
Normal file
29
node_modules/css-unit-converter/package.json
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "css-unit-converter",
|
||||||
|
"version": "1.1.2",
|
||||||
|
"description": "Converts CSS values from one unit to another",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "node test/test.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/andyjansson/css-unit-converter.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"css",
|
||||||
|
"value",
|
||||||
|
"unit",
|
||||||
|
"converter",
|
||||||
|
"convert"
|
||||||
|
],
|
||||||
|
"author": "Andy Jansson",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/andyjansson/css-unit-converter/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/andyjansson/css-unit-converter",
|
||||||
|
"devDependencies": {
|
||||||
|
"tape": "^4.6.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
120
package-lock.json
generated
120
package-lock.json
generated
@@ -9,7 +9,8 @@
|
|||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0"
|
"@actions/core": "^1.10.0",
|
||||||
|
"badge-maker": "^3.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/core": {
|
"node_modules/@actions/core": {
|
||||||
@@ -29,6 +30,68 @@
|
|||||||
"tunnel": "^0.0.6"
|
"tunnel": "^0.0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/anafanafo": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/anafanafo/-/anafanafo-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-Nlfq7NC4AOkTJerWRIZcOAiMNtIDVIGWGvQ98O7Jl6Kr2Dk0dX5u4MqN778kSRTy5KRqchpLdF2RtLFEz9FVkQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"char-width-table-consumer": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/badge-maker": {
|
||||||
|
"version": "3.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/badge-maker/-/badge-maker-3.3.1.tgz",
|
||||||
|
"integrity": "sha512-OO/PS7Zg2E6qaUWzHEHt21Q5VjcFBAJVA8ztgT/fIdSZFBUwoyeo0ZhA6V5tUM8Vcjq8DJl6jfGhpjESssyqMQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"anafanafo": "2.0.0",
|
||||||
|
"css-color-converter": "^2.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"badge": "lib/badge-cli.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 10",
|
||||||
|
"npm": ">= 5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/binary-search": {
|
||||||
|
"version": "1.3.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/binary-search/-/binary-search-1.3.6.tgz",
|
||||||
|
"integrity": "sha512-nbE1WxOTTrUWIfsfZ4aHGYu5DOuNkbxGokjV6Z2kxfJK3uaAb8zNK1muzOeipoLHZjInT4Br88BHpzevc681xA=="
|
||||||
|
},
|
||||||
|
"node_modules/char-width-table-consumer": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/char-width-table-consumer/-/char-width-table-consumer-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-Fz4UD0LBpxPgL9i29CJ5O4KANwaMnX/OhhbxzvNa332h+9+nRKyeuLw4wA51lt/ex67+/AdsoBQJF3kgX2feYQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"binary-search": "^1.3.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/color-convert": {
|
||||||
|
"version": "0.5.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-0.5.3.tgz",
|
||||||
|
"integrity": "sha512-RwBeO/B/vZR3dfKL1ye/vx8MHZ40ugzpyfeVG5GsiuGnrlMWe2o8wxBbLCpw9CsxV+wHuzYlCiWnybrIA0ling=="
|
||||||
|
},
|
||||||
|
"node_modules/color-name": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
||||||
|
},
|
||||||
|
"node_modules/css-color-converter": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/css-color-converter/-/css-color-converter-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-oLIG2soZz3wcC3aAl/7Us5RS8Hvvc6I8G8LniF/qfMmrm7fIKQ8RIDDRZeKyGL2SrWfNqYspuLShbnjBMVWm8g==",
|
||||||
|
"dependencies": {
|
||||||
|
"color-convert": "^0.5.2",
|
||||||
|
"color-name": "^1.1.4",
|
||||||
|
"css-unit-converter": "^1.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/css-unit-converter": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/css-unit-converter/-/css-unit-converter-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-IiJwMC8rdZE0+xiEZHeru6YoONC4rfPMqGm2W85jMIbkFvv5nFTwJVFHam2eFrN6txmoUYFAFXiv8ICVeTO0MA=="
|
||||||
|
},
|
||||||
"node_modules/tunnel": {
|
"node_modules/tunnel": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
||||||
@@ -64,6 +127,61 @@
|
|||||||
"tunnel": "^0.0.6"
|
"tunnel": "^0.0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"anafanafo": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/anafanafo/-/anafanafo-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-Nlfq7NC4AOkTJerWRIZcOAiMNtIDVIGWGvQ98O7Jl6Kr2Dk0dX5u4MqN778kSRTy5KRqchpLdF2RtLFEz9FVkQ==",
|
||||||
|
"requires": {
|
||||||
|
"char-width-table-consumer": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"badge-maker": {
|
||||||
|
"version": "3.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/badge-maker/-/badge-maker-3.3.1.tgz",
|
||||||
|
"integrity": "sha512-OO/PS7Zg2E6qaUWzHEHt21Q5VjcFBAJVA8ztgT/fIdSZFBUwoyeo0ZhA6V5tUM8Vcjq8DJl6jfGhpjESssyqMQ==",
|
||||||
|
"requires": {
|
||||||
|
"anafanafo": "2.0.0",
|
||||||
|
"css-color-converter": "^2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"binary-search": {
|
||||||
|
"version": "1.3.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/binary-search/-/binary-search-1.3.6.tgz",
|
||||||
|
"integrity": "sha512-nbE1WxOTTrUWIfsfZ4aHGYu5DOuNkbxGokjV6Z2kxfJK3uaAb8zNK1muzOeipoLHZjInT4Br88BHpzevc681xA=="
|
||||||
|
},
|
||||||
|
"char-width-table-consumer": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/char-width-table-consumer/-/char-width-table-consumer-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-Fz4UD0LBpxPgL9i29CJ5O4KANwaMnX/OhhbxzvNa332h+9+nRKyeuLw4wA51lt/ex67+/AdsoBQJF3kgX2feYQ==",
|
||||||
|
"requires": {
|
||||||
|
"binary-search": "^1.3.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"color-convert": {
|
||||||
|
"version": "0.5.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-0.5.3.tgz",
|
||||||
|
"integrity": "sha512-RwBeO/B/vZR3dfKL1ye/vx8MHZ40ugzpyfeVG5GsiuGnrlMWe2o8wxBbLCpw9CsxV+wHuzYlCiWnybrIA0ling=="
|
||||||
|
},
|
||||||
|
"color-name": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
||||||
|
},
|
||||||
|
"css-color-converter": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/css-color-converter/-/css-color-converter-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-oLIG2soZz3wcC3aAl/7Us5RS8Hvvc6I8G8LniF/qfMmrm7fIKQ8RIDDRZeKyGL2SrWfNqYspuLShbnjBMVWm8g==",
|
||||||
|
"requires": {
|
||||||
|
"color-convert": "^0.5.2",
|
||||||
|
"color-name": "^1.1.4",
|
||||||
|
"css-unit-converter": "^1.1.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"css-unit-converter": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/css-unit-converter/-/css-unit-converter-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-IiJwMC8rdZE0+xiEZHeru6YoONC4rfPMqGm2W85jMIbkFvv5nFTwJVFHam2eFrN6txmoUYFAFXiv8ICVeTO0MA=="
|
||||||
|
},
|
||||||
"tunnel": {
|
"tunnel": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"name": "dynamic-badges-action",
|
"name": "dynamic-badges-action",
|
||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
"description": "A GitHub Action which uses shields.io to create custom badges and uploads the to a gist.",
|
"description": "A GitHub Action which uses shields.io to create custom badges and uploads the to a gist.",
|
||||||
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/Schneegans/dynamic-badges-action#readme",
|
"homepage": "https://github.com/Schneegans/dynamic-badges-action#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0"
|
"@actions/core": "^1.10.0",
|
||||||
|
"badge-maker": "^3.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user