@thednp/color-picker 1.0.0 → 2.0.0-alpha1

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.
Files changed (88) 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/LICENSE +0 -0
  6. package/README.md +63 -80
  7. package/compile.js +48 -0
  8. package/cypress/downloads/downloads.htm +0 -0
  9. package/cypress/e2e/color-palette.cy.ts +128 -0
  10. package/cypress/e2e/color-picker.cy.ts +920 -0
  11. package/cypress/fixtures/colorNamesFrench.js +3 -0
  12. package/cypress/fixtures/componentLabelsFrench.js +21 -0
  13. package/cypress/fixtures/format.js +3 -0
  14. package/cypress/fixtures/getCEMarkup.js +29 -0
  15. package/cypress/fixtures/getMarkup.js +28 -0
  16. package/cypress/fixtures/getRandomInt.js +6 -0
  17. package/cypress/fixtures/sampleWebcolors.js +18 -0
  18. package/cypress/fixtures/testSample.js +8 -0
  19. package/cypress/plugins/esbuild-istanbul.ts +50 -0
  20. package/cypress/plugins/tsCompile.ts +34 -0
  21. package/cypress/support/commands.ts +0 -0
  22. package/cypress/support/e2e.ts +21 -0
  23. package/cypress/test.html +23 -0
  24. package/cypress.config.ts +29 -0
  25. package/dist/css/color-picker.css +15 -39
  26. package/dist/css/color-picker.min.css +2 -2
  27. package/dist/css/color-picker.rtl.css +15 -39
  28. package/dist/css/color-picker.rtl.min.css +2 -2
  29. package/dist/js/color-picker.cjs +8 -0
  30. package/dist/js/color-picker.cjs.map +1 -0
  31. package/dist/js/color-picker.d.ts +278 -0
  32. package/dist/js/color-picker.js +5 -3583
  33. package/dist/js/color-picker.js.map +1 -0
  34. package/dist/js/color-picker.mjs +2631 -0
  35. package/dist/js/color-picker.mjs.map +1 -0
  36. package/dts.config.ts +15 -0
  37. package/package.json +64 -74
  38. package/src/scss/_variables.scss +0 -1
  39. package/src/scss/color-picker.rtl.scss +4 -0
  40. package/src/scss/color-picker.scss +75 -39
  41. package/src/ts/colorPalette.ts +89 -0
  42. package/src/{js/color-picker.js → ts/index.ts} +492 -502
  43. package/src/ts/interface/colorPickerLabels.ts +20 -0
  44. package/src/ts/interface/colorPickerOptions.ts +11 -0
  45. package/src/ts/interface/paletteOptions.ts +6 -0
  46. package/src/ts/util/colorNames.ts +21 -0
  47. package/src/{js/util/colorPickerLabels.js → ts/util/colorPickerLabels.ts} +4 -2
  48. package/src/ts/util/getColorControls.ts +90 -0
  49. package/src/{js/util/getColorForm.js → ts/util/getColorForm.ts} +28 -18
  50. package/src/{js/util/getColorMenu.js → ts/util/getColorMenu.ts} +21 -30
  51. package/src/ts/util/isValidJSON.ts +19 -0
  52. package/src/{js/util/setMarkup.js → ts/util/setMarkup.ts} +57 -48
  53. package/src/{js/util/vHidden.js → ts/util/vHidden.ts} +0 -0
  54. package/tsconfig.json +29 -0
  55. package/vite.config.ts +34 -0
  56. package/dist/js/color-esm.js +0 -1167
  57. package/dist/js/color-esm.min.js +0 -2
  58. package/dist/js/color-palette-esm.js +0 -1238
  59. package/dist/js/color-palette-esm.min.js +0 -2
  60. package/dist/js/color-palette.js +0 -1246
  61. package/dist/js/color-palette.min.js +0 -2
  62. package/dist/js/color-picker-element-esm.js +0 -3739
  63. package/dist/js/color-picker-element-esm.min.js +0 -2
  64. package/dist/js/color-picker-element.js +0 -3747
  65. package/dist/js/color-picker-element.min.js +0 -2
  66. package/dist/js/color-picker-esm.js +0 -3578
  67. package/dist/js/color-picker-esm.min.js +0 -2
  68. package/dist/js/color-picker.min.js +0 -2
  69. package/dist/js/color.js +0 -1175
  70. package/dist/js/color.min.js +0 -2
  71. package/src/js/color-palette.js +0 -75
  72. package/src/js/color-picker-element.js +0 -110
  73. package/src/js/color.js +0 -1107
  74. package/src/js/index.js +0 -3
  75. package/src/js/util/colorNames.js +0 -6
  76. package/src/js/util/getColorControls.js +0 -103
  77. package/src/js/util/isValidJSON.js +0 -13
  78. package/src/js/util/nonColors.js +0 -5
  79. package/src/js/util/roundPart.js +0 -9
  80. package/src/js/util/setCSSProperties.js +0 -12
  81. package/src/js/util/tabindex.js +0 -3
  82. package/src/js/util/toggleCEAttr.js +0 -70
  83. package/src/js/util/version.js +0 -6
  84. package/src/js/version.js +0 -6
  85. package/types/cp.d.ts +0 -544
  86. package/types/index.d.ts +0 -48
  87. package/types/source/source.ts +0 -5
  88. package/types/source/types.d.ts +0 -92
