@thednp/color-picker 1.0.1 → 2.0.0-alpha2
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/LICENSE +0 -0
- package/README.md +55 -72
- package/compile.js +48 -0
- package/cypress/e2e/color-palette.cy.ts +128 -0
- package/cypress/e2e/color-picker.cy.ts +920 -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/getCEMarkup.js +29 -0
- package/cypress/fixtures/getMarkup.js +28 -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 +16 -40
- package/dist/css/color-picker.min.css +2 -2
- package/dist/css/color-picker.rtl.css +16 -40
- 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 +278 -0
- package/dist/js/color-picker.js +5 -3570
- package/dist/js/color-picker.js.map +1 -0
- package/dist/js/color-picker.mjs +2631 -0
- package/dist/js/color-picker.mjs.map +1 -0
- package/dts.config.ts +15 -0
- package/package.json +64 -74
- package/src/scss/_variables.scss +0 -1
- package/src/scss/color-picker.rtl.scss +4 -0
- package/src/scss/color-picker.scss +80 -40
- package/src/ts/colorPalette.ts +89 -0
- package/src/{js/color-picker.js → ts/index.ts} +489 -486
- 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} +57 -48
- package/src/{js/util/vHidden.js → ts/util/vHidden.ts} +0 -0
- 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/index.js
DELETED
@@ -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
|
-
}
|
package/src/js/util/nonColors.js
DELETED
package/src/js/util/roundPart.js
DELETED
@@ -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
|
-
}
|
package/src/js/util/tabindex.js
DELETED
@@ -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
|
-
}
|
package/src/js/util/version.js
DELETED