From c5a5384e846f242e901e859fe600d695d8990a9a Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 14 Oct 2023 15:20:49 +0800 Subject: legacy browser support via plugins from postcss --- node_modules/rgb-hex/index.d.ts | 27 ++++++++++++++++++++++++ node_modules/rgb-hex/index.js | 38 ++++++++++++++++++++++++++++++++++ node_modules/rgb-hex/license | 9 ++++++++ node_modules/rgb-hex/package.json | 36 ++++++++++++++++++++++++++++++++ node_modules/rgb-hex/readme.md | 43 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 node_modules/rgb-hex/index.d.ts create mode 100644 node_modules/rgb-hex/index.js create mode 100644 node_modules/rgb-hex/license create mode 100644 node_modules/rgb-hex/package.json create mode 100644 node_modules/rgb-hex/readme.md (limited to 'node_modules/rgb-hex') diff --git a/node_modules/rgb-hex/index.d.ts b/node_modules/rgb-hex/index.d.ts new file mode 100644 index 00000000..2d4a7548 --- /dev/null +++ b/node_modules/rgb-hex/index.d.ts @@ -0,0 +1,27 @@ +/** +Convert RGB(A) color to HEX. + +@example +``` +import rgbHex = require('rgb-hex'); + +rgbHex(65, 131, 196); +//=> '4183c4' + +rgbHex('rgb(40, 42, 54)'); +//=> '282a36' + +rgbHex(65, 131, 196, 0.2); +//=> '4183c433' + +rgbHex(40, 42, 54, '75%'); +//=> '282a36bf' + +rgbHex('rgba(40, 42, 54, 75%)'); +//=> '282a36bf' +``` +*/ +declare function rgbHex(rgba: string): string; +declare function rgbHex(red: number, green: number, blue: number, alpha?: string | number): string; + +export = rgbHex; diff --git a/node_modules/rgb-hex/index.js b/node_modules/rgb-hex/index.js new file mode 100644 index 00000000..f7b8f4e7 --- /dev/null +++ b/node_modules/rgb-hex/index.js @@ -0,0 +1,38 @@ +'use strict'; +/* eslint-disable no-mixed-operators */ +module.exports = (red, green, blue, alpha) => { + const isPercent = (red + (alpha || '')).toString().includes('%'); + + if (typeof red === 'string') { + [red, green, blue, alpha] = red.match(/(0?\.?\d{1,3})%?\b/g).map(Number); + } else if (alpha !== undefined) { + alpha = parseFloat(alpha); + } + + if (typeof red !== 'number' || + typeof green !== 'number' || + typeof blue !== 'number' || + red > 255 || + green > 255 || + blue > 255 + ) { + throw new TypeError('Expected three numbers below 256'); + } + + if (typeof alpha === 'number') { + if (!isPercent && alpha >= 0 && alpha <= 1) { + alpha = Math.round(255 * alpha); + } else if (isPercent && alpha >= 0 && alpha <= 100) { + alpha = Math.round(255 * alpha / 100); + } else { + throw new TypeError(`Expected alpha value (${alpha}) as a fraction or percentage`); + } + + alpha = (alpha | 1 << 8).toString(16).slice(1); + } else { + alpha = ''; + } + + return ((blue | green << 8 | red << 16) | 1 << 24).toString(16).slice(1) + alpha; +}; +/* eslint-enable no-mixed-operators */ diff --git a/node_modules/rgb-hex/license b/node_modules/rgb-hex/license new file mode 100644 index 00000000..e7af2f77 --- /dev/null +++ b/node_modules/rgb-hex/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus (sindresorhus.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. diff --git a/node_modules/rgb-hex/package.json b/node_modules/rgb-hex/package.json new file mode 100644 index 00000000..b10615c6 --- /dev/null +++ b/node_modules/rgb-hex/package.json @@ -0,0 +1,36 @@ +{ + "name": "rgb-hex", + "version": "3.0.0", + "description": "Convert RGB(A) color to HEX", + "license": "MIT", + "repository": "sindresorhus/rgb-hex", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=8" + }, + "scripts": { + "test": "xo && ava && tsd" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "rgb", + "hex", + "color", + "colour", + "convert", + "conversion", + "converter" + ], + "devDependencies": { + "ava": "^1.4.1", + "tsd": "^0.7.2", + "xo": "^0.24.0" + } +} diff --git a/node_modules/rgb-hex/readme.md b/node_modules/rgb-hex/readme.md new file mode 100644 index 00000000..528c91a4 --- /dev/null +++ b/node_modules/rgb-hex/readme.md @@ -0,0 +1,43 @@ +# rgb-hex [![Build Status](https://travis-ci.org/sindresorhus/rgb-hex.svg?branch=master)](https://travis-ci.org/sindresorhus/rgb-hex) + +> Convert RGB(A) color to HEX + + +## Install + +``` +$ npm install rgb-hex +``` + + +## Usage + +```js +const rgbHex = require('rgb-hex'); + +rgbHex(65, 131, 196); +//=> '4183c4' + +rgbHex('rgb(40, 42, 54)'); +//=> '282a36' + +rgbHex(65, 131, 196, 0.2); +//=> '4183c433' + +rgbHex(40, 42, 54, '75%'); +//=> '282a36bf' + +rgbHex('rgba(40, 42, 54, 75%)'); +//=> '282a36bf' +``` + + +## Related + +- [rgb-hex-cli](https://github.com/sindresorhus/rgb-hex-cli) - CLI for this module +- [hex-rgb](https://github.com/sindresorhus/hex-rgb) - Convert HEX color to RGB + + +## License + +MIT © [Sindre Sorhus](https://sindresorhus.com) -- cgit v1.2.3