Jesus sucks

This commit is contained in:
2024-12-17 13:23:11 -08:00
parent 3a3382ffff
commit b2dbf46d28
13060 changed files with 1310035 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
# Changes to Convert Colors
### 1.4.0 (January 27, 2018)
- Add LCH conversions
- Allow fallbacks in RGB conversions (for gray conversions)
- Add Lab and LCH tests
- Simplify test array joining
- Rename references from "LAB" to "Lab"
### 1.3.0 (January 25, 2018)
- Export all converter combinations of `rgb`, `hsl`, `hwb`, `lab`, `hsv`,
`xyz`, and also the `rgb2hue` converter
- Organize library into files
### 1.2.0 (January 24, 2018)
- Export `rgb2lab`, `lab2rgb`, `hsl2lab`, etc. converters
### 1.1.0 (January 22, 2018)
- Export `rgb2hue` converter
### 1.0.0 (January 21, 2018)
- Initial version

View File

@@ -0,0 +1,108 @@
# 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:
1. the right to reproduce, adapt, distribute, perform, display, communicate,
and translate a Work;
2. moral rights retained by the original author(s) and/or performer(s);
3. publicity and privacy rights pertaining to a persons image or likeness
depicted in a Work;
4. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(i), below;
5. rights protecting the extraction, dissemination, use and reuse of data in
a Work;
6. 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
7. 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 Affirmers 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 Affirmers 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 Affirmers 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
Affirmers 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 Affirmers 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 Affirmers express Statement of Purpose.
4. Limitations and Disclaimers.
1. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
2. 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.
3. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any persons 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.
4. 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/.

View File

