color-map 1.1.3 → 1.1.4

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.
@@ -0,0 +1,2 @@
1
+ import { RGB, RGBA, Alpha } from './interfaces';
2
+ export declare function createColors(from: RGB | RGBA, to: RGB | RGBA, shades: number, alpha?: Alpha): RGBA[];
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createColors = void 0;
13
+ function createColors(from, to, shades, alpha) {
14
+ if (alpha === void 0) { alpha = [
15
+ from.length === 4 ? from[3] : to.length === 4 ? to[3] : 1,
16
+ to.length === 4 ? to[3] : from.length === 4 ? from[3] : 1
17
+ ]; }
18
+ var start = __spreadArray([], from, true);
19
+ var diff = [
20
+ to[0] - from[0],
21
+ to[1] - from[1],
22
+ to[2] - from[2],
23
+ alpha[1] - alpha[0]
24
+ ];
25
+ if (start.length === 3)
26
+ start.push(alpha[0]);
27
+ var inc = 1 / Math.max(shades - 1, 1);
28
+ var rgba = [];
29
+ for (var i = 0; i < shades; i++) {
30
+ var color = [
31
+ Math.round(start[0] + i * diff[0] * inc),
32
+ Math.round(start[1] + i * diff[1] * inc),
33
+ Math.round(start[2] + i * diff[2] * inc),
34
+ start[3] + i * diff[3] * inc
35
+ ];
36
+ rgba.push(color);
37
+ }
38
+ return rgba;
39
+ }
40
+ exports.createColors = createColors;
41
+ //# sourceMappingURL=createColors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createColors.js","sourceRoot":"","sources":["../ts/createColors.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,SAAgB,YAAY,CAC1B,IAAgB,EAChB,EAAc,EACd,MAAc,EACd,KAGC;IAHD,sBAAA,EAAA;QACE,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACzD,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC1D;IACD,IAAM,KAAK,qBAAO,IAAI,OAAC,CAAA;IACvB,IAAM,IAAI,GAAG;QACX,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACf,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACf,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACf,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;KACpB,CAAA;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QACpB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAEtB,IAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IAEvC,IAAM,IAAI,GAAU,EAAE,CAAA;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;QAC/B,IAAM,KAAK,GAAG;YACZ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACxC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACxC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACxC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG;SAC7B,CAAA;QACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;KACjB;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAhCD,oCAgCC"}
@@ -0,0 +1,5 @@
1
+ import { ColorMap, Alpha, RGBA } from './interfaces';
2
+ /**
3
+ * Create colors with specified color map.
4
+ */
5
+ export declare function createColorsFromMap(colormap: ColorMap, shades: number, alpha?: Alpha): RGBA[];
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createColorsFromMap = void 0;
4
+ var createColors_1 = require("./createColors");
5
+ /**
6
+ * Create colors with specified color map.
7
+ */
8
+ function createColorsFromMap(colormap, shades, alpha) {
9
+ if (shades < colormap.length) {
10
+ throw new Error("Requires at least ".concat(colormap.length, " shades."));
11
+ }
12
+ var result = [];
13
+ var steps = [];
14
+ for (var i = 0; i < colormap.length; i++) {
15
+ steps.push(Math.round(colormap[i].index * shades));
16
+ }
17
+ for (var i = 0; i < colormap.length - 1; i++) {
18
+ var n = steps[i + 1] - steps[i];
19
+ var from = colormap[i].rgb;
20
+ var to = colormap[i + 1].rgb;
21
+ result.push.apply(result, (0, createColors_1.createColors)(from, to, n, alpha));
22
+ }
23
+ return result;
24
+ }
25
+ exports.createColorsFromMap = createColorsFromMap;
26
+ //# sourceMappingURL=createColorsFromMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createColorsFromMap.js","sourceRoot":"","sources":["../ts/createColorsFromMap.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAG7C;;GAEG;AACH,SAAgB,mBAAmB,CAAC,QAAkB,EAAE,MAAc,EAAE,KAAa;IACnF,IAAI,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,4BAAqB,QAAQ,CAAC,MAAM,aAAU,CAAC,CAAA;KAChE;IAED,IAAM,MAAM,GAAW,EAAE,CAAA;IACzB,IAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACxC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,CAAA;KACnD;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QAC5C,IAAM,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACjC,IAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QAC7B,IAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;QAC/B,MAAM,CAAC,IAAI,OAAX,MAAM,EAAS,IAAA,2BAAY,EAAC,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,EAAC;KACjD;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAnBD,kDAmBC"}
package/cjs/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './createColors';
2
+ export * from './createColorsFromMap';
3
+ export * from './interfaces';
4
+ export * from './rgbHex';
5
+ export * from './rgbaString';
package/cjs/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./createColors"), exports);
14
+ __exportStar(require("./createColorsFromMap"), exports);
15
+ __exportStar(require("./interfaces"), exports);
16
+ __exportStar(require("./rgbHex"), exports);
17
+ __exportStar(require("./rgbaString"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA8B;AAC9B,wDAAqC;AACrC,+CAA4B;AAC5B,2CAAwB;AACxB,+CAA4B"}
@@ -0,0 +1,14 @@
1
+ export declare type RGB = [number, number, number];
2
+ export declare type RGBA = [number, number, number, number];
3
+ export declare type Alpha = [number, number];
4
+ export declare type ColorMap = {
5
+ /**
6
+ * Defines how fast or slow the `rgb` values will change from one segment to the next.
7
+ * i.e. the steepness of the gradient between two segments.
8
+ */
9
+ index: number;
10
+ /**
11
+ * RGB or RGBA. if RGBA, this alpha will be used instead of the alpha specified in the call.
12
+ */
13
+ rgb: RGB | RGBA;
14
+ }[];
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../ts/interfaces.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { RGB, RGBA } from './interfaces';
2
+ /**
3
+ * Convert `RGB` to `#rgb`
4
+ * JavaScript note: no check for array length, use it properly.
5
+ */
6
+ export declare function rgbHex(rgb: RGB | RGBA): string;
package/cjs/rgbHex.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rgbHex = void 0;
4
+ /**
5
+ * Convert `RGB` to `#rgb`
6
+ * JavaScript note: no check for array length, use it properly.
7
+ */
8
+ function rgbHex(rgb) {
9
+ var hex = '#';
10
+ for (var i = 0; i < 3; i++) {
11
+ hex += d2h(rgb[i]);
12
+ }
13
+ return hex;
14
+ }
15
+ exports.rgbHex = rgbHex;
16
+ function d2h(d) {
17
+ var s = (+d).toString(16);
18
+ return s.length < 2 ? '0' + s : s;
19
+ }
20
+ //# sourceMappingURL=rgbHex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rgbHex.js","sourceRoot":"","sources":["../ts/rgbHex.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,SAAgB,MAAM,CAAC,GAAe;IACpC,IAAI,GAAG,GAAG,GAAG,CAAA;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QAC1B,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;KACnB;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAND,wBAMC;AAED,SAAS,GAAG,CAAC,CAAS;IACpB,IAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAC3B,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACnC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { RGBA } from './interfaces';
2
+ export declare function rgbaString(rgba: RGBA): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rgbaString = void 0;
4
+ function rgbaString(rgba) {
5
+ return 'rgba(' + rgba.join(',') + ')';
6
+ }
7
+ exports.rgbaString = rgbaString;
8
+ //# sourceMappingURL=rgbaString.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rgbaString.js","sourceRoot":"","sources":["../ts/rgbaString.ts"],"names":[],"mappings":";;;AAEA,SAAgB,UAAU,CAAC,IAAU;IACnC,OAAO,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACxC,CAAC;AAFD,gCAEC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-map.es5.js","mappings":"gWAEA,wBACEA,EACAC,EACAC,EACAC,QAAA,IAAAA,IAAAA,EAAA,CACkB,IAAhBH,EAAKI,OAAeJ,EAAK,GAAmB,IAAdC,EAAGG,OAAeH,EAAG,GAAK,EAC1C,IAAdA,EAAGG,OAAeH,EAAG,GAAqB,IAAhBD,EAAKI,OAAeJ,EAAK,GAAK,IAE1D,IAAMK,EAAQ,EAAH,GAAOL,GAAI,GAChBM,EAAO,CACXL,EAAG,GAAKD,EAAK,GACbC,EAAG,GAAKD,EAAK,GACbC,EAAG,GAAKD,EAAK,GACbG,EAAM,GAAKA,EAAM,IAGE,IAAjBE,EAAMD,QACRC,EAAME,KAAKJ,EAAM,IAKnB,IAHA,IAAMK,EAAM,EAAIC,KAAKC,IAAIR,EAAS,EAAG,GAE/BS,EAAc,GACXC,EAAI,EAAGA,EAAIV,EAAQU,IAAK,CAC/B,IAAMC,EAAQ,CACZJ,KAAKK,MAAMT,EAAM,GAAKO,EAAIN,EAAK,GAAKE,GACpCC,KAAKK,MAAMT,EAAM,GAAKO,EAAIN,EAAK,GAAKE,GACpCC,KAAKK,MAAMT,EAAM,GAAKO,EAAIN,EAAK,GAAKE,GACpCH,EAAM,GAAKO,EAAIN,EAAK,GAAKE,GAE3BG,EAAKJ,KAAKM,GAEZ,OAAOF,I,4FCjCT,aAMA,+BAAoCI,EAAoBb,EAAgBC,GACtE,GAAID,EAASa,EAASX,OACpB,MAAM,IAAIY,MAAM,4BAAqBD,EAASX,OAAM,aAKtD,IAFA,IAAMa,EAAiB,GACjBC,EAAkB,GACfN,EAAI,EAAGA,EAAIG,EAASX,OAAQQ,IACnCM,EAAMX,KAAKE,KAAKK,MAAMC,EAASH,GAAGO,MAAQjB,IAG5C,IAASU,EAAI,EAAGA,EAAIG,EAASX,OAAS,EAAGQ,IAAK,CAC5C,IAAMQ,EAAIF,EAAMN,EAAI,GAAKM,EAAMN,GACzBZ,EAAOe,EAASH,GAAGS,IACnBpB,EAAKc,EAASH,EAAI,GAAGS,IAC3BJ,EAAOV,KAAI,MAAXU,GAAe,IAAAK,cAAatB,EAAMC,EAAImB,EAAGjB,IAG3C,OAAOc,I,8YCxBT,YACA,YACA,YACA,YACA,W,2ICEA,kBAAuBI,GAErB,IADA,IAQME,EARFC,EAAM,IACDZ,EAAI,EAAGA,EAAI,EAAGA,IACrBY,SAMID,GAAAA,IANOF,EAAIT,IAMFa,SAAS,KACfrB,OAAS,EAAI,IAAMmB,EAAIA,GALhC,OAAOC,I,+ECTT,sBAA2Bb,GACzB,MAAO,QAAUA,EAAKe,KAAK,KAAO,OCFhCC,EAA2B,GCE3BC,EDCJ,SAASC,EAAoBC,GAE5B,IAAIC,EAAeJ,EAAyBG,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaE,QAGrB,IAAIC,EAASP,EAAyBG,GAAY,CAGjDG,QAAS,IAOV,OAHAE,EAAoBL,GAAUM,KAAKF,EAAOD,QAASC,EAAQA,EAAOD,QAASJ,GAGpEK,EAAOD,QClBWJ,CAAoB,K","sources":["webpack://ColorMap/./ts/createColors.ts","webpack://ColorMap/./ts/createColorsFromMap.ts","webpack://ColorMap/./ts/index.ts","webpack://ColorMap/./ts/rgbHex.ts","webpack://ColorMap/./ts/rgbaString.ts","webpack://ColorMap/webpack/bootstrap","webpack://ColorMap/webpack/startup"],"sourcesContent":["import { RGB, RGBA, Alpha } from './interfaces'\n\nexport function createColors(\n from: RGB | RGBA,\n to: RGB | RGBA,\n shades: number,\n alpha: Alpha = [\n from.length === 4 ? from[3] : to.length === 4 ? to[3] : 1,\n to.length === 4 ? to[3] : from.length === 4 ? from[3] : 1\n ]): RGBA[] {\n const start = [...from]\n const diff = [\n to[0] - from[0],\n to[1] - from[1],\n to[2] - from[2],\n alpha[1] - alpha[0]\n ]\n\n if (start.length === 3)\n start.push(alpha[0])\n\n const inc = 1 / Math.max(shades - 1, 1)\n\n const rgba: any[] = []\n for (let i = 0; i < shades; i++) {\n const color = [\n Math.round(start[0] + i * diff[0] * inc),\n Math.round(start[1] + i * diff[1] * inc),\n Math.round(start[2] + i * diff[2] * inc),\n start[3] + i * diff[3] * inc\n ]\n rgba.push(color)\n }\n return rgba\n}\n","import { createColors } from './createColors'\nimport { ColorMap, Alpha, RGBA } from './interfaces'\n\n/**\n * Create colors with specified color map.\n */\nexport function createColorsFromMap(colormap: ColorMap, shades: number, alpha?: Alpha): RGBA[] {\n if (shades < colormap.length) {\n throw new Error(`Requires at least ${colormap.length} shades.`)\n }\n\n const result: RGBA[] = []\n const steps: number[] = []\n for (let i = 0; i < colormap.length; i++) {\n steps.push(Math.round(colormap[i].index * shades))\n }\n\n for (let i = 0; i < colormap.length - 1; i++) {\n const n = steps[i + 1] - steps[i]\n const from = colormap[i].rgb;\n const to = colormap[i + 1].rgb;\n result.push(...createColors(from, to, n, alpha))\n }\n\n return result\n}\n","export * from './createColors'\nexport * from './createColorsFromMap'\nexport * from './interfaces'\nexport * from './rgbHex'\nexport * from './rgbaString'\n","import { RGB, RGBA } from './interfaces'\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 let hex = '#'\n for (let i = 0; i < 3; i++) {\n hex += d2h(rgb[i])\n }\n return hex\n}\n\nfunction d2h(d: number) {\n const s = (+d).toString(16)\n return s.length < 2 ? '0' + s : s\n}\n","import { RGBA } from './interfaces'\n\nexport function rgbaString(rgba: RGBA) {\n return 'rgba(' + rgba.join(',') + ')';\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(403);\n"],"names":["from","to","shades","alpha","length","start","diff","push","inc","Math","max","rgba","i","color","round","colormap","Error","result","steps","index","n","rgb","createColors","s","hex","toString","join","__webpack_module_cache__","__webpack_exports__","__webpack_require__","moduleId","cachedModule","undefined","exports","module","__webpack_modules__","call"],"sourceRoot":""}
@@ -0,0 +1,2 @@
1
+ import { RGB, RGBA, Alpha } from './interfaces';
2
+ export declare function createColors(from: RGB | RGBA, to: RGB | RGBA, shades: number, alpha?: Alpha): RGBA[];
@@ -0,0 +1,27 @@
1
+ export function createColors(from, to, shades, alpha = [
2
+ from.length === 4 ? from[3] : to.length === 4 ? to[3] : 1,
3
+ to.length === 4 ? to[3] : from.length === 4 ? from[3] : 1
4
+ ]) {
5
+ const start = [...from];
6
+ const diff = [
7
+ to[0] - from[0],
8
+ to[1] - from[1],
9
+ to[2] - from[2],
10
+ alpha[1] - alpha[0]
11
+ ];
12
+ if (start.length === 3)
13
+ start.push(alpha[0]);
14
+ const inc = 1 / Math.max(shades - 1, 1);
15
+ const rgba = [];
16
+ for (let i = 0; i < shades; i++) {
17
+ const color = [
18
+ Math.round(start[0] + i * diff[0] * inc),
19
+ Math.round(start[1] + i * diff[1] * inc),
20
+ Math.round(start[2] + i * diff[2] * inc),
21
+ start[3] + i * diff[3] * inc
22
+ ];
23
+ rgba.push(color);
24
+ }
25
+ return rgba;
26
+ }
27
+ //# sourceMappingURL=createColors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createColors.js","sourceRoot":"","sources":["../ts/createColors.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,YAAY,CAC1B,IAAgB,EAChB,EAAc,EACd,MAAc,EACd,QAAe;IACb,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzD,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC1D;IACD,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;IACvB,MAAM,IAAI,GAAG;QACX,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACf,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACf,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACf,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;KACpB,CAAA;IAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QACpB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAEtB,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IAEvC,MAAM,IAAI,GAAU,EAAE,CAAA;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,KAAK,GAAG;YACZ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACxC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACxC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACxC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG;SAC7B,CAAA;QACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;KACjB;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { ColorMap, Alpha, RGBA } from './interfaces';
2
+ /**
3
+ * Create colors with specified color map.
4
+ */
5
+ export declare function createColorsFromMap(colormap: ColorMap, shades: number, alpha?: Alpha): RGBA[];
@@ -0,0 +1,22 @@
1
+ import { createColors } from './createColors';
2
+ /**
3
+ * Create colors with specified color map.
4
+ */
5
+ export function createColorsFromMap(colormap, shades, alpha) {
6
+ if (shades < colormap.length) {
7
+ throw new Error(`Requires at least ${colormap.length} shades.`);
8
+ }
9
+ const result = [];
10
+ const steps = [];
11
+ for (let i = 0; i < colormap.length; i++) {
12
+ steps.push(Math.round(colormap[i].index * shades));
13
+ }
14
+ for (let i = 0; i < colormap.length - 1; i++) {
15
+ const n = steps[i + 1] - steps[i];
16
+ const from = colormap[i].rgb;
17
+ const to = colormap[i + 1].rgb;
18
+ result.push(...createColors(from, to, n, alpha));
19
+ }
20
+ return result;
21
+ }
22
+ //# sourceMappingURL=createColorsFromMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createColorsFromMap.js","sourceRoot":"","sources":["../ts/createColorsFromMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG7C;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAkB,EAAE,MAAc,EAAE,KAAa;IACnF,IAAI,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,CAAC,MAAM,UAAU,CAAC,CAAA;KAChE;IAED,MAAM,MAAM,GAAW,EAAE,CAAA;IACzB,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACxC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,CAAA;KACnD;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QAC5C,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACjC,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QAC7B,MAAM,EAAE,GAAG,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA;KACjD;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
package/esm/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './createColors';
2
+ export * from './createColorsFromMap';
3
+ export * from './interfaces';
4
+ export * from './rgbHex';
5
+ export * from './rgbaString';
package/esm/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from './createColors';
2
+ export * from './createColorsFromMap';
3
+ export * from './interfaces';
4
+ export * from './rgbHex';
5
+ export * from './rgbaString';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA"}
@@ -0,0 +1,14 @@
1
+ export declare type RGB = [number, number, number];
2
+ export declare type RGBA = [number, number, number, number];
3
+ export declare type Alpha = [number, number];
4
+ export declare type ColorMap = {
5
+ /**
6
+ * Defines how fast or slow the `rgb` values will change from one segment to the next.
7
+ * i.e. the steepness of the gradient between two segments.
8
+ */
9
+ index: number;
10
+ /**
11
+ * RGB or RGBA. if RGBA, this alpha will be used instead of the alpha specified in the call.
12
+ */
13
+ rgb: RGB | RGBA;
14
+ }[];
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../ts/interfaces.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { RGB, RGBA } from './interfaces';
2
+ /**
3
+ * Convert `RGB` to `#rgb`
4
+ * JavaScript note: no check for array length, use it properly.
5
+ */
6
+ export declare function rgbHex(rgb: RGB | RGBA): string;
package/esm/rgbHex.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Convert `RGB` to `#rgb`
3
+ * JavaScript note: no check for array length, use it properly.
4
+ */
5
+ export function rgbHex(rgb) {
6
+ let hex = '#';
7
+ for (let i = 0; i < 3; i++) {
8
+ hex += d2h(rgb[i]);
9
+ }
10
+ return hex;
11
+ }
12
+ function d2h(d) {
13
+ const s = (+d).toString(16);
14
+ return s.length < 2 ? '0' + s : s;
15
+ }
16
+ //# sourceMappingURL=rgbHex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rgbHex.js","sourceRoot":"","sources":["../ts/rgbHex.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,GAAe;IACpC,IAAI,GAAG,GAAG,GAAG,CAAA;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QAC1B,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;KACnB;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,GAAG,CAAC,CAAS;IACpB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;IAC3B,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACnC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { RGBA } from './interfaces';
2
+ export declare function rgbaString(rgba: RGBA): string;
@@ -0,0 +1,4 @@
1
+ export function rgbaString(rgba) {
2
+ return 'rgba(' + rgba.join(',') + ')';
3
+ }
4
+ //# sourceMappingURL=rgbaString.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rgbaString.js","sourceRoot":"","sources":["../ts/rgbaString.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACxC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "color-map",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Color map generator",
5
5
  "homepage": "https://github.com/unional/color-map",
6
6
  "bugs": {
@@ -37,6 +37,7 @@
37
37
  "dependency-check:missing": "dependency-check . --missing --no-dev",
38
38
  "dependency-check:unused": "dependency-check . --unused --no-dev",
39
39
  "lint": "eslint --ext=js,ts .",
40
+ "prepublishOnly": "yarn build",
40
41
  "release": "npx semantic-release",
41
42
  "size-limit": "size-limit",
42
43
  "test": "jest",