@mantine-vue/colors-generator 1.1.2

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/cjs/index.cjs ADDED
@@ -0,0 +1,76 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let chroma_js = require("chroma-js");
25
+ chroma_js = __toESM(chroma_js);
26
+ //#region src/generate-colors.ts
27
+ var LIGHTNESS_MAP = [
28
+ .96,
29
+ .907,
30
+ .805,
31
+ .697,
32
+ .605,
33
+ .547,
34
+ .518,
35
+ .445,
36
+ .395,
37
+ .34
38
+ ];
39
+ var SATURATION_MAP = [
40
+ .32,
41
+ .16,
42
+ .08,
43
+ .04,
44
+ 0,
45
+ 0,
46
+ .04,
47
+ .08,
48
+ .16,
49
+ .32
50
+ ];
51
+ function getClosestLightness(colorObject) {
52
+ const lightnessGoal = colorObject.get("hsl.l");
53
+ return LIGHTNESS_MAP.reduce((prev, curr) => Math.abs(curr - lightnessGoal) < Math.abs(prev - lightnessGoal) ? curr : prev);
54
+ }
55
+ function generateColorsMap(color) {
56
+ const colorObject = (0, chroma_js.default)(color);
57
+ const closestLightness = getClosestLightness(colorObject);
58
+ const baseColorIndex = LIGHTNESS_MAP.findIndex((l) => l === closestLightness);
59
+ const colors = LIGHTNESS_MAP.map((l) => colorObject.set("hsl.l", l)).map((c) => (0, chroma_js.default)(c)).map((c, i) => {
60
+ const saturationDelta = SATURATION_MAP[i] - SATURATION_MAP[baseColorIndex];
61
+ return saturationDelta >= 0 ? c.saturate(saturationDelta) : c.desaturate(saturationDelta * -1);
62
+ });
63
+ colors[baseColorIndex] = (0, chroma_js.default)(color);
64
+ return {
65
+ baseColorIndex,
66
+ colors
67
+ };
68
+ }
69
+ function generateColors(color) {
70
+ return generateColorsMap(color).colors.map((c) => c.hex());
71
+ }
72
+ //#endregion
73
+ exports.generateColors = generateColors;
74
+ exports.generateColorsMap = generateColorsMap;
75
+
76
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/generate-colors.ts"],"sourcesContent":["import chroma from 'chroma-js'\n\nconst LIGHTNESS_MAP = [0.96, 0.907, 0.805, 0.697, 0.605, 0.547, 0.518, 0.445, 0.395, 0.34]\nconst SATURATION_MAP = [0.32, 0.16, 0.08, 0.04, 0, 0, 0.04, 0.08, 0.16, 0.32]\n\nfunction getClosestLightness(colorObject: chroma.Color) {\n const lightnessGoal = colorObject.get('hsl.l')\n return LIGHTNESS_MAP.reduce((prev, curr) =>\n Math.abs(curr - lightnessGoal) < Math.abs(prev - lightnessGoal) ? curr : prev,\n )\n}\n\nexport function generateColorsMap(color: string) {\n const colorObject = chroma(color)\n const closestLightness = getClosestLightness(colorObject)\n const baseColorIndex = LIGHTNESS_MAP.findIndex((l) => l === closestLightness)\n\n const colors = LIGHTNESS_MAP.map((l) => colorObject.set('hsl.l', l))\n .map((c) => chroma(c))\n .map((c, i) => {\n const saturationDelta = SATURATION_MAP[i] - SATURATION_MAP[baseColorIndex]\n return saturationDelta >= 0 ? c.saturate(saturationDelta) : c.desaturate(saturationDelta * -1)\n })\n\n colors[baseColorIndex] = chroma(color)\n\n return { baseColorIndex, colors }\n}\n\nexport type MantineColorsTuple = readonly [\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n ...string[],\n]\n\nexport function generateColors(color: string) {\n return generateColorsMap(color).colors.map((c) => c.hex()) as unknown as MantineColorsTuple\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,gBAAgB;CAAC;CAAM;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;AAAI;AACzF,IAAM,iBAAiB;CAAC;CAAM;CAAM;CAAM;CAAM;CAAG;CAAG;CAAM;CAAM;CAAM;AAAI;AAE5E,SAAS,oBAAoB,aAA2B;CACtD,MAAM,gBAAgB,YAAY,IAAI,OAAO;CAC7C,OAAO,cAAc,QAAQ,MAAM,SACjC,KAAK,IAAI,OAAO,aAAa,IAAI,KAAK,IAAI,OAAO,aAAa,IAAI,OAAO,IAC3E;AACF;AAEA,SAAgB,kBAAkB,OAAe;CAC/C,MAAM,eAAA,GAAA,UAAA,SAAqB,KAAK;CAChC,MAAM,mBAAmB,oBAAoB,WAAW;CACxD,MAAM,iBAAiB,cAAc,WAAW,MAAM,MAAM,gBAAgB;CAE5E,MAAM,SAAS,cAAc,KAAK,MAAM,YAAY,IAAI,SAAS,CAAC,CAAC,EAChE,KAAK,OAAA,GAAA,UAAA,SAAa,CAAC,CAAC,EACpB,KAAK,GAAG,MAAM;EACb,MAAM,kBAAkB,eAAe,KAAK,eAAe;EAC3D,OAAO,mBAAmB,IAAI,EAAE,SAAS,eAAe,IAAI,EAAE,WAAW,kBAAkB,EAAE;CAC/F,CAAC;CAEH,OAAO,mBAAA,GAAA,UAAA,SAAyB,KAAK;CAErC,OAAO;EAAE;EAAgB;CAAO;AAClC;AAgBA,SAAgB,eAAe,OAAe;CAC5C,OAAO,kBAAkB,KAAK,EAAE,OAAO,KAAK,MAAM,EAAE,IAAI,CAAC;AAC3D"}
package/esm/index.mjs ADDED
@@ -0,0 +1,51 @@
1
+ import chroma from "chroma-js";
2
+ //#region src/generate-colors.ts
3
+ var LIGHTNESS_MAP = [
4
+ .96,
5
+ .907,
6
+ .805,
7
+ .697,
8
+ .605,
9
+ .547,
10
+ .518,
11
+ .445,
12
+ .395,
13
+ .34
14
+ ];
15
+ var SATURATION_MAP = [
16
+ .32,
17
+ .16,
18
+ .08,
19
+ .04,
20
+ 0,
21
+ 0,
22
+ .04,
23
+ .08,
24
+ .16,
25
+ .32
26
+ ];
27
+ function getClosestLightness(colorObject) {
28
+ const lightnessGoal = colorObject.get("hsl.l");
29
+ return LIGHTNESS_MAP.reduce((prev, curr) => Math.abs(curr - lightnessGoal) < Math.abs(prev - lightnessGoal) ? curr : prev);
30
+ }
31
+ function generateColorsMap(color) {
32
+ const colorObject = chroma(color);
33
+ const closestLightness = getClosestLightness(colorObject);
34
+ const baseColorIndex = LIGHTNESS_MAP.findIndex((l) => l === closestLightness);
35
+ const colors = LIGHTNESS_MAP.map((l) => colorObject.set("hsl.l", l)).map((c) => chroma(c)).map((c, i) => {
36
+ const saturationDelta = SATURATION_MAP[i] - SATURATION_MAP[baseColorIndex];
37
+ return saturationDelta >= 0 ? c.saturate(saturationDelta) : c.desaturate(saturationDelta * -1);
38
+ });
39
+ colors[baseColorIndex] = chroma(color);
40
+ return {
41
+ baseColorIndex,
42
+ colors
43
+ };
44
+ }
45
+ function generateColors(color) {
46
+ return generateColorsMap(color).colors.map((c) => c.hex());
47
+ }
48
+ //#endregion
49
+ export { generateColors, generateColorsMap };
50
+
51
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/generate-colors.ts"],"sourcesContent":["import chroma from 'chroma-js'\n\nconst LIGHTNESS_MAP = [0.96, 0.907, 0.805, 0.697, 0.605, 0.547, 0.518, 0.445, 0.395, 0.34]\nconst SATURATION_MAP = [0.32, 0.16, 0.08, 0.04, 0, 0, 0.04, 0.08, 0.16, 0.32]\n\nfunction getClosestLightness(colorObject: chroma.Color) {\n const lightnessGoal = colorObject.get('hsl.l')\n return LIGHTNESS_MAP.reduce((prev, curr) =>\n Math.abs(curr - lightnessGoal) < Math.abs(prev - lightnessGoal) ? curr : prev,\n )\n}\n\nexport function generateColorsMap(color: string) {\n const colorObject = chroma(color)\n const closestLightness = getClosestLightness(colorObject)\n const baseColorIndex = LIGHTNESS_MAP.findIndex((l) => l === closestLightness)\n\n const colors = LIGHTNESS_MAP.map((l) => colorObject.set('hsl.l', l))\n .map((c) => chroma(c))\n .map((c, i) => {\n const saturationDelta = SATURATION_MAP[i] - SATURATION_MAP[baseColorIndex]\n return saturationDelta >= 0 ? c.saturate(saturationDelta) : c.desaturate(saturationDelta * -1)\n })\n\n colors[baseColorIndex] = chroma(color)\n\n return { baseColorIndex, colors }\n}\n\nexport type MantineColorsTuple = readonly [\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n string,\n ...string[],\n]\n\nexport function generateColors(color: string) {\n return generateColorsMap(color).colors.map((c) => c.hex()) as unknown as MantineColorsTuple\n}\n"],"mappings":";;AAEA,IAAM,gBAAgB;CAAC;CAAM;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;AAAI;AACzF,IAAM,iBAAiB;CAAC;CAAM;CAAM;CAAM;CAAM;CAAG;CAAG;CAAM;CAAM;CAAM;AAAI;AAE5E,SAAS,oBAAoB,aAA2B;CACtD,MAAM,gBAAgB,YAAY,IAAI,OAAO;CAC7C,OAAO,cAAc,QAAQ,MAAM,SACjC,KAAK,IAAI,OAAO,aAAa,IAAI,KAAK,IAAI,OAAO,aAAa,IAAI,OAAO,IAC3E;AACF;AAEA,SAAgB,kBAAkB,OAAe;CAC/C,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,mBAAmB,oBAAoB,WAAW;CACxD,MAAM,iBAAiB,cAAc,WAAW,MAAM,MAAM,gBAAgB;CAE5E,MAAM,SAAS,cAAc,KAAK,MAAM,YAAY,IAAI,SAAS,CAAC,CAAC,EAChE,KAAK,MAAM,OAAO,CAAC,CAAC,EACpB,KAAK,GAAG,MAAM;EACb,MAAM,kBAAkB,eAAe,KAAK,eAAe;EAC3D,OAAO,mBAAmB,IAAI,EAAE,SAAS,eAAe,IAAI,EAAE,WAAW,kBAAkB,EAAE;CAC/F,CAAC;CAEH,OAAO,kBAAkB,OAAO,KAAK;CAErC,OAAO;EAAE;EAAgB;CAAO;AAClC;AAgBA,SAAgB,eAAe,OAAe;CAC5C,OAAO,kBAAkB,KAAK,EAAE,OAAO,KAAK,MAAM,EAAE,IAAI,CAAC;AAC3D"}
@@ -0,0 +1,19 @@
1
+ import chroma from 'chroma-js';
2
+ export declare function generateColorsMap(color: string): {
3
+ baseColorIndex: number;
4
+ colors: chroma.Color[];
5
+ };
6
+ export type MantineColorsTuple = readonly [
7
+ string,
8
+ string,
9
+ string,
10
+ string,
11
+ string,
12
+ string,
13
+ string,
14
+ string,
15
+ string,
16
+ string,
17
+ ...string[]
18
+ ];
19
+ export declare function generateColors(color: string): MantineColorsTuple;
@@ -0,0 +1,2 @@
1
+ export { generateColors, generateColorsMap } from './generate-colors';
2
+ export type { MantineColorsTuple } from './generate-colors';
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { generateColors, generateColorsMap } from './generate-colors';
2
+ export type { MantineColorsTuple } from './generate-colors';
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@mantine-vue/colors-generator",
3
+ "version": "1.1.2",
4
+ "description": "A library to generate 10 shades of color based on provided color value",
5
+ "license": "MIT",
6
+ "files": [
7
+ "cjs",
8
+ "esm",
9
+ "lib",
10
+ "styles.css",
11
+ "styles.layer.css",
12
+ "styles"
13
+ ],
14
+ "sideEffects": false,
15
+ "main": "./cjs/index.cjs",
16
+ "module": "./esm/index.mjs",
17
+ "types": "./lib/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": {
21
+ "types": "./lib/index.d.mts",
22
+ "default": "./esm/index.mjs"
23
+ },
24
+ "require": {
25
+ "types": "./lib/index.d.ts",
26
+ "default": "./cjs/index.cjs"
27
+ }
28
+ }
29
+ },
30
+ "devDependencies": {
31
+ "@types/chroma-js": "^3.1.2",
32
+ "chroma-js": "^3.2.0"
33
+ },
34
+ "peerDependencies": {
35
+ "chroma-js": ">=2.4.2"
36
+ }
37
+ }