@thednp/color-picker 1.0.1 → 2.0.0-alpha1

Sign up to get free protection for your applications and to get access to all the features.
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 +54 -72
  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 +14 -38
  26. package/dist/css/color-picker.min.css +2 -2
  27. package/dist/css/color-picker.rtl.css +14 -38
  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 -3570
  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 +74 -38
  41. package/src/ts/colorPalette.ts +89 -0
  42. package/src/{js/color-picker.js → ts/index.ts} +489 -486
  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 -1164
  57. package/dist/js/color-esm.min.js +0 -2
  58. package/dist/js/color-palette-esm.js +0 -1235
  59. package/dist/js/color-palette-esm.min.js +0 -2
  60. package/dist/js/color-palette.js +0 -1243
  61. package/dist/js/color-palette.min.js +0 -2
  62. package/dist/js/color-picker-element-esm.js +0 -3718
  63. package/dist/js/color-picker-element-esm.min.js +0 -2
  64. package/dist/js/color-picker-element.js +0 -3726
  65. package/dist/js/color-picker-element.min.js +0 -2
  66. package/dist/js/color-picker-esm.js +0 -3565
  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 -1172
  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 -107
  73. package/src/js/color.js +0 -1104
  74. package/src/js/index.js +0 -8
  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 -5
  84. package/src/js/version.js +0 -5
  85. package/types/cp.d.ts +0 -558
  86. package/types/index.d.ts +0 -44
  87. package/types/source/source.ts +0 -4
  88. package/types/source/types.d.ts +0 -92