package/src/js/index.js DELETED
@@ -1,3 +0,0 @@
1
- import ColorPicker from './color-picker';
2
-
3
- export default ColorPicker;
@@ -1,6 +0,0 @@
1
- /**
2
- * A list of 17 color names used for WAI-ARIA compliance.
3
- * @type {string[]}
4
- */
5
- const colorNames = ['white', 'black', 'grey', 'red', 'orange', 'brown', 'gold', 'olive', 'yellow', 'lime', 'green', 'teal', 'cyan', 'blue', 'violet', 'magenta', 'pink'];
6
- export default colorNames;
@@ -1,103 +0,0 @@
1
- import ariaLabel from 'shorter-js/src/strings/ariaLabel';
2
- import ariaValueMin from 'shorter-js/src/strings/ariaValueMin';
3
- import ariaValueMax from 'shorter-js/src/strings/ariaValueMax';
4
- import createElement from 'shorter-js/src/misc/createElement';
5
- import setAttribute from 'shorter-js/src/attr/setAttribute';
6
-
7
- import tabIndex from './tabindex';
8
-
9
- /**
10
- * Returns all color controls for `ColorPicker`.
11
- *
12
- * @param {CP.ColorPicker} self the `ColorPicker` instance
13
- * @returns {HTMLElement | Element} color controls
14
- */
15
- export default function getColorControls(self) {
16
- const { format, componentLabels } = self;
17
- const {
18
- hueLabel, alphaLabel, lightnessLabel, saturationLabel,
19
- whitenessLabel, blacknessLabel,
20
- } = componentLabels;
21
-
22
- const max1 = format === 'hsl' ? 360 : 100;
23
- const max2 = format === 'hsl' ? 100 : 360;
24
- const max3 = 100;
25
-
26
- let ctrl1Label = format === 'hsl'
27
- ? `${hueLabel} & ${lightnessLabel}`
28
- : `${lightnessLabel} & ${saturationLabel}`;
29
-
30
- ctrl1Label = format === 'hwb'
31
- ? `${whitenessLabel} & ${blacknessLabel}`
32
- : ctrl1Label;
33
-
34
- const ctrl2Label = format === 'hsl'
35
- ? `${saturationLabel}`
36
- : `${hueLabel}`;
37
-
38
- const colorControls = createElement({
39
- tagName: 'div',
40
- className: `color-controls ${format}`,
41
- });
42
-
43
- const colorPointer = 'color-pointer';
44
- const colorSlider = 'color-slider';
45
-
46
- const controls = [
47
- {
48
- i: 1,
49
- c: colorPointer,
50
- l: ctrl1Label,
51
- min: 0,
52
- max: max1,
53
- },
54
- {
55
- i: 2,
56
- c: colorSlider,
57
- l: ctrl2Label,
58
- min: 0,
59
- max: max2,
60
- },
61
- {
62
- i: 3,
63
- c: colorSlider,
64
- l: alphaLabel,
65
- min: 0,
66
- max: max3,
67
- },
68
- ];
69
-
70
- controls.forEach((template) => {
71
- const {
72
- i, c, l, min, max,
73
- } = template;
74
- const control = createElement({
75
- tagName: 'div',
76
- className: 'color-control',
77
- });
78
- setAttribute(control, 'role', 'presentation');
79
-
80
- control.append(
81
- createElement({
82
- tagName: 'div',
83
- className: `visual-control visual-control${i}`,
84
- }),
85
- );
86
-
87
- const knob = createElement({
88
- tagName: 'div',
89
- className: `${c} knob`,
90
- ariaLive: 'polite',
91
- });
92
-
93
- setAttribute(knob, ariaLabel, l);
94
- setAttribute(knob, 'role', 'slider');
95
- setAttribute(knob, tabIndex, '0');
96
- setAttribute(knob, ariaValueMin, `${min}`);
97
- setAttribute(knob, ariaValueMax, `${max}`);
98
- control.append(knob);
99
- colorControls.append(control);
100
- });
101
-
102
- return colorControls;
103
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Check if a string is valid JSON string.
3
- * @param {string} str the string input
4
- * @returns {boolean} the query result
5
- */
6
- export default function isValidJSON(str) {
7
- try {
8
- JSON.parse(str);
9
- } catch (e) {
10
- return false;
11
- }
12
- return true;
13
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * A list of explicit default non-color values.
3
- */
4
- const nonColors = ['transparent', 'currentColor', 'inherit', 'revert', 'initial'];
5
- export default nonColors;
@@ -1,9 +0,0 @@
1
- /**
2
- * Round colour components, for all formats except HEX.
3
- * @param {number} v one of the colour components
4
- * @returns {number} the rounded number
5
- */
6
- export default function roundPart(v) {
7
- const floor = Math.floor(v);
8
- return v - floor < 0.5 ? floor : Math.round(v);
9
- }
@@ -1,12 +0,0 @@
1
- import ObjectKeys from 'shorter-js/src/misc/ObjectKeys';
2
-
3
- /**
4
- * Helps setting CSS variables to the color-menu.
5
- * @param {HTMLElement} element
6
- * @param {Record<string,any>} props
7
- */
8
- export default function setCSSProperties(element, props) {
9
- ObjectKeys(props).forEach((prop) => {
10
- element.style.setProperty(prop, props[prop]);
11
- });
12
- }
@@ -1,3 +0,0 @@
1
- const tabIndex = 'tabindex';
2
-
3
- export default tabIndex;
@@ -1,70 +0,0 @@
1
- import setAttribute from 'shorter-js/src/attr/setAttribute';
2
- import removeAttribute from 'shorter-js/src/attr/removeAttribute';
3
- import ObjectKeys from 'shorter-js/src/misc/ObjectKeys';
4
-
5
- import ColorPalette from '../color-palette';
6
- import colorNames from './colorNames';
7
- import colorPickerLabels from './colorPickerLabels';
8
-
9
- /**
10
- * A small utility to toggle `ColorPickerElement` attributes
11
- * when `connectedCallback` or `disconnectedCallback` methods
12
- * are called and helps the instance keep its value and settings instact.
13
- *
14
- * @param {CP.ColorPickerElement} self ColorPickerElement instance
15
- * @param {Function=} callback when `true`, attributes are added
16
- *
17
- * @example
18
- * const attributes = [
19
- * // essentials
20
- * 'value', 'format',
21
- * // presets menus
22
- * 'color-presets', 'color-keywords',
23
- * // labels
24
- * 'color-labels', 'component-labels',
25
- * ];
26
- */
27
- export default function toggleCEAttr(self, callback) {
28
- if (callback) {
29
- const { input, colorPicker } = self;
30
-
31
- const {
32
- value, format, colorPresets, colorKeywords, componentLabels, colorLabels,
33
- } = colorPicker;
34
-
35
- const { id, placeholder } = input;
36
-
37
- setAttribute(self, 'data-id', id);
38
- setAttribute(self, 'data-value', value);
39
- setAttribute(self, 'data-format', format);
40
- setAttribute(self, 'data-placeholder', placeholder);
41
-
42
- if (ObjectKeys(colorPickerLabels).some((l) => colorPickerLabels[l] !== componentLabels[l])) {
43
- setAttribute(self, 'data-component-labels', JSON.stringify(componentLabels));
44
- }
45
- if (!colorNames.every((c) => c === colorLabels[c])) {
46
- setAttribute(self, 'data-color-labels', colorNames.map((n) => colorLabels[n]).join(','));
47
- }
48
- if (colorPresets instanceof ColorPalette) {
49
- const { hue, hueSteps, lightSteps } = colorPresets;
50
- setAttribute(self, 'data-color-presets', JSON.stringify({ hue, hueSteps, lightSteps }));
51
- }
52
- if (Array.isArray(colorPresets) && colorPresets.length) {
53
- setAttribute(self, 'data-color-presets', colorPresets.join(','));
54
- }
55
- if (colorKeywords) {
56
- setAttribute(self, 'data-color-keywords', colorKeywords.join(','));
57
- }
58
- setTimeout(callback, 0);
59
- } else {
60
- // keep id
61
- // removeAttribute(self, 'data-id');
62
- removeAttribute(self, 'data-value');
63
- removeAttribute(self, 'data-format');
64
- removeAttribute(self, 'data-placeholder');
65
- removeAttribute(self, 'data-component-labels');
66
- removeAttribute(self, 'data-color-labels');
67
- removeAttribute(self, 'data-color-presets');
68
- removeAttribute(self, 'data-color-keywords');
69
- }
70
- }
@@ -1,6 +0,0 @@
1
- // @ts-ignore
2
- import { version } from '../../../package.json';
3
-
4
- const Version = version;
5
-
6
- export default Version;
package/src/js/version.js DELETED
@@ -1,6 +0,0 @@
1
- // @ts-ignore
2
- import { version } from '../../package.json';
3
-
4
- const Version = version;
5
-
6
- export default Version;