color-map 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -3
- package/cjs/index.d.ts +37 -5
- package/cjs/index.d.ts.map +1 -0
- package/cjs/index.js +68 -20
- package/cjs/index.js.map +1 -1
- package/cjs/package.json +1 -1
- package/dist/color-map.es5.js +1 -1
- package/dist/color-map.es5.js.map +1 -1
- package/esm/createColors.d.ts +6 -2
- package/esm/createColors.d.ts.map +1 -0
- package/esm/createColors.js +25 -25
- package/esm/createColors.js.map +1 -1
- package/esm/createColorsFromMap.d.ts +6 -2
- package/esm/createColorsFromMap.d.ts.map +1 -0
- package/esm/createColorsFromMap.js +19 -19
- package/esm/createColorsFromMap.js.map +1 -1
- package/esm/index.d.ts +6 -5
- package/esm/index.js +5 -5
- package/esm/interfaces.d.ts +17 -13
- package/esm/interfaces.d.ts.map +1 -0
- package/esm/rgbHex.d.ts +6 -2
- package/esm/rgbHex.d.ts.map +1 -0
- package/esm/rgbHex.js +13 -11
- package/esm/rgbHex.js.map +1 -1
- package/esm/rgbaString.d.ts +6 -2
- package/esm/rgbaString.d.ts.map +1 -0
- package/esm/rgbaString.js +6 -2
- package/esm/rgbaString.js.map +1 -1
- package/package.json +63 -91
- package/ts/createColors.ts +24 -29
- package/ts/createColorsFromMap.ts +16 -16
- package/ts/index.ts +1 -1
- package/ts/interfaces.ts +9 -9
- package/ts/rgbHex.ts +7 -7
- package/ts/rgbaString.ts +1 -1
- package/cjs/createColors.d.ts +0 -2
- package/cjs/createColors.js +0 -40
- package/cjs/createColors.js.map +0 -1
- package/cjs/createColors.spec.d.ts +0 -1
- package/cjs/createColors.spec.js +0 -176
- package/cjs/createColors.spec.js.map +0 -1
- package/cjs/createColorsFromMap.d.ts +0 -5
- package/cjs/createColorsFromMap.js +0 -25
- package/cjs/createColorsFromMap.js.map +0 -1
- package/cjs/createColorsFromMap.spec.d.ts +0 -1
- package/cjs/createColorsFromMap.spec.js +0 -11
- package/cjs/createColorsFromMap.spec.js.map +0 -1
- package/cjs/interfaces.d.ts +0 -14
- package/cjs/interfaces.js +0 -3
- package/cjs/interfaces.js.map +0 -1
- package/cjs/rgbHex.d.ts +0 -6
- package/cjs/rgbHex.js +0 -19
- package/cjs/rgbHex.js.map +0 -1
- package/cjs/rgbHex.spec.d.ts +0 -1
- package/cjs/rgbHex.spec.js +0 -16
- package/cjs/rgbHex.spec.js.map +0 -1
- package/cjs/rgbaString.d.ts +0 -2
- package/cjs/rgbaString.js +0 -7
- package/cjs/rgbaString.js.map +0 -1
- package/cjs/rgbaString.spec.d.ts +0 -1
- package/cjs/rgbaString.spec.js +0 -10
- package/cjs/rgbaString.spec.js.map +0 -1
- package/esm/createColors.spec.d.ts +0 -1
- package/esm/createColors.spec.js +0 -171
- package/esm/createColors.spec.js.map +0 -1
- package/esm/createColorsFromMap.spec.d.ts +0 -1
- package/esm/createColorsFromMap.spec.js +0 -9
- package/esm/createColorsFromMap.spec.js.map +0 -1
- package/esm/index.js.map +0 -1
- package/esm/interfaces.js +0 -2
- package/esm/interfaces.js.map +0 -1
- package/esm/rgbHex.spec.d.ts +0 -1
- package/esm/rgbHex.spec.js +0 -14
- package/esm/rgbHex.spec.js.map +0 -1
- package/esm/rgbaString.spec.d.ts +0 -1
- package/esm/rgbaString.spec.js +0 -8
- package/esm/rgbaString.spec.js.map +0 -1
package/README.md
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
[![Semantic Release][semantic-release-image]][semantic-release-url]
|
|
10
10
|
|
|
11
11
|
[![Visual Studio Code][vscode-image]][vscode-url]
|
|
12
|
-
[![Wallaby.js][wallaby-image]][wallaby-url]
|
|
13
12
|
|
|
14
13
|
Color map generator with no dependency.
|
|
15
14
|
|
|
@@ -84,5 +83,3 @@ git push
|
|
|
84
83
|
[semantic-release-url]: https://github.com/semantic-release/semantic-release
|
|
85
84
|
[vscode-image]: https://img.shields.io/badge/vscode-ready-green.svg
|
|
86
85
|
[vscode-url]: https://code.visualstudio.com/
|
|
87
|
-
[wallaby-image]: https://img.shields.io/badge/wallaby.js-configured-green.svg
|
|
88
|
-
[wallaby-url]: https://wallabyjs.com
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
//#region ts/interfaces.d.ts
|
|
2
|
+
type RGB = [number, number, number];
|
|
3
|
+
type RGBA = [number, number, number, number];
|
|
4
|
+
type Alpha = [number, number];
|
|
5
|
+
type ColorMap = {
|
|
6
|
+
/**
|
|
7
|
+
* Defines how fast or slow the `rgb` values will change from one segment to the next.
|
|
8
|
+
* i.e. the steepness of the gradient between two segments.
|
|
9
|
+
*/
|
|
10
|
+
index: number;
|
|
11
|
+
/**
|
|
12
|
+
* RGB or RGBA. if RGBA, this alpha will be used instead of the alpha specified in the call.
|
|
13
|
+
*/
|
|
14
|
+
rgb: RGB | RGBA;
|
|
15
|
+
}[];
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region ts/createColors.d.ts
|
|
18
|
+
declare function createColors(from: RGB | RGBA, to: RGB | RGBA, shades: number, alpha?: Alpha): RGBA[];
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region ts/createColorsFromMap.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* Create colors with specified color map.
|
|
23
|
+
*/
|
|
24
|
+
declare function createColorsFromMap(colormap: ColorMap, shades: number, alpha?: Alpha): RGBA[];
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region ts/rgbaString.d.ts
|
|
27
|
+
declare function rgbaString(rgba: RGBA): string;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region ts/rgbHex.d.ts
|
|
30
|
+
/**
|
|
31
|
+
* Convert `RGB` to `#rgb`
|
|
32
|
+
* JavaScript note: no check for array length, use it properly.
|
|
33
|
+
*/
|
|
34
|
+
declare function rgbHex(rgb: RGB | RGBA): string;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { type Alpha, type ColorMap, type RGB, type RGBA, createColors, createColorsFromMap, rgbHex, rgbaString };
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../ts/interfaces.ts","../ts/createColors.ts","../ts/createColorsFromMap.ts","../ts/rgbaString.ts","../ts/rgbHex.ts"],"mappings":";KAAY;KACA;KACA;KAEA;;;;;EAKX;;;;EAIA,KAAK,MAAM;;;;iBCXI,aACf,MAAM,MAAM,MACZ,IAAI,MAAM,MACV,gBACA,QAAO,QAIL;;;;;;iBCJa,oBAAoB,UAAU,UAAU,gBAAgB,QAAQ,QAAQ;;;iBCJxE,WAAW,MAAM;;;;;;;iBCIjB,OAAO,KAAK,MAAM"}
|
package/cjs/index.js
CHANGED
|
@@ -1,21 +1,69 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region ts/createColors.ts
|
|
3
|
+
function createColors(from, to, shades, alpha = [from.length === 4 ? from[3] : to.length === 4 ? to[3] : 1, to.length === 4 ? to[3] : from.length === 4 ? from[3] : 1]) {
|
|
4
|
+
const start = [...from];
|
|
5
|
+
const diff = [
|
|
6
|
+
to[0] - from[0],
|
|
7
|
+
to[1] - from[1],
|
|
8
|
+
to[2] - from[2],
|
|
9
|
+
alpha[1] - alpha[0]
|
|
10
|
+
];
|
|
11
|
+
if (start.length === 3) start.push(alpha[0]);
|
|
12
|
+
const inc = 1 / Math.max(shades - 1, 1);
|
|
13
|
+
const rgba = [];
|
|
14
|
+
for (let i = 0; i < shades; i++) {
|
|
15
|
+
const color = [
|
|
16
|
+
Math.round(start[0] + i * diff[0] * inc),
|
|
17
|
+
Math.round(start[1] + i * diff[1] * inc),
|
|
18
|
+
Math.round(start[2] + i * diff[2] * inc),
|
|
19
|
+
start[3] + i * diff[3] * inc
|
|
20
|
+
];
|
|
21
|
+
rgba.push(color);
|
|
22
|
+
}
|
|
23
|
+
return rgba;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region ts/createColorsFromMap.ts
|
|
27
|
+
/**
|
|
28
|
+
* Create colors with specified color map.
|
|
29
|
+
*/
|
|
30
|
+
function createColorsFromMap(colormap, shades, alpha) {
|
|
31
|
+
if (shades < colormap.length) throw new Error(`Requires at least ${colormap.length} shades.`);
|
|
32
|
+
const result = [];
|
|
33
|
+
const steps = [];
|
|
34
|
+
for (let i = 0; i < colormap.length; i++) steps.push(Math.round(colormap[i].index * shades));
|
|
35
|
+
for (let i = 0; i < colormap.length - 1; i++) {
|
|
36
|
+
const n = steps[i + 1] - steps[i];
|
|
37
|
+
const from = colormap[i].rgb;
|
|
38
|
+
const to = colormap[i + 1].rgb;
|
|
39
|
+
result.push(...createColors(from, to, n, alpha));
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region ts/rgbaString.ts
|
|
45
|
+
function rgbaString(rgba) {
|
|
46
|
+
return "rgba(" + rgba.join(",") + ")";
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region ts/rgbHex.ts
|
|
50
|
+
/**
|
|
51
|
+
* Convert `RGB` to `#rgb`
|
|
52
|
+
* JavaScript note: no check for array length, use it properly.
|
|
53
|
+
*/
|
|
54
|
+
function rgbHex(rgb) {
|
|
55
|
+
let hex = "#";
|
|
56
|
+
for (let i = 0; i < 3; i++) hex += d2h(rgb[i]);
|
|
57
|
+
return hex;
|
|
58
|
+
}
|
|
59
|
+
function d2h(d) {
|
|
60
|
+
const s = (+d).toString(16);
|
|
61
|
+
return s.length < 2 ? "0" + s : s;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
exports.createColors = createColors;
|
|
65
|
+
exports.createColorsFromMap = createColorsFromMap;
|
|
66
|
+
exports.rgbHex = rgbHex;
|
|
67
|
+
exports.rgbaString = rgbaString;
|
|
68
|
+
|
|
21
69
|
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../ts/createColors.ts","../ts/createColorsFromMap.ts","../ts/rgbaString.ts","../ts/rgbHex.ts"],"sourcesContent":["import type { Alpha, RGB, RGBA } from './interfaces.js'\n\nexport function createColors(\n\tfrom: RGB | RGBA,\n\tto: RGB | RGBA,\n\tshades: number,\n\talpha: Alpha = [\n\t\tfrom.length === 4 ? from[3] : to.length === 4 ? to[3] : 1,\n\t\tto.length === 4 ? to[3] : from.length === 4 ? from[3] : 1\n\t]\n): RGBA[] {\n\tconst start = [...from]\n\tconst diff = [to[0] - from[0], to[1] - from[1], to[2] - from[2], alpha[1] - alpha[0]]\n\n\tif (start.length === 3) start.push(alpha[0])\n\n\tconst inc = 1 / Math.max(shades - 1, 1)\n\n\tconst rgba: any[] = []\n\tfor (let i = 0; i < shades; i++) {\n\t\tconst color = [\n\t\t\tMath.round(start[0] + i * diff[0] * inc),\n\t\t\tMath.round(start[1] + i * diff[1] * inc),\n\t\t\tMath.round(start[2] + i * diff[2] * inc),\n\t\t\tstart[3] + i * diff[3] * inc\n\t\t]\n\t\trgba.push(color)\n\t}\n\treturn rgba\n}\n","import { createColors } from './createColors.js'\nimport type { Alpha, ColorMap, RGBA } from './interfaces.js'\n\n/**\n * Create colors with specified color map.\n */\nexport function createColorsFromMap(colormap: ColorMap, shades: number, alpha?: Alpha): RGBA[] {\n\tif (shades < colormap.length) {\n\t\tthrow new Error(`Requires at least ${colormap.length} shades.`)\n\t}\n\n\tconst result: RGBA[] = []\n\tconst steps: number[] = []\n\tfor (let i = 0; i < colormap.length; i++) {\n\t\tsteps.push(Math.round(colormap[i].index * shades))\n\t}\n\n\tfor (let i = 0; i < colormap.length - 1; i++) {\n\t\tconst n = steps[i + 1] - steps[i]\n\t\tconst from = colormap[i].rgb\n\t\tconst to = colormap[i + 1].rgb\n\t\tresult.push(...createColors(from, to, n, alpha))\n\t}\n\n\treturn result\n}\n","import type { RGBA } from './interfaces.js'\n\nexport function rgbaString(rgba: RGBA) {\n\treturn 'rgba(' + rgba.join(',') + ')'\n}\n","import type { RGB, RGBA } from './interfaces.js'\n\n/**\n * Convert `RGB` to `#rgb`\n * JavaScript note: no check for array length, use it properly.\n */\nexport function rgbHex(rgb: RGB | RGBA) {\n\tlet hex = '#'\n\tfor (let i = 0; i < 3; i++) {\n\t\thex += d2h(rgb[i])\n\t}\n\treturn hex\n}\n\nfunction d2h(d: number) {\n\tconst s = (+d).toString(16)\n\treturn s.length < 2 ? '0' + s : s\n}\n"],"mappings":";;AAEA,SAAgB,aACf,MACA,IACA,QACA,QAAe,CACd,KAAK,WAAW,IAAI,KAAK,KAAK,GAAG,WAAW,IAAI,GAAG,KAAK,GACxD,GAAG,WAAW,IAAI,GAAG,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,CACzD,GACS;CACT,MAAM,QAAQ,CAAC,GAAG,IAAI;CACtB,MAAM,OAAO;EAAC,GAAG,KAAK,KAAK;EAAI,GAAG,KAAK,KAAK;EAAI,GAAG,KAAK,KAAK;EAAI,MAAM,KAAK,MAAM;CAAE;CAEpF,IAAI,MAAM,WAAW,GAAG,MAAM,KAAK,MAAM,EAAE;CAE3C,MAAM,MAAM,IAAI,KAAK,IAAI,SAAS,GAAG,CAAC;CAEtC,MAAM,OAAc,CAAC;CACrB,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK;EAChC,MAAM,QAAQ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+
{ "type": "commonjs" }
|
package/dist/color-map.es5.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var ColorMap
|
|
1
|
+
var ColorMap=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e,t,n,r=[e.length===4?e[3]:t.length===4?t[3]:1,t.length===4?t[3]:e.length===4?e[3]:1]){let i=[...e],a=[t[0]-e[0],t[1]-e[1],t[2]-e[2],r[1]-r[0]];i.length===3&&i.push(r[0]);let o=1/Math.max(n-1,1),s=[];for(let e=0;e<n;e++){let t=[Math.round(i[0]+e*a[0]*o),Math.round(i[1]+e*a[1]*o),Math.round(i[2]+e*a[2]*o),i[3]+e*a[3]*o];s.push(t)}return s}function n(e,n,r){if(n<e.length)throw Error(`Requires at least ${e.length} shades.`);let i=[],a=[];for(let t=0;t<e.length;t++)a.push(Math.round(e[t].index*n));for(let n=0;n<e.length-1;n++){let o=a[n+1]-a[n],s=e[n].rgb,c=e[n+1].rgb;i.push(...t(s,c,o,r))}return i}function r(e){return`rgba(`+e.join(`,`)+`)`}function i(e){let t=`#`;for(let n=0;n<3;n++)t+=a(e[n]);return t}function a(e){let t=(+e).toString(16);return t.length<2?`0`+t:t}return e.createColors=t,e.createColorsFromMap=n,e.rgbHex=i,e.rgbaString=r,e})({});
|
|
2
2
|
//# sourceMappingURL=color-map.es5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-map.es5.js","
|
|
1
|
+
{"version":3,"file":"color-map.es5.js","names":[],"sources":["../ts/createColors.ts","../ts/createColorsFromMap.ts","../ts/rgbaString.ts","../ts/rgbHex.ts"],"sourcesContent":["import type { Alpha, RGB, RGBA } from './interfaces.js'\n\nexport function createColors(\n\tfrom: RGB | RGBA,\n\tto: RGB | RGBA,\n\tshades: number,\n\talpha: Alpha = [\n\t\tfrom.length === 4 ? from[3] : to.length === 4 ? to[3] : 1,\n\t\tto.length === 4 ? to[3] : from.length === 4 ? from[3] : 1\n\t]\n): RGBA[] {\n\tconst start = [...from]\n\tconst diff = [to[0] - from[0], to[1] - from[1], to[2] - from[2], alpha[1] - alpha[0]]\n\n\tif (start.length === 3) start.push(alpha[0])\n\n\tconst inc = 1 / Math.max(shades - 1, 1)\n\n\tconst rgba: any[] = []\n\tfor (let i = 0; i < shades; i++) {\n\t\tconst color = [\n\t\t\tMath.round(start[0] + i * diff[0] * inc),\n\t\t\tMath.round(start[1] + i * diff[1] * inc),\n\t\t\tMath.round(start[2] + i * diff[2] * inc),\n\t\t\tstart[3] + i * diff[3] * inc\n\t\t]\n\t\trgba.push(color)\n\t}\n\treturn rgba\n}\n","import { createColors } from './createColors.js'\nimport type { Alpha, ColorMap, RGBA } from './interfaces.js'\n\n/**\n * Create colors with specified color map.\n */\nexport function createColorsFromMap(colormap: ColorMap, shades: number, alpha?: Alpha): RGBA[] {\n\tif (shades < colormap.length) {\n\t\tthrow new Error(`Requires at least ${colormap.length} shades.`)\n\t}\n\n\tconst result: RGBA[] = []\n\tconst steps: number[] = []\n\tfor (let i = 0; i < colormap.length; i++) {\n\t\tsteps.push(Math.round(colormap[i].index * shades))\n\t}\n\n\tfor (let i = 0; i < colormap.length - 1; i++) {\n\t\tconst n = steps[i + 1] - steps[i]\n\t\tconst from = colormap[i].rgb\n\t\tconst to = colormap[i + 1].rgb\n\t\tresult.push(...createColors(from, to, n, alpha))\n\t}\n\n\treturn result\n}\n","import type { RGBA } from './interfaces.js'\n\nexport function rgbaString(rgba: RGBA) {\n\treturn 'rgba(' + rgba.join(',') + ')'\n}\n","import type { RGB, RGBA } from './interfaces.js'\n\n/**\n * Convert `RGB` to `#rgb`\n * JavaScript note: no check for array length, use it properly.\n */\nexport function rgbHex(rgb: RGB | RGBA) {\n\tlet hex = '#'\n\tfor (let i = 0; i < 3; i++) {\n\t\thex += d2h(rgb[i])\n\t}\n\treturn hex\n}\n\nfunction d2h(d: number) {\n\tconst s = (+d).toString(16)\n\treturn s.length < 2 ? '0' + s : s\n}\n"],"mappings":"uF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AAK,GAAG,EAAa,EAAM,EAAI,EAAG,CAAK,CAAC,CAChD,CAEA,OAAO,CACR,CCvBA,SAAgB,EAAW,EAAY,CACtC,MAAO,QAAU,EAAK,KAAK,GAAG,EAAI,GACnC,CCEA,SAAgB,EAAO,EAAiB,CACvC,IAAI,EAAM,IACV,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,IACtB,GAAO,EAAI,EAAI,EAAE,EAElB,OAAO,CACR,CAEA,SAAS,EAAI,EAAW,CACvB,IAAM,GAAK,CAAC,EAAA,CAAG,SAAS,EAAE,EAC1B,OAAO,EAAE,OAAS,EAAI,IAAM,EAAI,CACjC"}
|
package/esm/createColors.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { Alpha, RGB, RGBA } from "./interfaces.js";
|
|
2
|
+
//#region ts/createColors.d.ts
|
|
3
|
+
declare function createColors(from: RGB | RGBA, to: RGB | RGBA, shades: number, alpha?: Alpha): RGBA[];
|
|
4
|
+
//#endregion
|
|
5
|
+
export { createColors };
|
|
6
|
+
//# sourceMappingURL=createColors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createColors.d.ts","names":[],"sources":["../ts/createColors.ts"],"mappings":";;iBAEgB,aACf,MAAM,MAAM,MACZ,IAAI,MAAM,MACV,gBACA,QAAO,QAIL"}
|
package/esm/createColors.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
rgba.push(color);
|
|
24
|
-
}
|
|
25
|
-
return rgba;
|
|
1
|
+
//#region ts/createColors.ts
|
|
2
|
+
function createColors(from, to, shades, alpha = [from.length === 4 ? from[3] : to.length === 4 ? to[3] : 1, to.length === 4 ? to[3] : from.length === 4 ? from[3] : 1]) {
|
|
3
|
+
const start = [...from];
|
|
4
|
+
const diff = [
|
|
5
|
+
to[0] - from[0],
|
|
6
|
+
to[1] - from[1],
|
|
7
|
+
to[2] - from[2],
|
|
8
|
+
alpha[1] - alpha[0]
|
|
9
|
+
];
|
|
10
|
+
if (start.length === 3) start.push(alpha[0]);
|
|
11
|
+
const inc = 1 / Math.max(shades - 1, 1);
|
|
12
|
+
const rgba = [];
|
|
13
|
+
for (let i = 0; i < shades; i++) {
|
|
14
|
+
const color = [
|
|
15
|
+
Math.round(start[0] + i * diff[0] * inc),
|
|
16
|
+
Math.round(start[1] + i * diff[1] * inc),
|
|
17
|
+
Math.round(start[2] + i * diff[2] * inc),
|
|
18
|
+
start[3] + i * diff[3] * inc
|
|
19
|
+
];
|
|
20
|
+
rgba.push(color);
|
|
21
|
+
}
|
|
22
|
+
return rgba;
|
|
26
23
|
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { createColors };
|
|
26
|
+
|
|
27
27
|
//# sourceMappingURL=createColors.js.map
|
package/esm/createColors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createColors.js","
|
|
1
|
+
{"version":3,"file":"createColors.js","names":[],"sources":["../ts/createColors.ts"],"sourcesContent":["import type { Alpha, RGB, RGBA } from './interfaces.js'\n\nexport function createColors(\n\tfrom: RGB | RGBA,\n\tto: RGB | RGBA,\n\tshades: number,\n\talpha: Alpha = [\n\t\tfrom.length === 4 ? from[3] : to.length === 4 ? to[3] : 1,\n\t\tto.length === 4 ? to[3] : from.length === 4 ? from[3] : 1\n\t]\n): RGBA[] {\n\tconst start = [...from]\n\tconst diff = [to[0] - from[0], to[1] - from[1], to[2] - from[2], alpha[1] - alpha[0]]\n\n\tif (start.length === 3) start.push(alpha[0])\n\n\tconst inc = 1 / Math.max(shades - 1, 1)\n\n\tconst rgba: any[] = []\n\tfor (let i = 0; i < shades; i++) {\n\t\tconst color = [\n\t\t\tMath.round(start[0] + i * diff[0] * inc),\n\t\t\tMath.round(start[1] + i * diff[1] * inc),\n\t\t\tMath.round(start[2] + i * diff[2] * inc),\n\t\t\tstart[3] + i * diff[3] * inc\n\t\t]\n\t\trgba.push(color)\n\t}\n\treturn rgba\n}\n"],"mappings":";AAEA,SAAgB,aACf,MACA,IACA,QACA,QAAe,CACd,KAAK,WAAW,IAAI,KAAK,KAAK,GAAG,WAAW,IAAI,GAAG,KAAK,GACxD,GAAG,WAAW,IAAI,GAAG,KAAK,KAAK,WAAW,IAAI,KAAK,KAAK,CACzD,GACS;CACT,MAAM,QAAQ,CAAC,GAAG,IAAI;CACtB,MAAM,OAAO;EAAC,GAAG,KAAK,KAAK;EAAI,GAAG,KAAK,KAAK;EAAI,GAAG,KAAK,KAAK;EAAI,MAAM,KAAK,MAAM;CAAE;CAEpF,IAAI,MAAM,WAAW,GAAG,MAAM,KAAK,MAAM,EAAE;CAE3C,MAAM,MAAM,IAAI,KAAK,IAAI,SAAS,GAAG,CAAC;CAEtC,MAAM,OAAc,CAAC;CACrB,KAAK,IAAI,IAAI,GAAG,IAAI,QAAQ,KAAK;EAChC,MAAM,QAAQ;GACb,KAAK,MAAM,MAAM,KAAK,IAAI,KAAK,KAAK,GAAG;GACvC,KAAK,MAAM,MAAM,KAAK,IAAI,KAAK,KAAK,GAAG;GACvC,KAAK,MAAM,MAAM,KAAK,IAAI,KAAK,KAAK,GAAG;GACvC,MAAM,KAAK,IAAI,KAAK,KAAK;EAC1B;EACA,KAAK,KAAK,KAAK;CAChB;CACA,OAAO;AACR"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Alpha, ColorMap, RGBA } from "./interfaces.js";
|
|
2
|
+
//#region ts/createColorsFromMap.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Create colors with specified color map.
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function createColorsFromMap(colormap: ColorMap, shades: number, alpha?: Alpha): RGBA[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { createColorsFromMap };
|
|
9
|
+
//# sourceMappingURL=createColorsFromMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createColorsFromMap.d.ts","names":[],"sources":["../ts/createColorsFromMap.ts"],"mappings":";;;;;iBAMgB,oBAAoB,UAAU,UAAU,gBAAgB,QAAQ,QAAQ"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { createColors } from
|
|
1
|
+
import { createColors } from "./createColors.js";
|
|
2
|
+
//#region ts/createColorsFromMap.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const to = colormap[i + 1].rgb;
|
|
18
|
-
result.push(...createColors(from, to, n, alpha));
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
4
|
+
* Create colors with specified color map.
|
|
5
|
+
*/
|
|
6
|
+
function createColorsFromMap(colormap, shades, alpha) {
|
|
7
|
+
if (shades < colormap.length) throw new Error(`Requires at least ${colormap.length} shades.`);
|
|
8
|
+
const result = [];
|
|
9
|
+
const steps = [];
|
|
10
|
+
for (let i = 0; i < colormap.length; i++) steps.push(Math.round(colormap[i].index * shades));
|
|
11
|
+
for (let i = 0; i < colormap.length - 1; i++) {
|
|
12
|
+
const n = steps[i + 1] - steps[i];
|
|
13
|
+
const from = colormap[i].rgb;
|
|
14
|
+
const to = colormap[i + 1].rgb;
|
|
15
|
+
result.push(...createColors(from, to, n, alpha));
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
21
18
|
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { createColorsFromMap };
|
|
21
|
+
|
|
22
22
|
//# sourceMappingURL=createColorsFromMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createColorsFromMap.js","
|
|
1
|
+
{"version":3,"file":"createColorsFromMap.js","names":[],"sources":["../ts/createColorsFromMap.ts"],"sourcesContent":["import { createColors } from './createColors.js'\nimport type { Alpha, ColorMap, RGBA } from './interfaces.js'\n\n/**\n * Create colors with specified color map.\n */\nexport function createColorsFromMap(colormap: ColorMap, shades: number, alpha?: Alpha): RGBA[] {\n\tif (shades < colormap.length) {\n\t\tthrow new Error(`Requires at least ${colormap.length} shades.`)\n\t}\n\n\tconst result: RGBA[] = []\n\tconst steps: number[] = []\n\tfor (let i = 0; i < colormap.length; i++) {\n\t\tsteps.push(Math.round(colormap[i].index * shades))\n\t}\n\n\tfor (let i = 0; i < colormap.length - 1; i++) {\n\t\tconst n = steps[i + 1] - steps[i]\n\t\tconst from = colormap[i].rgb\n\t\tconst to = colormap[i + 1].rgb\n\t\tresult.push(...createColors(from, to, n, alpha))\n\t}\n\n\treturn result\n}\n"],"mappings":";;;;;AAMA,SAAgB,oBAAoB,UAAoB,QAAgB,OAAuB;CAC9F,IAAI,SAAS,SAAS,QACrB,MAAM,IAAI,MAAM,qBAAqB,SAAS,OAAO,SAAS;CAG/D,MAAM,SAAiB,CAAC;CACxB,MAAM,QAAkB,CAAC;CACzB,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACpC,MAAM,KAAK,KAAK,MAAM,SAAS,EAAE,CAAC,QAAQ,MAAM,CAAC;CAGlD,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,SAAS,GAAG,KAAK;EAC7C,MAAM,IAAI,MAAM,IAAI,KAAK,MAAM;EAC/B,MAAM,OAAO,SAAS,EAAE,CAAC;EACzB,MAAM,KAAK,SAAS,IAAI,EAAE,CAAC;EAC3B,OAAO,KAAK,GAAG,aAAa,MAAM,IAAI,GAAG,KAAK,CAAC;CAChD;CAEA,OAAO;AACR"}
|
package/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Alpha, ColorMap, RGB, RGBA } from "./interfaces.js";
|
|
2
|
+
import { createColors } from "./createColors.js";
|
|
3
|
+
import { createColorsFromMap } from "./createColorsFromMap.js";
|
|
4
|
+
import { rgbaString } from "./rgbaString.js";
|
|
5
|
+
import { rgbHex } from "./rgbHex.js";
|
|
6
|
+
export { type Alpha, type ColorMap, type RGB, type RGBA, createColors, createColorsFromMap, rgbHex, rgbaString };
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createColors } from "./createColors.js";
|
|
2
|
+
import { createColorsFromMap } from "./createColorsFromMap.js";
|
|
3
|
+
import { rgbaString } from "./rgbaString.js";
|
|
4
|
+
import { rgbHex } from "./rgbHex.js";
|
|
5
|
+
export { createColors, createColorsFromMap, rgbHex, rgbaString };
|
package/esm/interfaces.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
//#region ts/interfaces.d.ts
|
|
2
|
+
type RGB = [number, number, number];
|
|
3
|
+
type RGBA = [number, number, number, number];
|
|
4
|
+
type Alpha = [number, number];
|
|
5
|
+
type ColorMap = {
|
|
6
|
+
/**
|
|
7
|
+
* Defines how fast or slow the `rgb` values will change from one segment to the next.
|
|
8
|
+
* i.e. the steepness of the gradient between two segments.
|
|
9
|
+
*/
|
|
10
|
+
index: number;
|
|
11
|
+
/**
|
|
12
|
+
* RGB or RGBA. if RGBA, this alpha will be used instead of the alpha specified in the call.
|
|
13
|
+
*/
|
|
14
|
+
rgb: RGB | RGBA;
|
|
14
15
|
}[];
|
|
16
|
+
//#endregion
|
|
17
|
+
export { Alpha, ColorMap, RGB, RGBA };
|
|
18
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","names":[],"sources":["../ts/interfaces.ts"],"mappings":";KAAY;KACA;KACA;KAEA;;;;;EAKX;;;;EAIA,KAAK,MAAM"}
|
package/esm/rgbHex.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RGB, RGBA } from "./interfaces.js";
|
|
2
|
+
//#region ts/rgbHex.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Convert `RGB` to `#rgb`
|
|
4
5
|
* JavaScript note: no check for array length, use it properly.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
declare function rgbHex(rgb: RGB | RGBA): string;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { rgbHex };
|
|
10
|
+
//# sourceMappingURL=rgbHex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgbHex.d.ts","names":[],"sources":["../ts/rgbHex.ts"],"mappings":";;;;;;iBAMgB,OAAO,KAAK,MAAM"}
|
package/esm/rgbHex.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
//#region ts/rgbHex.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return hex;
|
|
3
|
+
* Convert `RGB` to `#rgb`
|
|
4
|
+
* JavaScript note: no check for array length, use it properly.
|
|
5
|
+
*/
|
|
6
|
+
function rgbHex(rgb) {
|
|
7
|
+
let hex = "#";
|
|
8
|
+
for (let i = 0; i < 3; i++) hex += d2h(rgb[i]);
|
|
9
|
+
return hex;
|
|
11
10
|
}
|
|
12
11
|
function d2h(d) {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const s = (+d).toString(16);
|
|
13
|
+
return s.length < 2 ? "0" + s : s;
|
|
15
14
|
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { rgbHex };
|
|
17
|
+
|
|
16
18
|
//# sourceMappingURL=rgbHex.js.map
|
package/esm/rgbHex.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rgbHex.js","
|
|
1
|
+
{"version":3,"file":"rgbHex.js","names":[],"sources":["../ts/rgbHex.ts"],"sourcesContent":["import type { RGB, RGBA } from './interfaces.js'\n\n/**\n * Convert `RGB` to `#rgb`\n * JavaScript note: no check for array length, use it properly.\n */\nexport function rgbHex(rgb: RGB | RGBA) {\n\tlet hex = '#'\n\tfor (let i = 0; i < 3; i++) {\n\t\thex += d2h(rgb[i])\n\t}\n\treturn hex\n}\n\nfunction d2h(d: number) {\n\tconst s = (+d).toString(16)\n\treturn s.length < 2 ? '0' + s : s\n}\n"],"mappings":";;;;;AAMA,SAAgB,OAAO,KAAiB;CACvC,IAAI,MAAM;CACV,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KACtB,OAAO,IAAI,IAAI,EAAE;CAElB,OAAO;AACR;AAEA,SAAS,IAAI,GAAW;CACvB,MAAM,KAAK,CAAC,EAAA,CAAG,SAAS,EAAE;CAC1B,OAAO,EAAE,SAAS,IAAI,MAAM,IAAI;AACjC"}
|
package/esm/rgbaString.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { RGBA } from "./interfaces.js";
|
|
2
|
+
//#region ts/rgbaString.d.ts
|
|
3
|
+
declare function rgbaString(rgba: RGBA): string;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { rgbaString };
|
|
6
|
+
//# sourceMappingURL=rgbaString.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rgbaString.d.ts","names":[],"sources":["../ts/rgbaString.ts"],"mappings":";;iBAEgB,WAAW,MAAM"}
|
package/esm/rgbaString.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region ts/rgbaString.ts
|
|
2
|
+
function rgbaString(rgba) {
|
|
3
|
+
return "rgba(" + rgba.join(",") + ")";
|
|
3
4
|
}
|
|
5
|
+
//#endregion
|
|
6
|
+
export { rgbaString };
|
|
7
|
+
|
|
4
8
|
//# sourceMappingURL=rgbaString.js.map
|
package/esm/rgbaString.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rgbaString.js","
|
|
1
|
+
{"version":3,"file":"rgbaString.js","names":[],"sources":["../ts/rgbaString.ts"],"sourcesContent":["import type { RGBA } from './interfaces.js'\n\nexport function rgbaString(rgba: RGBA) {\n\treturn 'rgba(' + rgba.join(',') + ')'\n}\n"],"mappings":";AAEA,SAAgB,WAAW,MAAY;CACtC,OAAO,UAAU,KAAK,KAAK,GAAG,IAAI;AACnC"}
|