@@ -0,0 +1,87 @@
# Convert Colors [<img src="https://cdn.worldvectorlogo.com/logos/nodejs-icon.svg" alt="Convert Colors" width="90" height="90" align="right">][Convert Colors]
[![NPM Version][npm-img]][npm-url]
[![Linux Build Status][cli-img]][cli-url]
[![Windows Build Status][win-img]][win-url]
[Convert Colors] converts colors between RGB, HSL, HWB, Lab, LCH, HSV, and XYZ.
```js
import convert from '@csstools/convert-colors';
convert.rgb2hsl(100, 100, 100); // [ 0, 0, 100 ]
convert.rgb2hwb(100, 100, 100); // [ 0, 100, 0 ]
convert.hsl2rgb(0, 0, 100); // [ 0, 100, 0 ]
convert.hsl2hwb(0, 0, 100); // [ 0, 100, 0 ]
convert.hwb2rgb(0, 100, 0); // [ 0, 0, 100 ]
convert.hwb2hsl(0, 100, 0); // [ 0, 0, 100 ]
convert.rgb2hue(0, 0, 100); // 240
```
## Usage
Add [Convert Colors] to your build tool:
```bash
npm install @csstools/convert-colors --save-dev
```
## Features
Conversions work by taking arguments that represents a color in one color space
and returning an array of that same color in another color space.
- rgb2hsl(r, g, b)
- rgb2hwb(r, g, b)
- rgb2lab(r, g, b)
- rgb2lch(r, g, b)
- rgb2hsv(r, g, b)
- rgb2xyz(r, g, b)
- hsl2rgb(h, s, l)
- hsl2hwb(h, s, l)
- hsl2lab(h, s, l)
- hsl2lch(h, s, l)
- hsl2hsv(h, s, l)
- hsl2xyz(h, s, l)
- hwb2rgb(h, w, b)
- hwb2hsl(h, w, b)
- hwb2lab(h, w, b)
- hwb2lch(h, w, b)
- hwb2hsv(h, w, b)
- hwb2xyz(h, w, b)
- lab2rgb(l, a, b)
- lab2hsl(l, a, b)
- lab2hwb(l, a, b)
- lab2lch(l, a, b)
- lab2hsv(l, a, b)
- lab2xyz(l, a, b)
- lch2rgb(l, c, h)
- lch2hsl(l, c, h)
- lch2hwb(l, c, h)
- lch2lab(l, c, h)
- lch2hsv(l, c, h)
- lch2xyz(l, c, h)
- hsv2rgb(h, s, v)
- hsv2hsl(h, s, v)
- hsv2hwb(h, s, v)
- hsv2lab(h, s, v)
- hsv2lch(h, s, v)
- hsv2xyz(h, s, v)
- xyz2rgb(x, y, z)
- xyz2hsl(x, y, z)
- xyz2hwb(x, y, z)
- xyz2lab(x, y, z)
- xyz2lch(x, y, z)
- xyz2hsv(x, y, z)
[npm-url]: https://www.npmjs.com/package/@csstools/convert-colors
[npm-img]: https://img.shields.io/npm/v/@csstools/convert-colors.svg
[cli-url]: https://travis-ci.org/jonathantneal/convert-colors
[cli-img]: https://img.shields.io/travis/jonathantneal/convert-colors.svg
[win-url]: https://ci.appveyor.com/project/jonathantneal/convert-colors
[win-img]: https://img.shields.io/appveyor/ci/jonathantneal/convert-colors.svg
[Convert Colors]: https://github.com/jonathantneal/convert-colors

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,359 @@
import { rgb2hsl, hsl2rgb } from './lib/rgb-hsl';
import { rgb2hwb, hwb2rgb } from './lib/rgb-hwb';
import { rgb2hsv, hsv2rgb } from './lib/rgb-hsv';
import { rgb2xyz, xyz2rgb } from './lib/rgb-xyz';
import { hsl2hsv, hsv2hsl } from './lib/hsl-hsv';
import { hwb2hsv, hsv2hwb } from './lib/hwb-hsv';
import { lab2xyz, xyz2lab } from './lib/lab-xyz';
import { lab2lch, lch2lab } from './lib/lab-lch';
import { rgb2hue } from './lib/util';
/* Convert between RGB and Lab
/* ========================================================================== */
function rgb2lab(rgbR, rgbG, rgbB) {
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
const [ labL, labA, labB ] = xyz2lab(xyzX, xyzY, xyzZ);
return [ labL, labA, labB ];
}
function lab2rgb(labL, labA, labB) {
const [ xyzX, xyzY, xyzZ ] = lab2xyz(labL, labA, labB);
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
return [ rgbR, rgbG, rgbB ];
}
/* Convert between RGB and LCH
/* ========================================================================== */
function rgb2lch(rgbR, rgbG, rgbB) {
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
const [ labL, labA, labB ] = xyz2lab(xyzX, xyzY, xyzZ);
const [ lchL, lchC, lchH ] = lab2lch(labL, labA, labB);
return [ lchL, lchC, lchH ];
}
function lch2rgb(lchL, lchC, lchH) {
const [ labL, labA, labB ] = lch2lab(lchL, lchC, lchH);
const [ xyzX, xyzY, xyzZ ] = lab2xyz(labL, labA, labB);
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
return [ rgbR, rgbG, rgbB ];
}
/* Convert between HSL and HWB
/* ========================================================================== */
function hwb2hsl(hwbH, hwbW, hwbB) {
const [ hsvH, hsvS, hsvV ] = hwb2hsv(hwbH, hwbW, hwbB);
const [ hslH, hslS, hslL ] = hsv2hsl(hsvH, hsvS, hsvV);
return [ hslH, hslS, hslL ];
}
function hsl2hwb(hslH, hslS, hslL) {
const [ , hsvS, hsvV ] = hsl2hsv(hslH, hslS, hslL);
const [ , hwbW, hwbB ] = hsv2hwb(hslH, hsvS, hsvV);
return [ hslH, hwbW, hwbB ];
}
/* Convert between HSL and Lab
/* ========================================================================== */
function hsl2lab(hslH, hslS, hslL) {
const [ rgbR, rgbG, rgbB ] = hsl2rgb(hslH, hslS, hslL);
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
const [ labL, labA, labB ] = xyz2lab(xyzX, xyzY, xyzZ);
return [ labL, labA, labB ];
}
function lab2hsl(labL, labA, labB, fallbackhue) {
const [ xyzX, xyzY, xyzZ ] = lab2xyz(labL, labA, labB);
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
const [ hslH, hslS, hslL ] = rgb2hsl(rgbR, rgbG, rgbB, fallbackhue);
return [ hslH, hslS, hslL ];
}
/* Convert between HSL and LCH
/* ========================================================================== */
function hsl2lch(hslH, hslS, hslL) {
const [ rgbR, rgbG, rgbB ] = hsl2rgb(hslH, hslS, hslL);
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
const [ labL, labA, labB ] = xyz2lab(xyzX, xyzY, xyzZ);
const [ lchL, lchC, lchH ] = lab2lch(labL, labA, labB);
return [ lchL, lchC, lchH ];
}
function lch2hsl(lchL, lchC, lchH, fallbackhue) {
const [ labL, labA, labB ] = lch2lab(lchL, lchC, lchH);
const [ xyzX, xyzY, xyzZ ] = lab2xyz(labL, labA, labB);
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
const [ hslH, hslS, hslL ] = rgb2hsl(rgbR, rgbG, rgbB, fallbackhue);
return [ hslH, hslS, hslL ];
}
/* Convert between HSL and XYZ
/* ========================================================================== */
function hsl2xyz(hslH, hslS, hslL) {
const [ rgbR, rgbG, rgbB ] = hsl2rgb(hslH, hslS, hslL);
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
return [ xyzX, xyzY, xyzZ ];
}
function xyz2hsl(xyzX, xyzY, xyzZ, fallbackhue) {
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
const [ hslH, hslS, hslL ] = rgb2hsl(rgbR, rgbG, rgbB, fallbackhue);
return [ hslH, hslS, hslL ];
}
/* Convert between HWB and Lab
/* ========================================================================== */
function hwb2lab(hwbH, hwbW, hwbB) {
const [ rgbR, rgbG, rgbB ] = hwb2rgb(hwbH, hwbW, hwbB);
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
const [ labL, labA, labB ] = xyz2lab(xyzX, xyzY, xyzZ);
return [ labL, labA, labB ];
}
function lab2hwb(labL, labA, labB, fallbackhue) {
const [ xyzX, xyzY, xyzZ ] = lab2xyz(labL, labA, labB);
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
const [ hwbH, hwbW, hwbB ] = rgb2hwb(rgbR, rgbG, rgbB, fallbackhue);
return [ hwbH, hwbW, hwbB ];
}
/* Convert between HWB and LCH
/* ========================================================================== */
function hwb2lch(hwbH, hwbW, hwbB) {
const [ rgbR, rgbG, rgbB ] = hwb2rgb(hwbH, hwbW, hwbB);
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
const [ labL, labA, labB ] = xyz2lab(xyzX, xyzY, xyzZ);
const [ lchL, lchC, lchH ] = lab2lch(labL, labA, labB);
return [ lchL, lchC, lchH ];
}
function lch2hwb(lchL, lchC, lchH, fallbackhue) {
const [ labL, labA, labB ] = lch2lab(lchL, lchC, lchH);
const [ xyzX, xyzY, xyzZ ] = lab2xyz(labL, labA, labB);
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
const [ hwbH, hwbW, hwbB ] = rgb2hwb(rgbR, rgbG, rgbB, fallbackhue);
return [ hwbH, hwbW, hwbB ];
}
/* Convert between HWB and XYZ
/* ========================================================================== */
function hwb2xyz(hwbH, hwbW, hwbB) {
const [ rgbR, rgbG, rgbB ] = hwb2rgb(hwbH, hwbW, hwbB);
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
return [ xyzX, xyzY, xyzZ ];
}
function xyz2hwb(xyzX, xyzY, xyzZ, fallbackhue) {
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
const [ hwbH, hwbW, hwbB ] = rgb2hwb(rgbR, rgbG, rgbB, fallbackhue);
return [ hwbH, hwbW, hwbB ];
}
/* Convert between HSV and Lab
/* ========================================================================== */
function hsv2lab(hsvH, hsvS, hsvV) {
const [ rgbR, rgbG, rgbB ] = hsv2rgb(hsvH, hsvS, hsvV);
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
const [ labL, labA, labB ] = xyz2lab(xyzX, xyzY, xyzZ);
return [ labL, labA, labB ];
}
function lab2hsv(labL, labA, labB, fallbackhue) {
const [ xyzX, xyzY, xyzZ ] = lab2xyz(labL, labA, labB);
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
const [ hsvH, hsvS, hsvV ] = rgb2hsv(rgbR, rgbG, rgbB, fallbackhue);
return [ hsvH, hsvS, hsvV ];
}
/* Convert between HSV and LCH
/* ========================================================================== */
function hsv2lch(hsvH, hsvS, hsvV) {
const [ rgbR, rgbG, rgbB ] = hsv2rgb(hsvH, hsvS, hsvV);
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
const [ labL, labA, labB ] = xyz2lab(xyzX, xyzY, xyzZ);
const [ lchL, lchC, lchH ] = lab2lch(labL, labA, labB);
return [ lchL, lchC, lchH ];
}
function lch2hsv(lchL, lchC, lchH, fallbackhue) {
const [ labL, labA, labB ] = lch2lab(lchL, lchC, lchH);
const [ xyzX, xyzY, xyzZ ] = lab2xyz(labL, labA, labB);
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
const [ hsvH, hsvS, hsvV ] = rgb2hsv(rgbR, rgbG, rgbB, fallbackhue);
return [ hsvH, hsvS, hsvV ];
}
/* Convert between HSV and XYZ
/* ========================================================================== */
function hsv2xyz(hsvH, hsvS, hsvV) {
const [ rgbR, rgbG, rgbB ] = hsv2rgb(hsvH, hsvS, hsvV);
const [ xyzX, xyzY, xyzZ ] = rgb2xyz(rgbR, rgbG, rgbB);
return [ xyzX, xyzY, xyzZ ];
}
function xyz2hsv(xyzX, xyzY, xyzZ, fallbackhue) {
const [ rgbR, rgbG, rgbB ] = xyz2rgb(xyzX, xyzY, xyzZ);
const [ hsvH, hsvS, hsvV ] = rgb2hsv(rgbR, rgbG, rgbB, fallbackhue);
return [ hsvH, hsvS, hsvV ];
}
/* Convert between XYZ and LCH
/* ========================================================================== */
function xyz2lch(xyzX, xyzY, xyzZ) {
const [ labL, labA, labB ] = xyz2lab(xyzX, xyzY, xyzZ);
const [ lchL, lchC, lchH ] = lab2lch(labL, labA, labB);
return [ lchL, lchC, lchH ];
}
function lch2xyz(lchL, lchC, lchH) {
const [ labL, labA, labB ] = lch2lab(lchL, lchC, lchH);
const [ xyzX, xyzY, xyzZ ] = lab2xyz(labL, labA, labB);
return [ xyzX, xyzY, xyzZ ];
}
/* All Conversions
/* ========================================================================== */
export {
rgb2hsl,
rgb2hwb,
rgb2lab,
rgb2lch,
rgb2hsv,
rgb2xyz,
hsl2rgb,
hsl2hwb,
hsl2lab,
hsl2lch,
hsl2hsv,
hsl2xyz,
hwb2rgb,
hwb2hsl,
hwb2lab,
hwb2lch,
hwb2hsv,
hwb2xyz,
lab2rgb,
lab2hsl,
lab2hwb,
lab2lch,
lab2hsv,
lab2xyz,
lch2rgb,
lch2hsl,
lch2hwb,
lch2lab,
lch2hsv,
lch2xyz,
hsv2rgb,
hsv2hsl,
hsv2hwb,
hsv2lab,
hsv2lch,
hsv2xyz,
xyz2rgb,
xyz2hsl,
xyz2hwb,
xyz2lab,
xyz2lch,
xyz2hsv,
rgb2hue
};
export default {
rgb2hsl,
rgb2hwb,
rgb2lab,
rgb2lch,
rgb2hsv,
rgb2xyz,
hsl2rgb,
hsl2hwb,
hsl2lab,
hsl2lch,
hsl2hsv,
hsl2xyz,
hwb2rgb,
hwb2hsl,
hwb2lab,
hwb2lch,
hwb2hsv,
hwb2xyz,
lab2rgb,
lab2hsl,
lab2hwb,
lab2lch,
lab2hsv,
lab2xyz,
lch2rgb,
lch2hsl,
lch2hwb,
lch2lab,
lch2hsv,
lch2xyz,
hsv2rgb,
hsv2hsl,
hsv2hwb,
hsv2lab,
hsv2lch,
hsv2xyz,
xyz2rgb,
xyz2hsl,
xyz2hwb,
xyz2lab,
xyz2lch,
xyz2hsv,
rgb2hue
};

