@thednp/color-picker 2.0.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -4
- package/dist/css/color-picker.css +7 -7
- package/dist/css/color-picker.min.css +2 -2
- package/dist/css/color-picker.rtl.css +7 -7
- package/dist/css/color-picker.rtl.min.css +2 -2
- package/dist/js/color-picker.cjs +2 -2
- package/dist/js/color-picker.cjs.map +1 -1
- package/dist/js/color-picker.js +2 -2
- package/dist/js/color-picker.js.map +1 -1
- package/dist/js/color-picker.mjs +243 -239
- package/dist/js/color-picker.mjs.map +1 -1
- package/package.json +32 -35
- package/src/scss/color-picker.scss +6 -4
- package/src/ts/colorPalette.ts +2 -2
- package/src/ts/index.ts +20 -19
- package/test/color-palette.test.ts +137 -0
- package/test/color-picker.test.ts +705 -0
- package/{cypress → test}/fixtures/getMarkup.js +8 -7
- package/test/fixtures/swipe.ts +33 -0
- package/test/fixtures/write.ts +37 -0
- package/tsconfig.json +45 -27
- package/{vite.config.ts → vite.config.mts} +5 -12
- package/vitest.config-ui.ts +26 -0
- package/vitest.config.ts +26 -0
- package/cypress/e2e/color-palette.cy.ts +0 -128
- package/cypress/e2e/color-picker.cy.ts +0 -909
- package/cypress/plugins/esbuild-istanbul.ts +0 -50
- package/cypress/plugins/tsCompile.ts +0 -34
- package/cypress/support/commands.ts +0 -0
- package/cypress/support/e2e.ts +0 -21
- package/cypress/test.html +0 -23
- package/cypress.config.ts +0 -29
- /package/{compile.js → compile.cjs} +0 -0
- /package/{cypress → test}/fixtures/colorNamesFrench.js +0 -0
- /package/{cypress → test}/fixtures/componentLabelsFrench.js +0 -0
- /package/{cypress → test}/fixtures/format.js +0 -0
- /package/{cypress → test}/fixtures/getRandomInt.js +0 -0
- /package/{cypress → test}/fixtures/sampleWebcolors.js +0 -0
- /package/{cypress → test}/fixtures/testSample.js +0 -0
package/package.json
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
{
|
2
2
|
"name": "@thednp/color-picker",
|
3
|
-
"version": "2.0.
|
3
|
+
"version": "2.0.2",
|
4
4
|
"author": "thednp",
|
5
5
|
"license": "MIT",
|
6
6
|
"description": "🎨 Modern Color Picker Component",
|
7
|
-
"homepage": "
|
7
|
+
"homepage": "https://thednp.github.io/color-picker",
|
8
|
+
"type": "module",
|
8
9
|
"source": "./src/ts/index.ts",
|
9
10
|
"main": "./dist/js/color-picker.js",
|
10
11
|
"module": "./dist/js/color-picker.mjs",
|
11
12
|
"style": "./dist/css/color-picker.css",
|
12
13
|
"sass": "./src/scss/color-picker.scss",
|
14
|
+
"sideEffects": false,
|
13
15
|
"exports": {
|
14
16
|
".": {
|
15
17
|
"require": "./dist/js/color-picker.cjs",
|
@@ -54,44 +56,39 @@
|
|
54
56
|
"typescript"
|
55
57
|
],
|
56
58
|
"dependencies": {
|
57
|
-
"@thednp/color": "^1.0.
|
58
|
-
"@thednp/shorty": "2.0.
|
59
|
+
"@thednp/color": "^1.0.11",
|
60
|
+
"@thednp/shorty": "^2.0.4"
|
59
61
|
},
|
60
62
|
"devDependencies": {
|
61
|
-
"@
|
62
|
-
"@cypress/code-coverage": "^3.12.44",
|
63
|
-
"@types/istanbul-lib-instrument": "^1.7.7",
|
64
|
-
"@types/node": "^22.2.0",
|
63
|
+
"@types/node": "^22.5.5",
|
65
64
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
66
65
|
"@typescript-eslint/parser": "^6.21.0",
|
67
|
-
"
|
66
|
+
"@vitest/browser": "^2.1.1",
|
67
|
+
"@vitest/coverage-istanbul": "^2.1.1",
|
68
|
+
"@vitest/ui": "^2.1.1",
|
68
69
|
"dts-bundle-generator": "^9.5.1",
|
69
|
-
"eslint": "^8.57.
|
70
|
+
"eslint": "^8.57.1",
|
70
71
|
"eslint-plugin-jsdoc": "^46.10.1",
|
71
72
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
72
73
|
"eslint-plugin-prettier": "^5.2.1",
|
73
|
-
"
|
74
|
-
"istanbul-lib-instrument": "^6.0.3",
|
75
|
-
"ncp": "^2.0.0",
|
76
|
-
"npm-run-all": "^4.1.5",
|
77
|
-
"nyc": "^15.1.0",
|
74
|
+
"playwright": "^1.47.1",
|
78
75
|
"prettier": "^3.3.3",
|
79
|
-
"
|
80
|
-
"sass": "^1.77.8",
|
76
|
+
"sass": "^1.79.1",
|
81
77
|
"stylelint": "^15.11.0",
|
82
78
|
"stylelint-config-standard": "^34.0.0",
|
83
79
|
"stylelint-config-standard-scss": "^11.1.0",
|
84
80
|
"stylelint-order": "^6.0.4",
|
85
81
|
"stylelint-scss": "^5.3.2",
|
86
|
-
"typescript": "^5.
|
87
|
-
"vite": "^5.4.
|
82
|
+
"typescript": "^5.6.2",
|
83
|
+
"vite": "^5.4.6",
|
84
|
+
"vitest": "^2.1.1"
|
88
85
|
},
|
89
86
|
"scripts": {
|
90
87
|
"pre-test": "pnpm clean-coverage",
|
91
|
-
"test": "pnpm pre-test &&
|
92
|
-
"
|
93
|
-
"badges": "npx -p dependency-version-badge update-badge typescript
|
94
|
-
"clean-coverage": "
|
88
|
+
"test": "pnpm pre-test && vitest --config vitest.config.ts",
|
89
|
+
"test-ui": "pnpm pre-test && vitest --config vitest.config-ui.ts --browser=chrome",
|
90
|
+
"badges": "npx -p dependency-version-badge update-badge typescript eslint prettier vitest vite",
|
91
|
+
"clean-coverage": "rm -rf coverage && rm -rf .nyc_output",
|
95
92
|
"coverage:report": "nyc report --reporter=lcov --reporter=json --reporter=text --reporter=json-summary",
|
96
93
|
"format": "prettier --write \"src/**/*.ts\"",
|
97
94
|
"lint": "pnpm lint:ts && pnpm check:ts && pnpm lint:css",
|
@@ -100,18 +97,18 @@
|
|
100
97
|
"check:ts": "tsc --noEmit",
|
101
98
|
"fix:css": "stylelint --config .stylelintrc.json --fix scss \"src/scss/*.scss\"",
|
102
99
|
"lint:css": "stylelint --config .stylelintrc.json scss \"src/scss/*.scss\"",
|
103
|
-
"build": "
|
104
|
-
"build-vite": "vite build && pnpm docs",
|
100
|
+
"build": "vite build && pnpm dts",
|
105
101
|
"dev": "vite --open ./docs/dev.html --port 8577",
|
106
|
-
"dts": "dts-bundle-generator --config ./dts.config.ts",
|
107
|
-
"
|
108
|
-
"copy": "
|
109
|
-
"copy-
|
110
|
-
"copy-css-
|
111
|
-
"
|
112
|
-
"compile
|
113
|
-
"compile-scss
|
114
|
-
"compile-scss-
|
115
|
-
"compile-scss-rtl
|
102
|
+
"dts": "pnpm dts-bundle-generator --config ./dts.config.ts",
|
103
|
+
"copy": "pnpm copy-css-cp && pnpm copy-css-rtl && pnpm copy-js && pnpm copy-js-map",
|
104
|
+
"copy-js": "cp dist/js/color-picker.js docs/js/color-picker.js",
|
105
|
+
"copy-js-map": "cp dist/js/color-picker.js.map docs/js/color-picker.js.map",
|
106
|
+
"copy-css-cp": "cp dist/css/color-picker.css docs/css/color-picker.css",
|
107
|
+
"copy-css-rtl": "cp dist/css/color-picker.rtl.css docs/css/color-picker.rtl.css",
|
108
|
+
"compile": "pnpm lint:css && pnpm compile-scss && pnpm compile-scss-min && pnpm compile-scss-rtl && pnpm compile-scss-rtl-min && pnpm copy",
|
109
|
+
"compile-scss": "node compile.cjs",
|
110
|
+
"compile-scss-min": "node compile.cjs MIN:true",
|
111
|
+
"compile-scss-rtl": "node compile.cjs MIN:false,DIR:rtl",
|
112
|
+
"compile-scss-rtl-min": "node compile.cjs MIN:true,DIR:rtl"
|
116
113
|
}
|
117
114
|
}
|
@@ -1,14 +1,14 @@
|
|
1
1
|
@import "variables";
|
2
2
|
|
3
|
+
*, *::before, *::after {
|
4
|
+
box-sizing: border-box;
|
5
|
+
}
|
6
|
+
|
3
7
|
/* :host */
|
4
8
|
.color-picker {
|
5
9
|
position: relative;
|
6
10
|
display: flex;
|
7
11
|
|
8
|
-
*, *::before, *::after {
|
9
|
-
box-sizing: border-box;
|
10
|
-
}
|
11
|
-
|
12
12
|
@each $name in "white", "black" {
|
13
13
|
@each $lvl in $transparency-levels {
|
14
14
|
@if type-of($name) == "string" and type-of($lvl) == "number" {
|
@@ -21,6 +21,8 @@
|
|
21
21
|
$rgba: rgba($color, $lvl * 1%);
|
22
22
|
|
23
23
|
--#{$name}-#{$lvl}: #{$rgba};
|
24
|
+
|
25
|
+
// --#{$name}-#{$lvl}: #{rgba($color, $lvl * 1%)};
|
24
26
|
}
|
25
27
|
}
|
26
28
|
}
|
package/src/ts/colorPalette.ts
CHANGED
@@ -73,9 +73,9 @@ export default class ColorPalette {
|
|
73
73
|
|
74
74
|
// feed `colors` Array
|
75
75
|
for (let i = 0; i < hueSteps; i += 1) {
|
76
|
-
const currentHue = (
|
76
|
+
const currentHue = (hue + i * hueStep) % 360;
|
77
77
|
lightnessArray.forEach(l => {
|
78
|
-
const newColor = new Color({ h: currentHue, s:
|
78
|
+
const newColor = new Color({ h: currentHue, s: 100, l: l * 100 });
|
79
79
|
colors.push(saturation < 100 ? newColor.saturate(saturation - 100) : newColor);
|
80
80
|
});
|
81
81
|
}
|
package/src/ts/index.ts
CHANGED
@@ -117,8 +117,8 @@ const toggleEventsOnShown = (self: ColorPicker, action?: boolean) => {
|
|
117
117
|
const doc = getDocument(input);
|
118
118
|
const win = getWindow(doc);
|
119
119
|
|
120
|
-
fn(self.controls, pointerdownEvent, self.pointerDown
|
121
|
-
self.controlKnobs.forEach(x => fn(x, keydownEvent, self.handleKnobs
|
120
|
+
fn(self.controls, pointerdownEvent, self.pointerDown);
|
121
|
+
self.controlKnobs.forEach(x => fn(x, keydownEvent, self.handleKnobs));
|
122
122
|
|
123
123
|
fn(win, scrollEvent, self.handleScroll);
|
124
124
|
fn(win, resizeEvent, self.update);
|
@@ -127,13 +127,13 @@ const toggleEventsOnShown = (self: ColorPicker, action?: boolean) => {
|
|
127
127
|
|
128
128
|
if (colorMenu) {
|
129
129
|
fn(colorMenu, mouseclickEvent, self.menuClickHandler);
|
130
|
-
fn(colorMenu, keydownEvent, self.menuKeyHandler
|
130
|
+
fn(colorMenu, keydownEvent, self.menuKeyHandler);
|
131
131
|
}
|
132
132
|
|
133
|
-
fn(doc, pointermoveEvent, self.pointerMove
|
134
|
-
fn(doc, pointerupEvent, self.pointerUp
|
135
|
-
fn(parent, focusoutEvent, self.handleFocusOut
|
136
|
-
fn(doc, keyupEvent, self.handleDismiss
|
133
|
+
fn(doc, pointermoveEvent, self.pointerMove);
|
134
|
+
fn(doc, pointerupEvent, self.pointerUp);
|
135
|
+
fn(parent, focusoutEvent, self.handleFocusOut);
|
136
|
+
fn(doc, keyupEvent, self.handleDismiss);
|
137
137
|
};
|
138
138
|
|
139
139
|
/**
|
@@ -465,15 +465,15 @@ export default class ColorPicker {
|
|
465
465
|
const [v1, v2, v3] = visuals;
|
466
466
|
const { offsetHeight } = v1;
|
467
467
|
const hue = controlPositions.c2y / offsetHeight;
|
468
|
-
const { r, g, b } = new Color({ h: hue, s:
|
468
|
+
const { r, g, b } = new Color({ h: hue * 360, s: 100, l: 50 }).toRgb();
|
469
469
|
const whiteGrad = 'linear-gradient(rgb(255,255,255) 0%, rgb(255,255,255) 100%)';
|
470
470
|
const alpha = 1 - controlPositions.c3y / offsetHeight;
|
471
471
|
const roundA = roundPart(alpha * 100) / 100;
|
472
472
|
|
473
473
|
const fill = new Color({
|
474
|
-
h: hue,
|
475
|
-
s:
|
476
|
-
l:
|
474
|
+
h: hue * 360,
|
475
|
+
s: 100,
|
476
|
+
l: 50,
|
477
477
|
a: alpha,
|
478
478
|
}).toRgbString();
|
479
479
|
const hueGradient = `linear-gradient(
|
@@ -547,8 +547,9 @@ export default class ColorPicker {
|
|
547
547
|
const { previousElementSibling, nextElementSibling, parentElement } = target;
|
548
548
|
const isColorOptionsMenu = parentElement && hasClass(parentElement, 'color-options');
|
549
549
|
const allSiblings = parentElement ? [...parentElement.children] : [];
|
550
|
-
const columnsCount =
|
551
|
-
|
550
|
+
// const columnsCount =
|
551
|
+
// isColorOptionsMenu && getElementStyle(parentElement, 'grid-template-columns').split(' ').length;
|
552
|
+
const columnsCount = isColorOptionsMenu && Number(getElementStyle(parentElement, '--grid-fit'));
|
552
553
|
const currentIndex = allSiblings.indexOf(target);
|
553
554
|
const previousElement = currentIndex > -1 && columnsCount && allSiblings[currentIndex - columnsCount];
|
554
555
|
const nextElement = currentIndex > -1 && columnsCount && allSiblings[currentIndex + columnsCount];
|
@@ -861,9 +862,9 @@ export default class ColorPicker {
|
|
861
862
|
|
862
863
|
// new color
|
863
864
|
const { r, g, b, a } = new Color({
|
864
|
-
h: hue,
|
865
|
-
s: saturation,
|
866
|
-
v: lightness,
|
865
|
+
h: hue * 360,
|
866
|
+
s: saturation * 100,
|
867
|
+
v: lightness * 100,
|
867
868
|
a: alpha,
|
868
869
|
});
|
869
870
|
|
@@ -908,9 +909,9 @@ export default class ColorPicker {
|
|
908
909
|
|
909
910
|
// new color
|
910
911
|
const { r, g, b, a } = new Color({
|
911
|
-
h: hue,
|
912
|
-
s: saturation,
|
913
|
-
v: lightness,
|
912
|
+
h: hue * 360,
|
913
|
+
s: saturation * 100,
|
914
|
+
v: lightness * 100,
|
914
915
|
a: alpha,
|
915
916
|
});
|
916
917
|
|
@@ -0,0 +1,137 @@
|
|
1
|
+
import { expect, it, describe } from 'vitest';
|
2
|
+
import Color from "@thednp/color";
|
3
|
+
import ColorPalette from "~/ts/colorPalette";
|
4
|
+
|
5
|
+
describe("ColorPalette Class Test", () => {
|
6
|
+
it("Test init with no parameter, use all default values", () => {
|
7
|
+
const cpl = new ColorPalette();
|
8
|
+
expect(cpl).to.be.instanceOf(ColorPalette);
|
9
|
+
expect(cpl.hue).to.equal(0);
|
10
|
+
expect(cpl.hueSteps).to.equal(12);
|
11
|
+
expect(cpl.lightSteps).to.equal(10);
|
12
|
+
expect(cpl.colors.length).to.equal(120);
|
13
|
+
});
|
14
|
+
|
15
|
+
it("Test init with 1 parameter, throws error", () => {
|
16
|
+
try {
|
17
|
+
new ColorPalette(0, undefined);
|
18
|
+
} catch (error) {
|
19
|
+
expect(error).to.be.instanceOf(TypeError);
|
20
|
+
expect(error).to.have.property(
|
21
|
+
"message",
|
22
|
+
'ColorPalette: the two minimum arguments must be numbers higher than 0.'
|
23
|
+
);
|
24
|
+
}
|
25
|
+
});
|
26
|
+
|
27
|
+
it("Test init with 2 invalid parameters, throws error", () => {
|
28
|
+
try {
|
29
|
+
new ColorPalette(0, 5);
|
30
|
+
} catch (error) {
|
31
|
+
expect(error).to.be.instanceOf(TypeError);
|
32
|
+
expect(error).to.have.property(
|
33
|
+
"message",
|
34
|
+
'ColorPalette: the two minimum arguments must be numbers higher than 0.'
|
35
|
+
);
|
36
|
+
}
|
37
|
+
});
|
38
|
+
|
39
|
+
it("Test init with 2 valid parameters", () => {
|
40
|
+
// generated with new `ColorPalette(1, 5)`
|
41
|
+
const testSample = ["#330000", "#990000", "#ff0000", "#ff6666", "#ffcccc"];
|
42
|
+
const cpl = new ColorPalette(1, 5);
|
43
|
+
|
44
|
+
expect(cpl).to.be.instanceOf(ColorPalette);
|
45
|
+
expect(cpl.hue).to.equal(0);
|
46
|
+
expect(cpl.hueSteps).to.equal(1);
|
47
|
+
expect(cpl.lightSteps).to.equal(5);
|
48
|
+
expect(cpl.saturation).to.equal(100);
|
49
|
+
expect(cpl.colors.length).to.equal(5);
|
50
|
+
|
51
|
+
cpl.colors.forEach((color, i) => {
|
52
|
+
expect(color).to.be.instanceOf(Color);
|
53
|
+
expect(color.toHexString()).to.equal(testSample[i]);
|
54
|
+
})
|
55
|
+
});
|
56
|
+
|
57
|
+
it("Test init with 14 lightSteps", () => {
|
58
|
+
// generated with `new ColorPalette(1, 14)`
|
59
|
+
const testSample = [
|
60
|
+
"#330000", "#550000", "#770000", "#990000", "#bb0000",
|
61
|
+
"#dd0000", "#ff0000", "#ff2222", "#ff4444", "#ff6666",
|
62
|
+
"#ff8888", "#ffaaaa", "#ffcccc", "#ffeeee",
|
63
|
+
];
|
64
|
+
const cpl = new ColorPalette(1, 14);
|
65
|
+
|
66
|
+
expect(cpl).to.be.instanceOf(ColorPalette);
|
67
|
+
expect(cpl.hue).to.equal(0);
|
68
|
+
expect(cpl.hueSteps).to.equal(1);
|
69
|
+
expect(cpl.lightSteps).to.equal(14);
|
70
|
+
expect(cpl.colors.length).to.equal(14);
|
71
|
+
|
72
|
+
cpl.colors.forEach((color, i) => {
|
73
|
+
expect(color).to.be.instanceOf(Color);
|
74
|
+
// expect(color.ok).to.be.true;
|
75
|
+
expect(color.toHexString()).to.equal(testSample[i]);
|
76
|
+
})
|
77
|
+
});
|
78
|
+
|
79
|
+
it("Test init with 15 lightSteps", () => {
|
80
|
+
// generated with `new ColorPalette(1, 15)`
|
81
|
+
const testSample = [
|
82
|
+
"#110000", "#330000", "#550000", "#770000",
|
83
|
+
"#990000", "#bb0000", "#dd0000", "#ff0000",
|
84
|
+
"#ff2222", "#ff4444", "#ff6666", "#ff8888",
|
85
|
+
"#ffaaaa", "#ffcccc", "#ffeeee",
|
86
|
+
];
|
87
|
+
const cpl = new ColorPalette(1, 15);
|
88
|
+
|
89
|
+
expect(cpl).to.be.instanceOf(ColorPalette);
|
90
|
+
expect(cpl.hue).to.equal(0);
|
91
|
+
expect(cpl.hueSteps).to.equal(1);
|
92
|
+
expect(cpl.lightSteps).to.equal(15);
|
93
|
+
expect(cpl.colors.length).to.equal(15);
|
94
|
+
|
95
|
+
cpl.colors.forEach((color, i) => {
|
96
|
+
expect(color).to.be.instanceOf(Color);
|
97
|
+
// expect(color.ok).to.be.true;
|
98
|
+
expect(color.toHexString()).to.equal(testSample[i]);
|
99
|
+
})
|
100
|
+
});
|
101
|
+
|
102
|
+
it("Test init with 3 valid parameters", () => {
|
103
|
+
// generated with `new ColorPalette(270, 1, 10)`
|
104
|
+
const testSample = [
|
105
|
+
"#240047", "#3b0075", "#5200a3", "#6900d1",
|
106
|
+
"#7f00ff", "#962eff", "#ad5cff", "#c48aff",
|
107
|
+
"#dbb8ff", "#f2e5ff",
|
108
|
+
];
|
109
|
+
const cpl = new ColorPalette(270, 1, 10);
|
110
|
+
|
111
|
+
expect(cpl).to.be.instanceOf(ColorPalette);
|
112
|
+
expect(cpl.hue).to.equal(270);
|
113
|
+
expect(cpl.hueSteps).to.equal(1);
|
114
|
+
expect(cpl.lightSteps).to.equal(10);
|
115
|
+
expect(cpl.saturation).to.equal(100);
|
116
|
+
expect(cpl.colors.length).to.equal(10);
|
117
|
+
expect(cpl.colors.map(c => c.toHexString())).to.deep.equal(testSample);
|
118
|
+
});
|
119
|
+
|
120
|
+
it("Test init with 4 valid parameters", () => {
|
121
|
+
// generated with `new ColorPalette(270, 1, 10)`
|
122
|
+
const testSample = [
|
123
|
+
"#240740", "#3b0c6a", "#521093", "#6915bc",
|
124
|
+
"#7f19e6", "#9643ea", "#ad6cef", "#c495f3",
|
125
|
+
"#dbbff8", "#f2e8fc",
|
126
|
+
];
|
127
|
+
const cpl = new ColorPalette(270, 1, 10, 80);
|
128
|
+
|
129
|
+
expect(cpl).to.be.instanceOf(ColorPalette);
|
130
|
+
expect(cpl.hue).to.equal(270);
|
131
|
+
expect(cpl.hueSteps).to.equal(1);
|
132
|
+
expect(cpl.lightSteps).to.equal(10);
|
133
|
+
expect(cpl.saturation).to.equal(80);
|
134
|
+
expect(cpl.colors.length).to.equal(10);
|
135
|
+
expect(cpl.colors.map(c => c.toHexString())).to.deep.equal(testSample);
|
136
|
+
});
|
137
|
+
});
|