@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.
Files changed (86) hide show
  1. package/.eslintrc.cjs +199 -0
  2. package/.lgtm.yml +9 -0
  3. package/.prettierrc.json +15 -0
  4. package/.stylelintrc.json +236 -0
  5. package/README.md +55 -72
  6. package/compile.js +51 -0
  7. package/cypress/e2e/color-palette.cy.ts +128 -0
  8. package/cypress/e2e/color-picker.cy.ts +909 -0
  9. package/cypress/fixtures/colorNamesFrench.js +3 -0
  10. package/cypress/fixtures/componentLabelsFrench.js +21 -0
  11. package/cypress/fixtures/format.js +3 -0
  12. package/cypress/fixtures/getMarkup.js +35 -0
  13. package/cypress/fixtures/getRandomInt.js +6 -0
  14. package/cypress/fixtures/sampleWebcolors.js +18 -0
  15. package/cypress/fixtures/testSample.js +8 -0
  16. package/cypress/plugins/esbuild-istanbul.ts +50 -0
  17. package/cypress/plugins/tsCompile.ts +34 -0
  18. package/cypress/support/commands.ts +0 -0
  19. package/cypress/support/e2e.ts +21 -0
  20. package/cypress/test.html +23 -0
  21. package/cypress.config.ts +29 -0
  22. package/dist/css/color-picker.css +25 -54
  23. package/dist/css/color-picker.min.css +2 -2
  24. package/dist/css/color-picker.rtl.css +25 -54
  25. package/dist/css/color-picker.rtl.min.css +2 -2
  26. package/dist/js/color-picker.cjs +8 -0
  27. package/dist/js/color-picker.cjs.map +1 -0
  28. package/dist/js/color-picker.d.ts +296 -0
  29. package/dist/js/color-picker.js +5 -3570
  30. package/dist/js/color-picker.js.map +1 -0
  31. package/dist/js/color-picker.mjs +2618 -0
  32. package/dist/js/color-picker.mjs.map +1 -0
  33. package/dts.config.ts +15 -0
  34. package/package.json +116 -108
  35. package/src/scss/_variables.scss +0 -1
  36. package/src/scss/color-picker.rtl.scss +4 -0
  37. package/src/scss/color-picker.scss +93 -51
  38. package/src/ts/colorPalette.ts +89 -0
  39. package/src/{js/color-picker.js → ts/index.ts} +498 -509
  40. package/src/ts/interface/ColorNames.ts +20 -0
  41. package/src/ts/interface/colorPickerLabels.ts +20 -0
  42. package/src/ts/interface/colorPickerOptions.ts +11 -0
  43. package/src/ts/interface/paletteOptions.ts +6 -0
  44. package/src/ts/util/colorNames.ts +21 -0
  45. package/src/{js/util/colorPickerLabels.js → ts/util/colorPickerLabels.ts} +4 -2
  46. package/src/ts/util/getColorControls.ts +90 -0
  47. package/src/{js/util/getColorForm.js → ts/util/getColorForm.ts} +28 -18
  48. package/src/{js/util/getColorMenu.js → ts/util/getColorMenu.ts} +21 -30
  49. package/src/ts/util/isValidJSON.ts +19 -0
  50. package/src/{js/util/setMarkup.js → ts/util/setMarkup.ts} +61 -50
  51. package/tsconfig.json +29 -0
  52. package/vite.config.ts +34 -0
  53. package/dist/js/color-esm.js +0 -1164
  54. package/dist/js/color-esm.min.js +0 -2
  55. package/dist/js/color-palette-esm.js +0 -1235
  56. package/dist/js/color-palette-esm.min.js +0 -2
  57. package/dist/js/color-palette.js +0 -1243
  58. package/dist/js/color-palette.min.js +0 -2
  59. package/dist/js/color-picker-element-esm.js +0 -3718
  60. package/dist/js/color-picker-element-esm.min.js +0 -2
  61. package/dist/js/color-picker-element.js +0 -3726
  62. package/dist/js/color-picker-element.min.js +0 -2
  63. package/dist/js/color-picker-esm.js +0 -3565
  64. package/dist/js/color-picker-esm.min.js +0 -2
  65. package/dist/js/color-picker.min.js +0 -2
  66. package/dist/js/color.js +0 -1172
  67. package/dist/js/color.min.js +0 -2
  68. package/src/js/color-palette.js +0 -75
  69. package/src/js/color-picker-element.js +0 -107
  70. package/src/js/color.js +0 -1104
  71. package/src/js/index.js +0 -8
  72. package/src/js/util/colorNames.js +0 -6
  73. package/src/js/util/getColorControls.js +0 -103
  74. package/src/js/util/isValidJSON.js +0 -13
  75. package/src/js/util/nonColors.js +0 -5
  76. package/src/js/util/roundPart.js +0 -9
  77. package/src/js/util/setCSSProperties.js +0 -12
  78. package/src/js/util/tabindex.js +0 -3
  79. package/src/js/util/toggleCEAttr.js +0 -70
  80. package/src/js/util/version.js +0 -5
  81. package/src/js/version.js +0 -5
  82. package/types/cp.d.ts +0 -558
  83. package/types/index.d.ts +0 -44
  84. package/types/source/source.ts +0 -4
  85. package/types/source/types.d.ts +0 -92
  86. /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
+ }