View File

@@ -0,0 +1,70 @@
{
"name": "@csstools/convert-colors",
"version": "1.4.0",
"description": "Convert colors between RGB, HSL, and HWB",
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
"license": "CC0-1.0",
"repository": "jonathantneal/convert-colors",
"homepage": "https://github.com/jonathantneal/convert-colors#readme",
"bugs": "https://github.com/jonathantneal/convert-colors/issues",
"main": "index.bundle.js",
"module": "index.js",
"files": [
"index.js",
"index.bundle.js",
"lib"
],
"scripts": {
"prepublishOnly": "npm test",
"pretest": "rollup -c .rollup.js --silent",
"test": "echo 'Running tests...'; npm run test:ec && npm run test:js && npm run test:tape",
"test:ec": "echint test",
"test:js": "eslint *.js --cache --ignore-path .gitignore --quiet",
"test:tape": "node .tape"
},
"engines": {
"node": ">=4.0.0"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6",
"echint": "^4.0",
"eslint": "^4.15",
"eslint-config-dev": "2.0",
"pre-commit": "^1.2",
"rollup": "^0.54",
"rollup-plugin-babel": "^3.0"
},
"eslintConfig": {
"extends": "dev",
"rules": {
"max-params": [
2,
4
]
}
},
"keywords": [
"colors",
"converts",
"conversions",
"converting",
"css",
"rgb",
"hsl",
"hwb",
"lab",
"lch",
"hsv",
"xyz",
"red",
"green",
"blue",
"hue",
"saturation",
"lightness",
"whiteness",
"blackness",
"cie"
]
}