@@ -0,0 +1,20 @@
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
+ }
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,6 @@
1
+ export default interface PaletteOptions {
2
+ hue: number;
3
+ hueSteps: number;
4
+ lightSteps: number;
5
+ saturation: number;
6
+ }
@@ -0,0 +1,21 @@
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,5 +1,7 @@
1
- /** @type {Record<string, string>} */
2
- const colorPickerLabels = {
1
+ import ColorPickerLabels from '../interface/colorPickerLabels';
2
+
3
+ /** The labels presented to the user. */
4
+ const colorPickerLabels: ColorPickerLabels = {
3
5
  pickerLabel: 'Colour Picker',
4
6
  appearanceLabel: 'Colour Appearance',
5
7
  valueLabel: 'Colour Value',
@@ -0,0 +1,90 @@
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,37 +1,43 @@
1
- import createElement from 'shorter-js/src/misc/createElement';
2
- import setAttribute from 'shorter-js/src/attr/setAttribute';
3
- import ObjectAssign from 'shorter-js/src/misc/ObjectAssign';
4
- import toUpperCase from 'shorter-js/src/misc/toUpperCase';
1
+ import { createElement, setAttribute, ObjectAssign, toUpperCase } from '@thednp/shorty';
5
2
 
6
3
  import vHidden from './vHidden';
4
+ import ColorPicker from '../index';
7
5
 
8
6
  /**
9
7
  * Returns the color form for `ColorPicker`.
10
8
  *
11
- * @param {CP.ColorPicker} self the `ColorPicker` instance
12
- * @returns {HTMLElement | Element} a new `<div>` element with color component `<input>`
9
+ * @param self the `ColorPicker` instance
10
+ * @returns a new `<div>` element with color component `<input>`
13
11
  */
14
- export default function getColorForm(self) {
12
+ const getColorForm = (self: ColorPicker): HTMLElement => {
15
13
  const { format, id, componentLabels } = self;
16
14
  const colorForm = createElement({
17
15
  tagName: 'div',
18
16
  className: `color-form ${format}`,
19
- });
17
+ }) as HTMLElement;
20
18
 
21
19
  let components = ['hex'];
22
20
  if (format === 'rgb') components = ['red', 'green', 'blue', 'alpha'];
23
21
  else if (format === 'hsl') components = ['hue', 'saturation', 'lightness', 'alpha'];
24
22
  else if (format === 'hwb') components = ['hue', 'whiteness', 'blackness', 'alpha'];
25
23
 
26
- components.forEach((c) => {
24
+ components.forEach((c: string): void => {
27
25
  const [C] = format === 'hex' ? ['#'] : toUpperCase(c).split('');
28
26
  const cID = `color_${format}_${c}_${id}`;
29
27
  const formatLabel = componentLabels[`${c}Label`];
30
- const cInputLabel = createElement({ tagName: 'label' });
28
+ const cInputLabel = createElement({ tagName: 'label' }) as HTMLElement;
31
29
  setAttribute(cInputLabel, 'for', cID);
32
30
  cInputLabel.append(
33
- createElement({ tagName: 'span', ariaHidden: 'true', innerText: `${C}:` }),
34
- createElement({ tagName: 'span', className: vHidden, innerText: formatLabel }),
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,
35
41
  );
36
42
  const cInput = createElement({
37
43
  tagName: 'input',
@@ -40,18 +46,20 @@ export default function getColorForm(self) {
40
46
  type: format === 'hex' ? 'text' : 'number',
41
47
  value: c === 'alpha' ? '100' : '0',
42
48
  className: `color-input ${c}`,
43
- });
44
- setAttribute(cInput, 'autocomplete', 'off');
45
- setAttribute(cInput, 'spellcheck', 'false');
49
+ autocomplete: 'off',
50
+ spellcheck: false,
51
+ } as Partial<HTMLInputElement>) as HTMLInputElement;
46
52
 
47
53
  // alpha
48
54
  let max = '100';
49
55
  let step = '1';
50
56
  if (c !== 'alpha') {
51
57
  if (format === 'rgb') {
52
- max = '255'; step = '1';
58
+ max = '255';
59
+ step = '1';
53
60
  } else if (c === 'hue') {
54
- max = '360'; step = '1';
61
+ max = '360';
62
+ step = '1';
55
63
  }
56
64
  }
57
65
  ObjectAssign(cInput, {
@@ -62,4 +70,6 @@ export default function getColorForm(self) {
62
70
  colorForm.append(cInputLabel, cInput);
63
71
  });
64
72
  return colorForm;
65
- }
73
+ };
74
+
75
+ export default getColorForm;
@@ -1,23 +1,13 @@
1
- import ariaLabel from 'shorter-js/src/strings/ariaLabel';
2
- import ariaSelected from 'shorter-js/src/strings/ariaSelected';
3
- import setAttribute from 'shorter-js/src/attr/setAttribute';
4
- import getAttribute from 'shorter-js/src/attr/getAttribute';
5
- import createElement from 'shorter-js/src/misc/createElement';
6
- import setElementStyle from 'shorter-js/src/misc/setElementStyle';
1
+ import { setAttribute, getAttribute, createElement, setElementStyle } from '@thednp/shorty';
7
2
 
8
- import setCSSProperties from './setCSSProperties';
9
- import tabIndex from './tabindex';
10
- import Color from '../color';
11
- import ColorPalette from '../color-palette';
3
+ import Color from '@thednp/color';
4
+ import ColorPalette from '../colorPalette';
5
+ import ColorPicker from '../index';
12
6
 
13
7
  /**
14
8
  * Returns a color-defaults with given values and class.
15
- * @param {CP.ColorPicker} self
16
- * @param {CP.ColorPalette | string[]} colorsSource
17
- * @param {string} menuClass
18
- * @returns {HTMLElement | Element}
19
9
  */
20
- export default function getColorMenu(self, colorsSource, menuClass) {
10
+ const getColorMenu = (self: ColorPicker, colorsSource: ColorPalette | string[], menuClass: string): HTMLElement => {
21
11
  const { input, format, componentLabels } = self;
22
12
  const { defaultsLabel, presetsLabel } = componentLabels;
23
13
  const isOptionsMenu = menuClass === 'color-options';
@@ -26,7 +16,7 @@ export default function getColorMenu(self, colorsSource, menuClass) {
26
16
  const colorsArray = isPalette ? colorsSource.colors : colorsSource;
27
17
  const colorsCount = colorsArray.length;
28
18
  const { lightSteps } = isPalette ? colorsSource : { lightSteps: null };
29
- const fit = lightSteps || [9, 10].find((x) => colorsCount >= x * 2 && !(colorsCount % x)) || 5;
19
+ const fit = lightSteps || [9, 10].find(x => colorsCount >= x * 2 && !(colorsCount % x)) || 5;
30
20
  const isMultiLine = isOptionsMenu && colorsCount > fit;
31
21
  let rowCountHover = 2;
32
22
  rowCountHover = isMultiLine && colorsCount > fit * 2 ? 3 : rowCountHover;
@@ -42,26 +32,26 @@ export default function getColorMenu(self, colorsSource, menuClass) {
42
32
  optionSize = fit > 5 && isMultiLine ? 1.5 : optionSize;
43
33
  const menuHeight = `${rowCount * optionSize}rem`;
44
34
  const menuHeightHover = `calc(${rowCountHover} * ${optionSize}rem + ${rowCountHover - 1} * ${gap})`;
45
- /** @type {HTMLUListElement} */
46
- // @ts-ignore -- <UL> is an `HTMLElement`
35
+
36
+ // <UL> is an `HTMLElement`
47
37
  const menu = createElement({
48
38
  tagName: 'ul',
49
39
  className: finalClass,
50
- });
51
- setAttribute(menu, 'role', 'listbox');
52
- setAttribute(menu, ariaLabel, menuLabel);
40
+ role: 'listbox',
41
+ ariaLabel: menuLabel,
42
+ }) as HTMLElement;
53
43
 
54
44
  if (isScrollable) {
55
- setCSSProperties(menu, {
45
+ setElementStyle(menu, {
56
46
  '--grid-item-size': `${optionSize}rem`,
57
- '--grid-fit': fit,
47
+ '--grid-fit': `${fit}`,
58
48
  '--grid-gap': gap,
59
49
  '--grid-height': menuHeight,
60
50
  '--grid-hover-height': menuHeightHover,
61
51
  });
62
52
  }
63
53
 
64
- colorsArray.forEach((x) => {
54
+ colorsArray.forEach(x => {
65
55
  let [value, label] = typeof x === 'string' ? x.trim().split(':') : [];
66
56
  if (x instanceof Color) {
67
57
  value = x.toHexString();
@@ -75,12 +65,11 @@ export default function getColorMenu(self, colorsSource, menuClass) {
75
65
  tagName: 'li',
76
66
  className: `color-option${active}`,
77
67
  innerText: `${label || value}`,
78
- });
79
-
80
- setAttribute(option, tabIndex, '0');
68
+ tabIndex: 0,
69
+ role: 'option',
70
+ ariaSelected: isActive ? 'true' : 'false',
71
+ }) as HTMLElement;
81
72
  setAttribute(option, 'data-value', `${value}`);
82
- setAttribute(option, 'role', 'option');
83
- setAttribute(option, ariaSelected, isActive ? 'true' : 'false');
84
73
 
85
74
  if (isOptionsMenu) {
86
75
  setElementStyle(option, { backgroundColor: value });
@@ -89,4 +78,6 @@ export default function getColorMenu(self, colorsSource, menuClass) {
89
78
  menu.append(option);
90
79
  });
91
80
  return menu;
92
- }
81
+ };
82
+
83
+ export default getColorMenu;
@@ -0,0 +1,19 @@
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;
@@ -1,36 +1,33 @@
1
- import getAttribute from 'shorter-js/src/attr/getAttribute';
2
- import setAttribute from 'shorter-js/src/attr/setAttribute';
3
- import toUpperCase from 'shorter-js/src/misc/toUpperCase';
4
- // import ariaLabel from 'shorter-js/src/strings/ariaLabel';
5
- import ariaExpanded from 'shorter-js/src/strings/ariaExpanded';
6
- import ariaHasPopup from 'shorter-js/src/strings/ariaHasPopup';
7
- import ariaHidden from 'shorter-js/src/strings/ariaHidden';
8
- import ariaLabelledBy from 'shorter-js/src/strings/ariaLabelledBy';
9
- import createElement from 'shorter-js/src/misc/createElement';
10
- import createElementNS from 'shorter-js/src/misc/createElementNS';
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';
11
12
 
12
13
  import getColorForm from './getColorForm';
13
14
  import getColorControls from './getColorControls';
14
15
  import getColorMenu from './getColorMenu';
15
- import nonColors from './nonColors';
16
16
  import vHidden from './vHidden';
17
- import tabIndex from './tabindex';
18
17
 
19
- import Color from '../color';
18
+ import ColorPicker from '../index';
20
19
 
21
20
  /**
22
- * Generate HTML markup and update instance properties.
23
- * @param {CP.ColorPicker} self
24
- */
25
- export default function setMarkup(self) {
26
- const {
27
- input, parent, format, id, componentLabels, colorKeywords, colorPresets,
28
- } = self;
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;
29
27
  const colorValue = getAttribute(input, 'value') || '#fff';
28
+ const { nonColors } = Color;
30
29
 
31
- const {
32
- toggleLabel, pickerLabel, formatLabel, hexLabel,
33
- } = componentLabels;
30
+ const { toggleLabel, pickerLabel, formatLabel, hexLabel } = componentLabels;
34
31
 
35
32
  // update color
36
33
  const color = nonColors.includes(colorValue) ? '#fff' : colorValue;
@@ -43,21 +40,24 @@ export default function setMarkup(self) {
43
40
  id: `picker-btn-${id}`,
44
41
  tagName: 'button',
45
42
  className: 'picker-toggle btn-appearance',
46
- });
47
- setAttribute(pickerBtn, ariaExpanded, 'false');
48
- setAttribute(pickerBtn, ariaHasPopup, 'true');
49
- pickerBtn.append(createElement({
50
- tagName: 'span',
51
- className: vHidden,
52
- innerText: `${pickerLabel}. ${formatLabel}: ${formatString}`,
53
- }));
43
+ ariaExpanded: 'false',
44
+ ariaHasPopup: 'true',
45
+ }) as HTMLElement;
46
+
47
+ pickerBtn.append(
48
+ createElement({
49
+ tagName: 'span',
50
+ className: vHidden,
51
+ innerText: `${pickerLabel}. ${formatLabel}: ${formatString}`,
52
+ }) as HTMLElement,
53
+ );
54
54
 
55
55
  const pickerDropdown = createElement({
56
56
  tagName: 'div',
57
57
  className: 'color-dropdown picker',
58
- });
59
- setAttribute(pickerDropdown, ariaLabelledBy, `picker-btn-${id}`);
60
- setAttribute(pickerDropdown, 'role', 'group');
58
+ role: 'group',
59
+ ariaLabelledBy: `picker-btn-${id}`,
60
+ } as Partial<HTMLElement> & { ariaLabelledBy: string }) as HTMLElement;
61
61
 
62
62
  const colorControls = getColorControls(self);
63
63
  const colorForm = getColorForm(self);
@@ -71,7 +71,7 @@ export default function setMarkup(self) {
71
71
  const presetsDropdown = createElement({
72
72
  tagName: 'div',
73
73
  className: 'color-dropdown scrollable menu',
74
- });
74
+ }) as HTMLElement;
75
75
 
76
76
  // color presets
77
77
  if (colorPresets) {
@@ -87,26 +87,33 @@ export default function setMarkup(self) {
87
87
  const presetsBtn = createElement({
88
88
  tagName: 'button',
89
89
  className: 'menu-toggle btn-appearance',
90
- });
91
- setAttribute(presetsBtn, tabIndex, '-1');
92
- setAttribute(presetsBtn, ariaExpanded, 'false');
93
- setAttribute(presetsBtn, ariaHasPopup, 'true');
90
+ tabIndex: -1,
91
+ ariaExpanded: 'false',
92
+ ariaHasPopup: 'true',
93
+ }) as HTMLElement;
94
94
 
95
95
  const xmlns = encodeURI('http://www.w3.org/2000/svg');
96
- const presetsIcon = createElementNS(xmlns, { tagName: 'svg' });
96
+ const presetsIcon = createElementNS(xmlns, {
97
+ tagName: 'svg',
98
+ }) as HTMLElement;
97
99
  setAttribute(presetsIcon, 'xmlns', xmlns);
98
100
  setAttribute(presetsIcon, 'viewBox', '0 0 512 512');
99
101
  setAttribute(presetsIcon, ariaHidden, 'true');
100
102
 
101
- const path = createElementNS(xmlns, { tagName: 'path' });
103
+ const path = createElementNS(xmlns, {
104
+ tagName: 'path',
105
+ }) as HTMLElement;
102
106
  setAttribute(path, 'd', 'M98,158l157,156L411,158l27,27L255,368L71,185L98,158z');
103
107
  setAttribute(path, 'fill', '#fff');
104
108
  presetsIcon.append(path);
105
- presetsBtn.append(createElement({
106
- tagName: 'span',
107
- className: vHidden,
108
- innerText: `${toggleLabel}`,
109
- }), presetsIcon);
109
+ presetsBtn.append(
110
+ createElement({
111
+ tagName: 'span',
112
+ className: vHidden,
113
+ innerText: `${toggleLabel}`,
114
+ }) as HTMLElement,
115
+ presetsIcon,
116
+ );
110
117
 
111
118
  parent.append(presetsBtn, presetsDropdown);
112
119
  }
@@ -115,5 +122,7 @@ export default function setMarkup(self) {
115
122
  if (colorKeywords && nonColors.includes(colorValue)) {
116
123
  self.value = colorValue;
117
124
  }
118
- setAttribute(input, tabIndex, '-1');
119
- }
125
+ setAttribute(input, tabindex, '-1');
126
+ };
127
+
128
+ export default setMarkup;
File without changes
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ // https://janessagarrow.com/blog/typescript-and-esbuild/
3
+ "compilerOptions": {
4
+ "lib": ["DOM", "ESNext", "DOM.Iterable"],
5
+ "types": ["vite", "vite/client", "cypress", "@thednp/shorty", "@thednp/event-listener", "@thednp/color"],
6
+ "rootDir": "./",
7
+ "baseUrl": "./",
8
+ "module": "ESNext",
9
+ "target": "ESNext",
10
+ "moduleResolution": "Node",
11
+ "allowJs": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "useDefineForClassFields": true,
14
+ "strict": true,
15
+ "sourceMap": true,
16
+ "resolveJsonModule": true,
17
+ "esModuleInterop": true,
18
+ "isolatedModules": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noImplicitReturns": true,
22
+ "removeComments": false,
23
+ "allowSyntheticDefaultImports": true,
24
+ "noEmit": true,
25
+ "skipLibCheck": true // allows dts-bundle-generator to import from package.json
26
+ },
27
+ "include": ["src/*", "src/**/*"],
28
+ "exclude": ["node_modules", "experiments", "coverage", "dist"],
29
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ import { resolve } from 'path';
3
+ import { defineConfig } from 'vite';
4
+ import { name } from './package.json';
5
+
6
+ const getPackageName = () => {
7
+ return name.includes('@') ? name.split('/')[1] : name;
8
+ };
9
+
10
+ const NAME = 'ColorPicker';
11
+
12
+ const fileName = {
13
+ es: `${getPackageName()}.mjs`,
14
+ cjs: `${getPackageName()}.cjs`,
15
+ iife: `${getPackageName()}.js`,
16
+ };
17
+
18
+ export default defineConfig({
19
+ base: './',
20
+ build: {
21
+ emptyOutDir: true,
22
+ outDir: 'dist/js',
23
+ lib: {
24
+ entry: resolve(__dirname, 'src/ts/index.ts'),
25
+ name: NAME,
26
+ formats: ['es', 'cjs', 'iife'],
27
+ fileName: (format: string) => fileName[format],
28
+ },
29
+ target: 'ESNext',
30
+ sourcemap: true,
31
+ minify: true,
32
+ },
33
+ });
34
+