@thednp/color-picker 1.0.1 → 2.0.0-alpha10
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc.cjs +199 -0
- package/.lgtm.yml +9 -0
- package/.prettierrc.json +15 -0
- package/.stylelintrc.json +236 -0
- package/README.md +55 -72
- package/compile.js +51 -0
- package/cypress/e2e/color-palette.cy.ts +128 -0
- package/cypress/e2e/color-picker.cy.ts +909 -0
- package/cypress/fixtures/colorNamesFrench.js +3 -0
- package/cypress/fixtures/componentLabelsFrench.js +21 -0
- package/cypress/fixtures/format.js +3 -0
- package/cypress/fixtures/getMarkup.js +35 -0
- package/cypress/fixtures/getRandomInt.js +6 -0
- package/cypress/fixtures/sampleWebcolors.js +18 -0
- package/cypress/fixtures/testSample.js +8 -0
- package/cypress/plugins/esbuild-istanbul.ts +50 -0
- package/cypress/plugins/tsCompile.ts +34 -0
- package/cypress/support/commands.ts +0 -0
- package/cypress/support/e2e.ts +21 -0
- package/cypress/test.html +23 -0
- package/cypress.config.ts +29 -0
- package/dist/css/color-picker.css +25 -54
- package/dist/css/color-picker.min.css +2 -2
- package/dist/css/color-picker.rtl.css +25 -54
- package/dist/css/color-picker.rtl.min.css +2 -2
- package/dist/js/color-picker.cjs +8 -0
- package/dist/js/color-picker.cjs.map +1 -0
- package/dist/js/color-picker.d.ts +296 -0
- package/dist/js/color-picker.js +5 -3570
- package/dist/js/color-picker.js.map +1 -0
- package/dist/js/color-picker.mjs +2618 -0
- package/dist/js/color-picker.mjs.map +1 -0
- package/dts.config.ts +15 -0
- package/package.json +116 -108
- package/src/scss/_variables.scss +0 -1
- package/src/scss/color-picker.rtl.scss +4 -0
- package/src/scss/color-picker.scss +93 -51
- package/src/ts/colorPalette.ts +89 -0
- package/src/{js/color-picker.js → ts/index.ts} +498 -509
- package/src/ts/interface/ColorNames.ts +20 -0
- package/src/ts/interface/colorPickerLabels.ts +20 -0
- package/src/ts/interface/colorPickerOptions.ts +11 -0
- package/src/ts/interface/paletteOptions.ts +6 -0
- package/src/ts/util/colorNames.ts +21 -0
- package/src/{js/util/colorPickerLabels.js → ts/util/colorPickerLabels.ts} +4 -2
- package/src/ts/util/getColorControls.ts +90 -0
- package/src/{js/util/getColorForm.js → ts/util/getColorForm.ts} +28 -18
- package/src/{js/util/getColorMenu.js → ts/util/getColorMenu.ts} +21 -30
- package/src/ts/util/isValidJSON.ts +19 -0
- package/src/{js/util/setMarkup.js → ts/util/setMarkup.ts} +61 -50
- package/tsconfig.json +29 -0
- package/vite.config.ts +34 -0
- package/dist/js/color-esm.js +0 -1164
- package/dist/js/color-esm.min.js +0 -2
- package/dist/js/color-palette-esm.js +0 -1235
- package/dist/js/color-palette-esm.min.js +0 -2
- package/dist/js/color-palette.js +0 -1243
- package/dist/js/color-palette.min.js +0 -2
- package/dist/js/color-picker-element-esm.js +0 -3718
- package/dist/js/color-picker-element-esm.min.js +0 -2
- package/dist/js/color-picker-element.js +0 -3726
- package/dist/js/color-picker-element.min.js +0 -2
- package/dist/js/color-picker-esm.js +0 -3565
- package/dist/js/color-picker-esm.min.js +0 -2
- package/dist/js/color-picker.min.js +0 -2
- package/dist/js/color.js +0 -1172
- package/dist/js/color.min.js +0 -2
- package/src/js/color-palette.js +0 -75
- package/src/js/color-picker-element.js +0 -107
- package/src/js/color.js +0 -1104
- package/src/js/index.js +0 -8
- package/src/js/util/colorNames.js +0 -6
- package/src/js/util/getColorControls.js +0 -103
- package/src/js/util/isValidJSON.js +0 -13
- package/src/js/util/nonColors.js +0 -5
- package/src/js/util/roundPart.js +0 -9
- package/src/js/util/setCSSProperties.js +0 -12
- package/src/js/util/tabindex.js +0 -3
- package/src/js/util/toggleCEAttr.js +0 -70
- package/src/js/util/version.js +0 -5
- package/src/js/version.js +0 -5
- package/types/cp.d.ts +0 -558
- package/types/index.d.ts +0 -44
- package/types/source/source.ts +0 -4
- package/types/source/types.d.ts +0 -92
- /package/src/{js/util/vHidden.js → ts/util/vHidden.ts} +0 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
import Color from '@thednp/color';
|
2
|
+
// import { isNumber } from '@thednp/shorty';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Returns a color palette with a given set of parameters.
|
6
|
+
*
|
7
|
+
* @example
|
8
|
+
* new ColorPalette(0, 12, 10, 80);
|
9
|
+
* // => { hue: 0, hueSteps: 12, lightSteps: 10, saturation: 80, colors: Array<Color> }
|
10
|
+
*/
|
11
|
+
export default class ColorPalette {
|
12
|
+
public static Color = Color;
|
13
|
+
hue: number;
|
14
|
+
hueSteps: number;
|
15
|
+
lightSteps: number;
|
16
|
+
saturation: number;
|
17
|
+
colors: Color[];
|
18
|
+
/**
|
19
|
+
* The `hue` parameter is optional, which would be set to 0.
|
20
|
+
* * `args.hue` the starting Hue [0, 360]
|
21
|
+
* * `args.hueSteps` Hue Steps Count [5, 24]
|
22
|
+
* * `args.lightSteps` Lightness Steps Count [5, 12]
|
23
|
+
* * `args.saturation` Saturation [0, 100]
|
24
|
+
*/
|
25
|
+
constructor(...args: [number?, number?, number?, number?]) {
|
26
|
+
let hue = 0;
|
27
|
+
let hueSteps = 12;
|
28
|
+
let lightSteps = 10;
|
29
|
+
let lightnessArray = [0.5];
|
30
|
+
let saturation = 100;
|
31
|
+
// if (!args.every(n => isNumber(n))) throw TypeError('ColorPalette only accepts numbers.');
|
32
|
+
|
33
|
+
if (args.length === 4) {
|
34
|
+
[hue, hueSteps, lightSteps, saturation] = args as [number, number, number, number];
|
35
|
+
} else if (args.length === 3) {
|
36
|
+
[hue, hueSteps, lightSteps] = args as [number, number, number];
|
37
|
+
} else if (args.length === 2) {
|
38
|
+
[hueSteps, lightSteps] = args as [number, number];
|
39
|
+
if ([hueSteps, lightSteps].some(n => n < 1)) {
|
40
|
+
throw TypeError('ColorPalette: the two minimum arguments must be numbers higher than 0.');
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
const colors: Color[] = [];
|
45
|
+
const hueStep = 360 / hueSteps;
|
46
|
+
const half = Color.roundPart((lightSteps - (lightSteps % 2 ? 1 : 0)) / 2);
|
47
|
+
const steps1To13 = [0.25, 0.2, 0.15, 0.11, 0.09, 0.075];
|
48
|
+
const lightSets = [
|
49
|
+
[1, 2, 3],
|
50
|
+
[4, 5],
|
51
|
+
[6, 7],
|
52
|
+
[8, 9],
|
53
|
+
[10, 11],
|
54
|
+
[12, 13],
|
55
|
+
];
|
56
|
+
const closestSet = lightSets.find(set => set.includes(lightSteps));
|
57
|
+
|
58
|
+
// find a lightStep that won't go beyond black and white
|
59
|
+
// something within the [10-90] range of lightness
|
60
|
+
const lightStep = closestSet
|
61
|
+
? steps1To13[lightSets.indexOf(closestSet)]
|
62
|
+
: 100 / (lightSteps + (lightSteps % 2 ? 0 : 1)) / 100;
|
63
|
+
|
64
|
+
// light tints
|
65
|
+
for (let i = 1; i < half + 1; i += 1) {
|
66
|
+
lightnessArray = [...lightnessArray, 0.5 + lightStep * i];
|
67
|
+
}
|
68
|
+
|
69
|
+
// dark tints
|
70
|
+
for (let i = 1; i < lightSteps - half; i += 1) {
|
71
|
+
lightnessArray = [0.5 - lightStep * i, ...lightnessArray];
|
72
|
+
}
|
73
|
+
|
74
|
+
// feed `colors` Array
|
75
|
+
for (let i = 0; i < hueSteps; i += 1) {
|
76
|
+
const currentHue = ((hue + i * hueStep) % 360) / 360;
|
77
|
+
lightnessArray.forEach(l => {
|
78
|
+
const newColor = new Color({ h: currentHue, s: 1, l });
|
79
|
+
colors.push(saturation < 100 ? newColor.saturate(saturation - 100) : newColor);
|
80
|
+
});
|
81
|
+
}
|
82
|
+
|
83
|
+
this.hue = hue;
|
84
|
+
this.hueSteps = hueSteps;
|
85
|
+
this.lightSteps = lightSteps;
|
86
|
+
this.saturation = saturation;
|
87
|
+
this.colors = colors;
|
88
|
+
}
|
89
|
+
}
|