View File

@@ -0,0 +1,106 @@
# 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:
1. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
2. moral rights retained by the original author(s) and/or performer(s);
3. publicity and privacy rights pertaining to a persons image or likeness
depicted in a Work;
4. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(i), below;
5. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
6. 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
7. 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 Affirmers 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 Affirmers 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 Affirmers 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
Affirmers 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 Affirmers 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 Affirmers express Statement of Purpose.
4. Limitations and Disclaimers.
1. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
2. 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.
3. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any persons 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.
4. 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/.

View File

@@ -0,0 +1,100 @@
# Sass Import Resolve [<img src="https://jonathantneal.github.io/sass-import-resolve/sass-logo.svg" alt="Sass Logo" width="90" height="90" align="right">][Sass Import Resolve]
[![NPM Version][npm-img]][npm-url]
[![Linux Build Status][cli-img]][cli-url]
[![Windows Build Status][win-img]][win-url]
[![Gitter Chat][git-img]][git-url]
[Sass Import Resolve] resolves the path and contents of Sass imports, following
the [Sass Import Resolve Specification].
```sh
npm install @csstools/sass-import-resolve
```
## The Resolve Method
The `resolve` method takes any path and returns its absolute path, as
resolved by the [Sass Import Resolve Specification].
```js
import resolve from '@csstools/sass-import-resolve';
const { file } = resolve('path/to/sass-file');
```
The `resolve` method may also return the contents of the resolved file.
```js
const { file, contents } = resolve('path/to/sass-file', {
readFile: true
});
```
The `resolve` method may also resolve the path from a specific directory.
```js
const { file } = resolve('sass-file', {
cwd: 'path/to'
});
```
The `resolve` method may also share its resolved cache.
```js
const sharedCache = {};
const { file } = resolve('path/to/sass-file', {
cache: sharedCache
});
/* sharedCache {
"/absolute/path/to/sass-file": Promise {
file,
contents (when `readFile` is true)
}
} */
```
## The Resolve Algorithm
When `@import` is called, the following high-level algorithm is used to resolve
the location of a file within `url(id)` from `cwd`:
1. if `id` begins with `/`
1. `cwd` is the filesystem root
2. `file` is `cwd/id`
3. `base` is base path of `file`
4. `dir` is directory path of `file`
5. if `base` ends with `.sass`, `.scss`, or `.css`
1. test whether `file` exists
2. if `base` does not start with `_`
1. test whether `dir/_base` exists
6. otherwise
1. test whether `dir/base.scss` exists
2. test whether `dir/base.sass` exists
3. test whether `dir/base.css` exists
4. if `base` does not start with `_`
1. test whether `dir/_base.scss` exists
2. test whether `dir/_base.sass` exists
3. test whether `dir/_base.css` exists
6. if the length of existing files is `1`
1. return the existing file
7. otherwise, if the length of existing files is greater than `1`
1. throw `"It's not clear which file to import"`
8. otherwise, if `base` does not end with `.css`
1. throw `"File to import not found or unreadable"`
See the [Sass Import Resolve Specification] for more details.
[Sass Import Resolve]: https://github.com/jonathantneal/sass-import-resolve
[Sass Import Resolve Specification]: https://jonathantneal.github.io/sass-import-resolve
[cli-url]: https://travis-ci.org/jonathantneal/sass-import-resolve
[cli-img]: https://img.shields.io/travis/jonathantneal/sass-import-resolve.svg
[git-url]: https://gitter.im/postcss/postcss
[git-img]: https://img.shields.io/badge/chat-gitter-blue.svg
[npm-url]: https://www.npmjs.com/package/@csstools/sass-import-resolve
[npm-img]: https://img.shields.io/npm/v/@csstools/sass-import-resolve.svg
[win-url]: https://ci.appveyor.com/project/jonathantneal/sass-import-resolve
[win-img]: https://img.shields.io/appveyor/ci/jonathantneal/sass-import-resolve.svg

