@thednp/color-picker 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +25 -14
- package/dist/css/color-picker.css +3 -6
- package/dist/css/color-picker.css.map +1 -0
- package/dist/css/color-picker.min.css +1 -2
- package/dist/css/color-picker.min.css.map +1 -0
- package/dist/css/color-picker.rtl.css +3 -6
- package/dist/css/color-picker.rtl.css.map +1 -0
- package/dist/css/color-picker.rtl.min.css +1 -2
- package/dist/css/color-picker.rtl.min.css.map +1 -0
- package/dist/js/color-picker.cjs +2 -2
- package/dist/js/color-picker.cjs.map +1 -1
- package/dist/js/color-picker.d.ts +307 -300
- package/dist/js/color-picker.js +2 -2
- package/dist/js/color-picker.js.map +1 -1
- package/dist/js/color-picker.mjs +369 -332
- package/dist/js/color-picker.mjs.map +1 -1
- package/package.json +36 -44
- package/.eslintrc.cjs +0 -199
- package/.lgtm.yml +0 -9
- package/.prettierrc.json +0 -15
- package/.stylelintrc.json +0 -236
- package/compile.cjs +0 -51
- package/dts.config.ts +0 -15
- package/src/scss/_variables.scss +0 -6
- package/src/scss/color-picker.rtl.scss +0 -27
- package/src/scss/color-picker.scss +0 -536
- package/src/ts/colorPalette.ts +0 -89
- package/src/ts/index.ts +0 -1237
- package/src/ts/interface/ColorNames.ts +0 -20
- package/src/ts/interface/colorPickerLabels.ts +0 -20
- package/src/ts/interface/colorPickerOptions.ts +0 -11
- package/src/ts/interface/paletteOptions.ts +0 -6
- package/src/ts/util/colorNames.ts +0 -21
- package/src/ts/util/colorPickerLabels.ts +0 -24
- package/src/ts/util/getColorControls.ts +0 -90
- package/src/ts/util/getColorForm.ts +0 -75
- package/src/ts/util/getColorMenu.ts +0 -83
- package/src/ts/util/isValidJSON.ts +0 -19
- package/src/ts/util/setMarkup.ts +0 -130
- package/src/ts/util/vHidden.ts +0 -2
- package/test/color-palette.test.ts +0 -137
- package/test/color-picker.test.ts +0 -705
- package/test/fixtures/colorNamesFrench.js +0 -3
- package/test/fixtures/componentLabelsFrench.js +0 -21
- package/test/fixtures/format.js +0 -3
- package/test/fixtures/getMarkup.js +0 -36
- package/test/fixtures/getRandomInt.js +0 -6
- package/test/fixtures/sampleWebcolors.js +0 -18
- package/test/fixtures/swipe.ts +0 -33
- package/test/fixtures/testSample.js +0 -8
- package/test/fixtures/write.ts +0 -37
- package/tsconfig.json +0 -47
- package/vite.config.mts +0 -27
- package/vitest.config-ui.ts +0 -26
- package/vitest.config.ts +0 -26
@@ -1,20 +0,0 @@
|
|
1
|
-
export default interface ColorNames {
|
2
|
-
white: string;
|
3
|
-
black: string;
|
4
|
-
grey: string;
|
5
|
-
red: string;
|
6
|
-
orange: string;
|
7
|
-
brown: string;
|
8
|
-
gold: string;
|
9
|
-
olive: string;
|
10
|
-
yellow: string;
|
11
|
-
lime: string;
|
12
|
-
green: string;
|
13
|
-
teal: string;
|
14
|
-
cyan: string;
|
15
|
-
blue: string;
|
16
|
-
violet: string;
|
17
|
-
magenta: string;
|
18
|
-
pink: string;
|
19
|
-
[key: string]: string;
|
20
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
export default interface ColorPickerLabels {
|
2
|
-
pickerLabel: string;
|
3
|
-
appearanceLabel: string;
|
4
|
-
valueLabel: string;
|
5
|
-
toggleLabel: string;
|
6
|
-
presetsLabel: string;
|
7
|
-
defaultsLabel: string;
|
8
|
-
formatLabel: string;
|
9
|
-
alphaLabel: string;
|
10
|
-
hexLabel: string;
|
11
|
-
hueLabel: string;
|
12
|
-
whitenessLabel: string;
|
13
|
-
blacknessLabel: string;
|
14
|
-
saturationLabel: string;
|
15
|
-
lightnessLabel: string;
|
16
|
-
redLabel: string;
|
17
|
-
greenLabel: string;
|
18
|
-
blueLabel: string;
|
19
|
-
[key: string]: string;
|
20
|
-
}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { ColorFormats } from '@thednp/color';
|
2
|
-
import ColorPickerLabels from './colorPickerLabels';
|
3
|
-
import ColorPalette from '../colorPalette';
|
4
|
-
|
5
|
-
export default interface ColorPickerOptions {
|
6
|
-
colorLabels: string | string[];
|
7
|
-
componentLabels: ColorPickerLabels;
|
8
|
-
format: ColorFormats;
|
9
|
-
colorPresets: string | string[] | ColorPalette | false;
|
10
|
-
colorKeywords: string | string[] | false;
|
11
|
-
}
|
@@ -1,21 +0,0 @@
|
|
1
|
-
/** A list of 17 color names used for WAI-ARIA compliance. */
|
2
|
-
const colorNames: string[] = [
|
3
|
-
'white',
|
4
|
-
'black',
|
5
|
-
'grey',
|
6
|
-
'red',
|
7
|
-
'orange',
|
8
|
-
'brown',
|
9
|
-
'gold',
|
10
|
-
'olive',
|
11
|
-
'yellow',
|
12
|
-
'lime',
|
13
|
-
'green',
|
14
|
-
'teal',
|
15
|
-
'cyan',
|
16
|
-
'blue',
|
17
|
-
'violet',
|
18
|
-
'magenta',
|
19
|
-
'pink',
|
20
|
-
];
|
21
|
-
export default colorNames;
|
@@ -1,24 +0,0 @@
|
|
1
|
-
import ColorPickerLabels from '../interface/colorPickerLabels';
|
2
|
-
|
3
|
-
/** The labels presented to the user. */
|
4
|
-
const colorPickerLabels: ColorPickerLabels = {
|
5
|
-
pickerLabel: 'Colour Picker',
|
6
|
-
appearanceLabel: 'Colour Appearance',
|
7
|
-
valueLabel: 'Colour Value',
|
8
|
-
toggleLabel: 'Select Colour',
|
9
|
-
presetsLabel: 'Colour Presets',
|
10
|
-
defaultsLabel: 'Colour Defaults',
|
11
|
-
formatLabel: 'Format',
|
12
|
-
alphaLabel: 'Alpha',
|
13
|
-
hexLabel: 'Hexadecimal',
|
14
|
-
hueLabel: 'Hue',
|
15
|
-
whitenessLabel: 'Whiteness',
|
16
|
-
blacknessLabel: 'Blackness',
|
17
|
-
saturationLabel: 'Saturation',
|
18
|
-
lightnessLabel: 'Lightness',
|
19
|
-
redLabel: 'Red',
|
20
|
-
greenLabel: 'Green',
|
21
|
-
blueLabel: 'Blue',
|
22
|
-
};
|
23
|
-
|
24
|
-
export default colorPickerLabels;
|
@@ -1,90 +0,0 @@
|
|
1
|
-
import { createElement } from '@thednp/shorty';
|
2
|
-
|
3
|
-
import ColorPicker from '..';
|
4
|
-
|
5
|
-
/**
|
6
|
-
* Returns all color controls for `ColorPicker`.
|
7
|
-
*
|
8
|
-
* @param self the `ColorPicker` instance
|
9
|
-
* @returns color controls
|
10
|
-
*/
|
11
|
-
const getColorControls = (self: ColorPicker): HTMLElement => {
|
12
|
-
const { format, componentLabels } = self;
|
13
|
-
const { hueLabel, alphaLabel, lightnessLabel, saturationLabel, whitenessLabel, blacknessLabel } = componentLabels;
|
14
|
-
|
15
|
-
const max1 = format === 'hsl' ? 360 : 100;
|
16
|
-
const max2 = format === 'hsl' ? 100 : 360;
|
17
|
-
const max3 = 100;
|
18
|
-
|
19
|
-
let ctrl1Label = format === 'hsl' ? `${hueLabel} & ${lightnessLabel}` : `${lightnessLabel} & ${saturationLabel}`;
|
20
|
-
|
21
|
-
ctrl1Label = format === 'hwb' ? `${whitenessLabel} & ${blacknessLabel}` : ctrl1Label;
|
22
|
-
|
23
|
-
const ctrl2Label = format === 'hsl' ? `${saturationLabel}` : `${hueLabel}`;
|
24
|
-
|
25
|
-
const colorControls = createElement({
|
26
|
-
tagName: 'div',
|
27
|
-
className: `color-controls ${format}`,
|
28
|
-
}) as HTMLElement;
|
29
|
-
|
30
|
-
const colorPointer = 'color-pointer';
|
31
|
-
const colorSlider = 'color-slider';
|
32
|
-
|
33
|
-
const controls = [
|
34
|
-
{
|
35
|
-
i: 1,
|
36
|
-
c: colorPointer,
|
37
|
-
l: ctrl1Label,
|
38
|
-
min: 0,
|
39
|
-
max: max1,
|
40
|
-
},
|
41
|
-
{
|
42
|
-
i: 2,
|
43
|
-
c: colorSlider,
|
44
|
-
l: ctrl2Label,
|
45
|
-
min: 0,
|
46
|
-
max: max2,
|
47
|
-
},
|
48
|
-
{
|
49
|
-
i: 3,
|
50
|
-
c: colorSlider,
|
51
|
-
l: alphaLabel,
|
52
|
-
min: 0,
|
53
|
-
max: max3,
|
54
|
-
},
|
55
|
-
];
|
56
|
-
|
57
|
-
controls.forEach(template => {
|
58
|
-
const { i, c, l, min, max } = template;
|
59
|
-
const control = createElement({
|
60
|
-
tagName: 'div',
|
61
|
-
className: 'color-control',
|
62
|
-
role: 'presentation',
|
63
|
-
}) as HTMLElement;
|
64
|
-
|
65
|
-
control.append(
|
66
|
-
createElement({
|
67
|
-
tagName: 'div',
|
68
|
-
className: `visual-control visual-control${i}`,
|
69
|
-
}) as HTMLElement,
|
70
|
-
);
|
71
|
-
|
72
|
-
const knob = createElement({
|
73
|
-
tagName: 'div',
|
74
|
-
className: `${c} knob`,
|
75
|
-
ariaLive: 'polite',
|
76
|
-
ariaLabel: l,
|
77
|
-
role: 'slider',
|
78
|
-
tabIndex: 0,
|
79
|
-
ariaValueMin: `${min}`,
|
80
|
-
ariaValueMax: `${max}`,
|
81
|
-
}) as HTMLElement;
|
82
|
-
|
83
|
-
control.append(knob);
|
84
|
-
colorControls.append(control);
|
85
|
-
});
|
86
|
-
|
87
|
-
return colorControls;
|
88
|
-
};
|
89
|
-
|
90
|
-
export default getColorControls;
|
@@ -1,75 +0,0 @@
|
|
1
|
-
import { createElement, setAttribute, ObjectAssign, toUpperCase } from '@thednp/shorty';
|
2
|
-
|
3
|
-
import vHidden from './vHidden';
|
4
|
-
import ColorPicker from '../index';
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Returns the color form for `ColorPicker`.
|
8
|
-
*
|
9
|
-
* @param self the `ColorPicker` instance
|
10
|
-
* @returns a new `<div>` element with color component `<input>`
|
11
|
-
*/
|
12
|
-
const getColorForm = (self: ColorPicker): HTMLElement => {
|
13
|
-
const { format, id, componentLabels } = self;
|
14
|
-
const colorForm = createElement({
|
15
|
-
tagName: 'div',
|
16
|
-
className: `color-form ${format}`,
|
17
|
-
}) as HTMLElement;
|
18
|
-
|
19
|
-
let components = ['hex'];
|
20
|
-
if (format === 'rgb') components = ['red', 'green', 'blue', 'alpha'];
|
21
|
-
else if (format === 'hsl') components = ['hue', 'saturation', 'lightness', 'alpha'];
|
22
|
-
else if (format === 'hwb') components = ['hue', 'whiteness', 'blackness', 'alpha'];
|
23
|
-
|
24
|
-
components.forEach((c: string): void => {
|
25
|
-
const [C] = format === 'hex' ? ['#'] : toUpperCase(c).split('');
|
26
|
-
const cID = `color_${format}_${c}_${id}`;
|
27
|
-
const formatLabel = componentLabels[`${c}Label`];
|
28
|
-
const cInputLabel = createElement({ tagName: 'label' }) as HTMLElement;
|
29
|
-
setAttribute(cInputLabel, 'for', cID);
|
30
|
-
cInputLabel.append(
|
31
|
-
createElement({
|
32
|
-
tagName: 'span',
|
33
|
-
ariaHidden: 'true',
|
34
|
-
innerText: `${C}:`,
|
35
|
-
}) as HTMLElement,
|
36
|
-
createElement({
|
37
|
-
tagName: 'span',
|
38
|
-
className: vHidden,
|
39
|
-
innerText: formatLabel,
|
40
|
-
}) as HTMLElement,
|
41
|
-
);
|
42
|
-
const cInput = createElement({
|
43
|
-
tagName: 'input',
|
44
|
-
id: cID,
|
45
|
-
// name: cID, - prevent saving the value to a form
|
46
|
-
type: format === 'hex' ? 'text' : 'number',
|
47
|
-
value: c === 'alpha' ? '100' : '0',
|
48
|
-
className: `color-input ${c}`,
|
49
|
-
autocomplete: 'off',
|
50
|
-
spellcheck: false,
|
51
|
-
} as Partial<HTMLInputElement>) as HTMLInputElement;
|
52
|
-
|
53
|
-
// alpha
|
54
|
-
let max = '100';
|
55
|
-
let step = '1';
|
56
|
-
if (c !== 'alpha') {
|
57
|
-
if (format === 'rgb') {
|
58
|
-
max = '255';
|
59
|
-
step = '1';
|
60
|
-
} else if (c === 'hue') {
|
61
|
-
max = '360';
|
62
|
-
step = '1';
|
63
|
-
}
|
64
|
-
}
|
65
|
-
ObjectAssign(cInput, {
|
66
|
-
min: '0',
|
67
|
-
max,
|
68
|
-
step,
|
69
|
-
});
|
70
|
-
colorForm.append(cInputLabel, cInput);
|
71
|
-
});
|
72
|
-
return colorForm;
|
73
|
-
};
|
74
|
-
|
75
|
-
export default getColorForm;
|
@@ -1,83 +0,0 @@
|
|
1
|
-
import { setAttribute, getAttribute, createElement, setElementStyle } from '@thednp/shorty';
|
2
|
-
|
3
|
-
import Color from '@thednp/color';
|
4
|
-
import ColorPalette from '../colorPalette';
|
5
|
-
import ColorPicker from '../index';
|
6
|
-
|
7
|
-
/**
|
8
|
-
* Returns a color-defaults with given values and class.
|
9
|
-
*/
|
10
|
-
const getColorMenu = (self: ColorPicker, colorsSource: ColorPalette | string[], menuClass: string): HTMLElement => {
|
11
|
-
const { input, format, componentLabels } = self;
|
12
|
-
const { defaultsLabel, presetsLabel } = componentLabels;
|
13
|
-
const isOptionsMenu = menuClass === 'color-options';
|
14
|
-
const isPalette = colorsSource instanceof ColorPalette;
|
15
|
-
const menuLabel = isOptionsMenu ? presetsLabel : defaultsLabel;
|
16
|
-
const colorsArray = isPalette ? colorsSource.colors : colorsSource;
|
17
|
-
const colorsCount = colorsArray.length;
|
18
|
-
const { lightSteps } = isPalette ? colorsSource : { lightSteps: null };
|
19
|
-
const fit = lightSteps || [9, 10].find(x => colorsCount >= x * 2 && !(colorsCount % x)) || 5;
|
20
|
-
const isMultiLine = isOptionsMenu && colorsCount > fit;
|
21
|
-
let rowCountHover = 2;
|
22
|
-
rowCountHover = isMultiLine && colorsCount > fit * 2 ? 3 : rowCountHover;
|
23
|
-
rowCountHover = isMultiLine && colorsCount > fit * 3 ? 4 : rowCountHover;
|
24
|
-
rowCountHover = isMultiLine && colorsCount > fit * 4 ? 5 : rowCountHover;
|
25
|
-
const rowCount = rowCountHover - (colorsCount <= fit * 3 ? 1 : 2);
|
26
|
-
const isScrollable = isMultiLine && colorsCount > rowCount * fit;
|
27
|
-
let finalClass = menuClass;
|
28
|
-
finalClass += isScrollable ? ' scrollable' : '';
|
29
|
-
finalClass += isMultiLine ? ' multiline' : '';
|
30
|
-
const gap = isMultiLine ? '1px' : '0.25rem';
|
31
|
-
let optionSize = isMultiLine ? 1.75 : 2;
|
32
|
-
optionSize = fit > 5 && isMultiLine ? 1.5 : optionSize;
|
33
|
-
const menuHeight = `${rowCount * optionSize}rem`;
|
34
|
-
const menuHeightHover = `calc(${rowCountHover} * ${optionSize}rem + ${rowCountHover - 1} * ${gap})`;
|
35
|
-
|
36
|
-
// <UL> is an `HTMLElement`
|
37
|
-
const menu = createElement({
|
38
|
-
tagName: 'ul',
|
39
|
-
className: finalClass,
|
40
|
-
role: 'listbox',
|
41
|
-
ariaLabel: menuLabel,
|
42
|
-
}) as HTMLElement;
|
43
|
-
|
44
|
-
if (isScrollable) {
|
45
|
-
setElementStyle(menu, {
|
46
|
-
'--grid-item-size': `${optionSize}rem`,
|
47
|
-
'--grid-fit': `${fit}`,
|
48
|
-
'--grid-gap': gap,
|
49
|
-
'--grid-height': menuHeight,
|
50
|
-
'--grid-hover-height': menuHeightHover,
|
51
|
-
});
|
52
|
-
}
|
53
|
-
|
54
|
-
colorsArray.forEach(x => {
|
55
|
-
let [value, label] = typeof x === 'string' ? x.trim().split(':') : [];
|
56
|
-
if (x instanceof Color) {
|
57
|
-
value = x.toHexString();
|
58
|
-
label = value;
|
59
|
-
}
|
60
|
-
const color = new Color(x instanceof Color ? x : value, format);
|
61
|
-
const isActive = color.toString() === getAttribute(input, 'value');
|
62
|
-
const active = isActive ? ' active' : '';
|
63
|
-
|
64
|
-
const option = createElement({
|
65
|
-
tagName: 'li',
|
66
|
-
className: `color-option${active}`,
|
67
|
-
innerText: `${label || value}`,
|
68
|
-
tabIndex: 0,
|
69
|
-
role: 'option',
|
70
|
-
ariaSelected: isActive ? 'true' : 'false',
|
71
|
-
}) as HTMLElement;
|
72
|
-
setAttribute(option, 'data-value', `${value}`);
|
73
|
-
|
74
|
-
if (isOptionsMenu) {
|
75
|
-
setElementStyle(option, { backgroundColor: value });
|
76
|
-
}
|
77
|
-
|
78
|
-
menu.append(option);
|
79
|
-
});
|
80
|
-
return menu;
|
81
|
-
};
|
82
|
-
|
83
|
-
export default getColorMenu;
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import { isString } from '@thednp/shorty';
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Check if a string is valid JSON string.
|
5
|
-
*
|
6
|
-
* @param str the string input
|
7
|
-
* @returns the query result
|
8
|
-
*/
|
9
|
-
const isValidJSON = (str: unknown): str is string => {
|
10
|
-
if (!isString(str)) return false;
|
11
|
-
try {
|
12
|
-
JSON.parse(str);
|
13
|
-
} catch (e) {
|
14
|
-
return false;
|
15
|
-
}
|
16
|
-
return true;
|
17
|
-
};
|
18
|
-
|
19
|
-
export default isValidJSON;
|
package/src/ts/util/setMarkup.ts
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
getAttribute,
|
3
|
-
setAttribute,
|
4
|
-
toUpperCase,
|
5
|
-
ariaHidden,
|
6
|
-
tabindex,
|
7
|
-
createElement,
|
8
|
-
createElementNS,
|
9
|
-
} from '@thednp/shorty';
|
10
|
-
|
11
|
-
import Color from '@thednp/color';
|
12
|
-
|
13
|
-
import getColorForm from './getColorForm';
|
14
|
-
import getColorControls from './getColorControls';
|
15
|
-
import getColorMenu from './getColorMenu';
|
16
|
-
import vHidden from './vHidden';
|
17
|
-
|
18
|
-
import ColorPicker from '../index';
|
19
|
-
|
20
|
-
/**
|
21
|
-
* Generate HTML markup and update instance properties.
|
22
|
-
*
|
23
|
-
* @param self
|
24
|
-
*/
|
25
|
-
const setMarkup = (self: ColorPicker) => {
|
26
|
-
const { input, parent, format, id, componentLabels, colorKeywords, colorPresets } = self;
|
27
|
-
const colorValue = getAttribute(input, 'value') || '#fff';
|
28
|
-
const { nonColors } = Color;
|
29
|
-
|
30
|
-
const { toggleLabel, pickerLabel, formatLabel, hexLabel } = componentLabels;
|
31
|
-
|
32
|
-
// update color
|
33
|
-
const color = nonColors.includes(colorValue) ? '#fff' : colorValue;
|
34
|
-
self.color = new Color(color, format);
|
35
|
-
|
36
|
-
// set initial controls dimensions
|
37
|
-
const formatString = format === 'hex' ? hexLabel : toUpperCase(format);
|
38
|
-
|
39
|
-
const pickerBtn = createElement<HTMLButtonElement>({
|
40
|
-
id: `picker-btn-${id}`,
|
41
|
-
tagName: 'button',
|
42
|
-
type: 'button',
|
43
|
-
className: 'picker-toggle btn-appearance',
|
44
|
-
ariaExpanded: 'false',
|
45
|
-
ariaHasPopup: 'true',
|
46
|
-
}) as HTMLButtonElement;
|
47
|
-
|
48
|
-
pickerBtn.append(
|
49
|
-
createElement({
|
50
|
-
tagName: 'span',
|
51
|
-
className: vHidden,
|
52
|
-
innerText: `${pickerLabel}. ${formatLabel}: ${formatString}`,
|
53
|
-
}) as HTMLElement,
|
54
|
-
);
|
55
|
-
|
56
|
-
const pickerDropdown = createElement({
|
57
|
-
tagName: 'div',
|
58
|
-
className: 'color-dropdown picker',
|
59
|
-
role: 'group',
|
60
|
-
ariaLabelledBy: `picker-btn-${id}`,
|
61
|
-
} as Partial<HTMLElement> & { ariaLabelledBy: string }) as HTMLElement;
|
62
|
-
|
63
|
-
const colorControls = getColorControls(self);
|
64
|
-
const colorForm = getColorForm(self);
|
65
|
-
|
66
|
-
pickerDropdown.append(colorControls, colorForm);
|
67
|
-
input.before(pickerBtn);
|
68
|
-
parent.append(pickerDropdown);
|
69
|
-
|
70
|
-
// set colour key menu template
|
71
|
-
if (colorKeywords || colorPresets) {
|
72
|
-
const presetsDropdown = createElement({
|
73
|
-
tagName: 'div',
|
74
|
-
className: 'color-dropdown scrollable menu',
|
75
|
-
}) as HTMLElement;
|
76
|
-
|
77
|
-
// color presets
|
78
|
-
if (colorPresets) {
|
79
|
-
presetsDropdown.append(getColorMenu(self, colorPresets, 'color-options'));
|
80
|
-
}
|
81
|
-
|
82
|
-
// explicit defaults [reset, initial, inherit, transparent, currentColor]
|
83
|
-
// also custom defaults [default: #069, complementary: #930]
|
84
|
-
if (colorKeywords && colorKeywords.length) {
|
85
|
-
presetsDropdown.append(getColorMenu(self, colorKeywords, 'color-defaults'));
|
86
|
-
}
|
87
|
-
|
88
|
-
const presetsBtn = createElement<HTMLButtonElement>({
|
89
|
-
tagName: 'button',
|
90
|
-
type: 'button',
|
91
|
-
className: 'menu-toggle btn-appearance',
|
92
|
-
tabIndex: -1,
|
93
|
-
ariaExpanded: 'false',
|
94
|
-
ariaHasPopup: 'true',
|
95
|
-
}) as HTMLButtonElement;
|
96
|
-
|
97
|
-
const xmlns = encodeURI('http://www.w3.org/2000/svg');
|
98
|
-
const presetsIcon = createElementNS(xmlns, {
|
99
|
-
tagName: 'svg',
|
100
|
-
}) as HTMLElement;
|
101
|
-
setAttribute(presetsIcon, 'xmlns', xmlns);
|
102
|
-
setAttribute(presetsIcon, 'viewBox', '0 0 512 512');
|
103
|
-
setAttribute(presetsIcon, ariaHidden, 'true');
|
104
|
-
|
105
|
-
const path = createElementNS(xmlns, {
|
106
|
-
tagName: 'path',
|
107
|
-
}) as HTMLElement;
|
108
|
-
setAttribute(path, 'd', 'M98,158l157,156L411,158l27,27L255,368L71,185L98,158z');
|
109
|
-
setAttribute(path, 'fill', '#fff');
|
110
|
-
presetsIcon.append(path);
|
111
|
-
presetsBtn.append(
|
112
|
-
createElement({
|
113
|
-
tagName: 'span',
|
114
|
-
className: vHidden,
|
115
|
-
innerText: `${toggleLabel}`,
|
116
|
-
}) as HTMLElement,
|
117
|
-
presetsIcon,
|
118
|
-
);
|
119
|
-
|
120
|
-
parent.append(presetsBtn, presetsDropdown);
|
121
|
-
}
|
122
|
-
|
123
|
-
// solve non-colors after settings save
|
124
|
-
if (colorKeywords && nonColors.includes(colorValue)) {
|
125
|
-
self.value = colorValue;
|
126
|
-
}
|
127
|
-
setAttribute(input, tabindex, '-1');
|
128
|
-
};
|
129
|
-
|
130
|
-
export default setMarkup;
|
package/src/ts/util/vHidden.ts
DELETED
@@ -1,137 +0,0 @@
|
|
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
|
-
});
|