View File

@@ -0,0 +1,147 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = resolve;
var _fs = require('fs');
var _path = require('path');
/* Resolve the absolute path of a file in Sass
/* ========================================================================== */
function resolve(id, rawopts) {
var opts = Object.assign({
cache: {},
cwd: process.cwd(),
readFile: false
}, rawopts);
// if `id` starts with `/`
if (starts_with_root(id)) {
// `cwd` is the filesystem root
opts.cwd = '';
}
// `file` is `cwd/id`
var file = (0, _path.join)(opts.cwd, id);
// `base` is the last segment path of `file`
var base = (0, _path.basename)(file);
// `dir` is all but the last segment path of `file`
var dir = (0, _path.dirname)(file);
var tests = [];
// if `base` ends with `.sass`, `.scss`, or `.css`
if (ends_with_sass_extension(base) || ends_with_css_extension(base)) {
// test whether `file` exists
tests.push(test_file(file, opts));
// if `base` does not start with `_`
if (!starts_with_partial(base)) {
// test whether `dir/_base` exists
tests.push(test_file((0, _path.join)(dir, '_' + base), opts));
}
} else {
// otherwise
tests.push(
// test whether `dir/base.scss` exists
test_file((0, _path.join)(dir, base + '.scss'), opts),
// test whether `dir/base.sass` exists
test_file((0, _path.join)(dir, base + '.sass'), opts),
// test whether `dir/base.css` exists
test_file((0, _path.join)(dir, base + '.css'), opts));
// if `base` does not start with `_`
if (!starts_with_partial(base)) {
tests.push(
// test whether `dir/_base.scss` exists
test_file((0, _path.join)(dir, '_' + base + '.scss'), opts),
// test whether `dir/_base.sass` exists
test_file((0, _path.join)(dir, '_' + base + '.sass'), opts),
// test whether `dir/_base.css` exists
test_file((0, _path.join)(dir, '_' + base + '.css'), opts));
}
}
return Promise.all(tests).then(function (test) {
return test.filter(function (result) {
return result;
});
}).then(function (files) {
// if the length of existing files is `1`
if (files.length === 1) {
// return the existing file
return files[0];
}
// otherwise, if the length of existing files is greater than `1`
if (files.length > 1) {
// throw `"It's not clear which file to import"`
throw new Error('It\'s not clear which file to import');
}
// otherwise, if `base` does not end with `.css`
if (!ends_with_css_extension(base)) {
// throw `"File to import not found or unreadable"`
throw new Error('File to import not found or unreadable');
}
});
}
/* Additional tooling
/* ========================================================================== */
function test_file(file, opts) {
opts.cache[file] = opts.cache[file] || new Promise(function (resolvePromise) {
if (opts.readFile) {
(0, _fs.readFile)(file, 'utf8', function (error, contents) {
if (error) {
resolvePromise(false);
} else {
resolvePromise({
file: file,
contents: contents
});
}
});
} else {
(0, _fs.stat)(file, function (error, stats) {
if (error || !stats.isFile()) {
resolvePromise(false);
} else {
resolvePromise({
file: file
});
}
});
}
});
return opts.cache[file];
}
function starts_with_root(id) {
return (/^\//.test(id)
);
}
function starts_with_partial(base) {
return (/^_/.test(base)
);
}
function ends_with_css_extension(base) {
return (/\.css$/i.test(base)
);
}
function ends_with_sass_extension(base) {
return (/\.s[ac]ss$/i.test(base)
);
}
module.exports = exports['default'];

View File

@@ -0,0 +1,134 @@
import { readFile, stat } from 'fs';
import { basename, dirname, join } from 'path';
/* Resolve the absolute path of a file in Sass
/* ========================================================================== */
export default function resolve(id, rawopts) {
const opts = Object.assign({
cache: {},
cwd: process.cwd(),
readFile: false
}, rawopts);
// if `id` starts with `/`
if (starts_with_root(id)) {
// `cwd` is the filesystem root
opts.cwd = '';
}
// `file` is `cwd/id`
const file = join(opts.cwd, id);
// `base` is the last segment path of `file`
const base = basename(file);
// `dir` is all but the last segment path of `file`
const dir = dirname(file);
const tests = [];
// if `base` ends with `.sass`, `.scss`, or `.css`
if (ends_with_sass_extension(base) || ends_with_css_extension(base)) {
// test whether `file` exists
tests.push(test_file(file, opts));
// if `base` does not start with `_`
if (!starts_with_partial(base)) {
// test whether `dir/_base` exists
tests.push(test_file(join(dir, `_${base}`), opts));
}
} else {
// otherwise
tests.push(
// test whether `dir/base.scss` exists
test_file(join(dir, `${base}.scss`), opts),
// test whether `dir/base.sass` exists
test_file(join(dir, `${base}.sass`), opts),
// test whether `dir/base.css` exists
test_file(join(dir, `${base}.css`), opts)
);
// if `base` does not start with `_`
if (!starts_with_partial(base)) {
tests.push(
// test whether `dir/_base.scss` exists
test_file(join(dir, `_${base}.scss`), opts),
// test whether `dir/_base.sass` exists
test_file(join(dir, `_${base}.sass`), opts),
// test whether `dir/_base.css` exists
test_file(join(dir, `_${base}.css`), opts)
);
}
}
return Promise.all(tests).then(
test => test.filter(result => result)
).then(files => {
// if the length of existing files is `1`
if (files.length === 1) {
// return the existing file
return files[0];
}
// otherwise, if the length of existing files is greater than `1`
if (files.length > 1) {
// throw `"It's not clear which file to import"`
throw new Error('It\'s not clear which file to import');
}
// otherwise, if `base` does not end with `.css`
if (!ends_with_css_extension(base)) {
// throw `"File to import not found or unreadable"`
throw new Error('File to import not found or unreadable');
}
});
}
/* Additional tooling
/* ========================================================================== */
function test_file(file, opts) {
opts.cache[file] = opts.cache[file] || new Promise(resolvePromise => {
if (opts.readFile) {
readFile(file, 'utf8', (error, contents) => {
if (error) {
resolvePromise(false);
} else {
resolvePromise({
file,
contents
});
}
});
} else {
stat(file, (error, stats) => {
if (error || !stats.isFile()) {
resolvePromise(false);
} else {
resolvePromise({
file
});
}
});
}
});
return opts.cache[file];
}
function starts_with_root(id) {
return /^\//.test(id);
}
function starts_with_partial(base) {
return /^_/.test(base);
}
function ends_with_css_extension(base) {
return /\.css$/i.test(base);
}
function ends_with_sass_extension(base) {
return /\.s[ac]ss$/i.test(base);
}

View File

@@ -0,0 +1,52 @@
{
"name": "@csstools/sass-import-resolve",
"version": "1.0.0",
"description": "An algorithm for resolving imports in Sass",
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
"license": "CC0-1.0",
"repository": "jonathantneal/sass-import-resolve",
"homepage": "https://github.com/jonathantneal/sass-import-resolve#readme",
"bugs": "https://github.com/jonathantneal/sass-import-resolve/issues",
"main": "index.js",
"module": "index.mjs",
"files": [
"index.mjs",
"index.js"
],
"scripts": {
"prepublishOnly": "npm start",
"start": "babel index.mjs --presets=env --plugins=add-module-exports --out-file index.js",
"test": "npm start && npm run test:lint && npm run test:tape",
"test:lint": "eslint index.mjs --cache --ignore-pattern .gitignore",
"test:tape": "node .tape"
},
"engines": {
"node": ">=4.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-env": "^1.6.1",
"eslint": "^4.12.1",
"eslint-config-dev": "^2.0.0"
},
"eslintConfig": {
"extends": "dev",
"rules": {
"consistent-return": 0,
"max-params": 0,
"no-param-reassign": 0
}
},
"keywords": [
"sass",
"spec",
"imports",
"resolve",
"algorithm",
"external",
"files",
"style",
"sheets"
]
}