@thednp/color-picker 1.0.1 → 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 +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
package/package.json CHANGED
@@ -1,60 +1,54 @@
1
1
  {
2
2
  "name": "@thednp/color-picker",
3
- "version": "1.0.1",
4
- "description": "Modern Color Picker Web Component",
5
- "main": "dist/js/color-picker.min.js",
6
- "module": "dist/js/color-picker.esm.js",
7
- "types": "types/index.d.ts",
8
- "style": "dist/css/color-picker.min.css",
9
- "sass": "src/scss/color-picker.scss",
10
- "jsnext": "src/js/color-picker.js",
11
- "files": [
12
- "types",
13
- "dist",
14
- "src"
15
- ],
16
- "publishConfig": {
17
- "access": "public",
18
- "registry": "https://registry.npmjs.org/"
3
+ "version": "2.0.0-alpha1",
4
+ "author": "thednp",
5
+ "license": "MIT",
6
+ "description": "🎨 Modern Color Picker Component",
7
+ "homepage": "http://thednp.github.io/color-picker",
8
+ "source": "./src/ts/index.ts",
9
+ "main": "./dist/js/color-picker.js",
10
+ "module": "./dist/js/color-picker.mjs",
11
+ "types": "./dist/js/color-picker.d.ts",
12
+ "style": "./dist/css/color-picker.css",
13
+ "sass": "./src/scss/color-picker.scss",
14
+ "exports": {
15
+ ".": {
16
+ "require": "./dist/color-picker.cjs",
17
+ "import": "./dist/color-picker.mjs"
18
+ }
19
19
  },
20
20
  "scripts": {
21
- "test": "cypress run",
22
- "cypress": "npx cypress open",
21
+ "pre-test": "npm run clean-coverage",
22
+ "test": "npm run pre-test && cypress run",
23
+ "cypress": "npm run pre-test && npx cypress open",
24
+ "clean-coverage": "rimraf coverage .nyc_output",
23
25
  "coverage:report": "nyc report --reporter=lcov --reporter=json --reporter=text --reporter=json-summary",
24
- "fix:js": "eslint src/ --config .eslintrc --fix",
25
- "lint:js": "eslint src/ --config .eslintrc",
26
- "fix:css": "stylelint --config .stylelintrc.json -s --fix scss \"src/scss/*.scss\"",
27
- "lint:css": "stylelint --config .stylelintrc.json -s scss \"src/scss/*.scss\"",
28
- "bundle": "npm-run-all build compile",
29
- "build": "npm run lint:js && npm-run-all --parallel build-* && npm-run-all --parallel copy-js-*",
30
- "build:ts": "tsc -d",
31
- "build-js": "rollup --environment FORMAT:umd,MIN:false -c",
32
- "build-ce": "rollup --environment FORMAT:umd,MIN:false,NAME:ColorPickerElement,INPUTFILE:src/js/color-picker-element.js,OUTPUTFILE:dist/js/color-picker-element.js -c",
33
- "build-ce-min": "rollup --environment FORMAT:umd,MIN:true,NAME:ColorPickerElement,INPUTFILE:src/js/color-picker-element.js,OUTPUTFILE:dist/js/color-picker-element.min.js -c",
34
- "build-ce-esm": "rollup --environment FORMAT:esm,MIN:false,NAME:ColorPickerElement,INPUTFILE:src/js/color-picker-element.js,OUTPUTFILE:dist/js/color-picker-element-esm.js -c",
35
- "build-ce-esm-min": "rollup --environment FORMAT:esm,MIN:true,NAME:ColorPickerElement,INPUTFILE:src/js/color-picker-element.js,OUTPUTFILE:dist/js/color-picker-element-esm.min.js -c",
36
- "build-cl": "rollup --environment FORMAT:umd,MIN:false,NAME:Color,INPUTFILE:src/js/color.js,OUTPUTFILE:dist/js/color.js -c",
37
- "build-cl-min": "rollup --environment FORMAT:umd,MIN:true,NAME:Color,INPUTFILE:src/js/color.js,OUTPUTFILE:dist/js/color.min.js -c",
38
- "build-cl-esm": "rollup --environment FORMAT:esm,MIN:false,NAME:Color,INPUTFILE:src/js/color.js,OUTPUTFILE:dist/js/color-esm.js -c",
39
- "build-cl-esm-min": "rollup --environment FORMAT:esm,MIN:true,NAME:Color,INPUTFILE:src/js/color.js,OUTPUTFILE:dist/js/color-esm.min.js -c",
40
- "build-cpl": "rollup --environment FORMAT:umd,MIN:false,NAME:ColorPalette,INPUTFILE:src/js/color-palette.js,OUTPUTFILE:dist/js/color-palette.js -c",
41
- "build-cpl-min": "rollup --environment FORMAT:umd,MIN:true,NAME:ColorPalette,INPUTFILE:src/js/color-palette.js,OUTPUTFILE:dist/js/color-palette.min.js -c",
42
- "build-cpl-esm": "rollup --environment FORMAT:esm,MIN:false,NAME:ColorPalette,INPUTFILE:src/js/color-palette.js,OUTPUTFILE:dist/js/color-palette-esm.js -c",
43
- "build-cpl-esm-min": "rollup --environment FORMAT:esm,MIN:true,NAME:ColorPalette,INPUTFILE:src/js/color-palette.js,OUTPUTFILE:dist/js/color-palette-esm.min.js -c",
44
- "build-minjs": "rollup --environment FORMAT:umd,MIN:true -c",
45
- "build-esm": "rollup --environment FORMAT:esm,MIN:false -c",
46
- "build-esmjs": "rollup --environment FORMAT:esm,MIN:true -c",
26
+ "format": "prettier --write \"src/**/*.ts\"",
27
+ "fix:ts": "eslint src --config .eslintrc.cjs --fix",
28
+ "lint:ts": "eslint src --config .eslintrc.cjs",
29
+ "fix:css": "stylelint --config .stylelintrc.json --fix scss \"src/scss/*.scss\"",
30
+ "lint:css": "stylelint --config .stylelintrc.json scss \"src/scss/*.scss\"",
31
+ "build": "npm run lint:ts && npm run build-vite && npm run dts",
32
+ "build-vite": "vite build && npm run docs",
33
+ "dev": "vite --open ./docs/index.html --port 8577",
34
+ "dts": "dts-bundle-generator --config ./dts.config.ts",
35
+ "docs": "ncp dist/js/color-picker.js docs/js/color-picker.js && ncp dist/js/color-picker.js.map docs/js/color-picker.js.map",
47
36
  "copy": "npm-run-all --parallel copy-*",
48
- "copy-js-cp": "ncp dist/js/color-picker.js docs/js/color-picker.js",
49
- "copy-js-ce": "ncp dist/js/color-picker-element.js docs/js/color-picker-element.js",
50
37
  "copy-css-cp": "ncp dist/css/color-picker.css docs/css/color-picker.css",
51
38
  "copy-css-rtl": "ncp dist/css/color-picker.rtl.css docs/css/color-picker.rtl.css",
52
- "compile": "npm run lint:css && npm-run-all --parallel compile-* && npm-run-all --parallel copy-css-*",
39
+ "compile": "npm run lint:css && npm-run-all --parallel compile-* && npm run copy",
53
40
  "compile-scss": "node compile.js",
54
41
  "compile-scss-min": "node compile.js MIN:true",
55
42
  "compile-scss-rtl": "node compile.js MIN:false,DIR:rtl",
56
43
  "compile-scss-rtl-min": "node compile.js MIN:true,DIR:rtl"
57
44
  },
45
+ "bugs": {
46
+ "url": "https://github.com/thednp/color-picker/issues"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "registry": "https://registry.npmjs.org/"
51
+ },
58
52
  "repository": {
59
53
  "type": "git",
60
54
  "url": "git+https://github.com/thednp/color-picker.git"
@@ -66,43 +60,39 @@
66
60
  "colorpicker",
67
61
  "palette",
68
62
  "color-palette",
69
- "javascript"
63
+ "typescript"
70
64
  ],
71
- "author": "thednp",
72
- "license": "MIT",
73
- "bugs": {
74
- "url": "https://github.com/thednp/color-picker/issues"
75
- },
76
- "homepage": "http://thednp.github.io/color-picker",
77
65
  "dependencies": {
78
- "@thednp/event-listener": "^1.0.4",
79
- "shorter-js": "^0.3.4"
66
+ "@thednp/color": "^1.0.6",
67
+ "@thednp/event-listener": "^2.0.0",
68
+ "@thednp/shorty": "^2.0.0-alpha14"
80
69
  },
81
70
  "devDependencies": {
82
- "@bahmutov/cypress-esbuild-preprocessor": "^2.1.3",
83
- "@cypress/code-coverage": "^3.9.12",
84
- "@rollup/plugin-buble": "^0.21.3",
85
- "@rollup/plugin-commonjs": "^21.0.3",
86
- "@rollup/plugin-json": "^4.1.0",
87
- "@rollup/plugin-node-resolve": "^7.1.3",
88
- "cypress": "^9.7.0",
89
- "esbuild": "^0.14.30",
90
- "eslint": "^7.22.0",
91
- "eslint-config-airbnb-base": "^14.2.1",
92
- "eslint-plugin-import": "^2.22.1",
93
- "eslint-plugin-vue": "^7.7.0",
71
+ "@bahmutov/cypress-esbuild-preprocessor": "^2.2.0",
72
+ "@cypress/code-coverage": "^3.10.3",
73
+ "@types/istanbul-lib-instrument": "^1.7.4",
74
+ "@typescript-eslint/eslint-plugin": "^5.57.1",
75
+ "@typescript-eslint/parser": "^5.57.1",
76
+ "cypress": "^12.9.0",
77
+ "dts-bundle-generator": "^8.0.0",
78
+ "eslint": "^8.37.0",
79
+ "eslint-plugin-jsdoc": "^40.1.1",
80
+ "eslint-plugin-prefer-arrow": "^1.2.3",
81
+ "eslint-plugin-prettier": "^4.2.1",
94
82
  "istanbul-lib-coverage": "^3.2.0",
95
- "istanbul-lib-instrument": "^5.2.0",
83
+ "istanbul-lib-instrument": "^5.2.1",
96
84
  "ncp": "^2.0.0",
97
85
  "npm-run-all": "^4.1.5",
98
86
  "nyc": "^15.1.0",
99
- "rollup": "^2.71.1",
100
- "rollup-plugin-terser": "^5.3.1",
101
- "sass": "^1.39.0",
102
- "stylelint": "^13.12.0",
103
- "stylelint-config-standard": "^20.0.0",
104
- "stylelint-order": "^4.1.0",
105
- "stylelint-scss": "^3.19.0",
106
- "typescript": "^4.5.2"
87
+ "prettier": "^2.8.7",
88
+ "rimraf": "^4.4.1",
89
+ "sass": "^1.60.0",
90
+ "stylelint": "^15.4.0",
91
+ "stylelint-config-standard": "^32.0.0",
92
+ "stylelint-config-standard-scss": "^7.0.1",
93
+ "stylelint-order": "^6.0.3",
94
+ "stylelint-scss": "^4.6.0",
95
+ "typescript": "^5.0.3",
96
+ "vite": "^4.3.9"
107
97
  }
108
98
  }
@@ -1,7 +1,6 @@
1
1
  $transparency-levels: (
2
2
  15, 25, 33, 50, 75, 90
3
3
  );
4
-
5
4
  $dropdown-transition: transform .33s ease, opacity .33s ease;
6
5
  $btn-transition: box-shadow .33s ease, border .33s ease;
7
6
  $options-transition: height .33s ease;
@@ -7,16 +7,20 @@
7
7
  right: auto; left: 0;
8
8
  border-radius: .25rem 0 0 .25rem;
9
9
  }
10
+
10
11
  .color-dropdown.picker {
11
12
  right: 0; left: auto;
12
13
  }
14
+
13
15
  .color-dropdown.menu {
14
16
  right: auto; left: 0;
15
17
  }
18
+
16
19
  .color-control + .color-control {
17
20
  margin-right: .5rem;
18
21
  margin-left: 0;
19
22
  }
23
+
20
24
  .color-options.scrollable {
21
25
  margin: 0 0 0 -.5rem;
22
26
  }
@@ -1,23 +1,26 @@
1
1
  @import "variables";
2
2
 
3
3
  /* :host */
4
- color-picker,
5
4
  .color-picker {
6
5
  position: relative;
7
6
  display: flex;
8
7
 
9
8
  @each $name in "white", "black" {
10
9
  @each $lvl in $transparency-levels {
11
- @if (type-of($name) == "string" and type-of($lvl) == "number") {
10
+ @if type-of($name) == "string" and type-of($lvl) == "number" {
12
11
  $color: #fff;
12
+
13
13
  @if $name == "black" {
14
14
  $color: #000;
15
15
  }
16
- $rgba: rgba($color, $lvl * .01);
16
+
17
+ $rgba: rgba($color, $lvl * 1%);
18
+
17
19
  --#{$name}-#{$lvl}: #{$rgba};
18
20
  }
19
21
  }
20
22
  }
23
+
21
24
  --dropdown-transition: #{$dropdown-transition};
22
25
  --btn-transition: #{$btn-transition};
23
26
  --options-transition: #{$options-transition};
@@ -40,7 +43,6 @@ color-picker,
40
43
  --visual-shadow: 0 0 0 1px var(--white-15) inset;
41
44
  }
42
45
 
43
- color-picker:focus,
44
46
  .color-picker:focus {
45
47
  outline: none;
46
48
  }
@@ -62,7 +64,7 @@ color-picker:focus,
62
64
  }
63
65
 
64
66
  .color-dropdown.picker { left: 0; }
65
- .color-dropdown.menu { right: 0; }
67
+ .color-dropdown.menu { right: 0; max-height: 230px; }
66
68
 
67
69
  .open .color-dropdown.top {
68
70
  top: auto;
@@ -100,10 +102,12 @@ color-picker:focus,
100
102
  border-radius: .25rem;
101
103
  outline: none;
102
104
  appearance: none;
105
+
103
106
  // transition-duration: .33s;
104
107
  // transition-property: box-shadow, border;
105
108
  transition: var(--btn-transition);
106
109
  }
110
+
107
111
  .btn-appearance:focus,
108
112
  .btn-appearance:hover {
109
113
  box-shadow: 0 0 0 3px var(--black-15);
@@ -111,26 +115,31 @@ color-picker:focus,
111
115
 
112
116
  /* color-preview */
113
117
  .color-preview {
114
- box-shadow: 0 0 0 1px rgba(120,120,120,.33) inset;
118
+ box-shadow: 0 0 0 1px rgba(120,120,120,33%) inset;
115
119
  direction: ltr; /* color value can never be rtl */
116
120
  }
117
121
 
118
122
  .txt-dark .color-preview {
119
123
  color: var(--white-75);
120
124
  }
125
+
121
126
  .txt-dark .color-preview:focus {
122
127
  box-shadow: 0 0 0 1px #fff inset, 0 0 0 3px var(--black-15);
123
128
  }
129
+
124
130
  .txt-dark .color-preview::placeholder {
125
131
  color: var(--white-50);
126
132
  }
133
+
127
134
  .txt-light .color-preview {
128
135
  color: var(--black-75);
129
136
  }
137
+
130
138
  .txt-light .color-preview:focus {
131
139
  color: var(--black-75);
132
140
  box-shadow: 0 0 0 1px #000 inset, 0 0 0 3px var(--black-15);
133
141
  }
142
+
134
143
  .txt-light .color-preview::placeholder {
135
144
  color: var(--black-50);
136
145
  }
@@ -163,20 +172,23 @@ color-picker:focus,
163
172
  border: 0;
164
173
  border-radius: 0 .25rem .25rem 0;
165
174
  }
175
+
166
176
  .txt-light .menu-toggle {
167
177
  background: var(--black-50);
178
+
179
+ &:focus {
180
+ background: var(--black-75);
181
+ }
168
182
  }
169
- .txt-light .menu-toggle:focus,
170
- .txt-light .menu-toggle:focus {
171
- background: var(--black-75);
172
- }
183
+
173
184
  .txt-dark .menu-toggle {
174
185
  background: var(--white-33);
186
+
187
+ &:focus {
188
+ background: var(--white-50);
189
+ }
175
190
  }
176
- .txt-dark .menu-toggle:focus,
177
- .txt-dark .menu-toggle:focus {
178
- background: var(--white-50);
179
- }
191
+
180
192
  .menu-toggle svg {
181
193
  width: auto;
182
194
  height: 100%;
@@ -188,6 +200,7 @@ color-picker:focus,
188
200
  overflow-y: auto;
189
201
  scrollbar-width: thin;
190
202
  }
203
+
191
204
  .scrollable::-webkit-scrollbar {
192
205
  width: .5rem;
193
206
  }
@@ -214,8 +227,9 @@ color-picker:focus,
214
227
  /* color-defaults */
215
228
  .color-defaults {
216
229
  display: none;
217
- flex-wrap: wrap;
218
- flex-flow: column;
230
+
231
+ // flex-wrap: ;
232
+ flex-flow: column wrap;
219
233
  margin: 0;
220
234
  list-style: none;
221
235
  padding-inline: 0; // Firefox
@@ -226,9 +240,9 @@ color-picker:focus,
226
240
  display: flex;
227
241
  }
228
242
 
229
- .color-dropdown.menu {
230
- max-height: 230px;
231
- }
243
+ // .color-dropdown.menu {
244
+ // max-height: 230px;
245
+ // }
232
246
 
233
247
  .color-defaults .color-option {
234
248
  padding: .25rem .5rem;
@@ -259,6 +273,7 @@ color-picker:focus,
259
273
  --grid-gap: .25rem; // grid vertical / horizontal spacing
260
274
  --grid-height: auto; // default height
261
275
  --grid-hover-height: auto; // height on hover
276
+
262
277
  display: grid;
263
278
  padding: 0;
264
279
  margin: 0;
@@ -267,25 +282,30 @@ color-picker:focus,
267
282
  grid-template-rows: repeat(auto-fill, var(--grid-item-size));
268
283
  gap: var(--grid-gap);
269
284
  }
285
+
270
286
  .color-options.scrollable {
271
287
  height: var(--grid-height);
272
288
  margin: 0 -.5rem 0 0; // 0.5rem is the scrollbar width
273
289
  overflow-y: scroll;
274
290
  transition: var(--options-transition);
275
291
  }
292
+
276
293
  .color-options.scrollable:hover {
277
294
  height: var(--grid-hover-height);
278
295
  }
296
+
279
297
  .color-options + .color-defaults {
280
298
  margin-top: .25rem;
281
299
  }
300
+
282
301
  .multiline + .color-defaults {
283
- flex-direction: row;
284
- flex-wrap: wrap;
302
+ flex-flow: row wrap;
303
+
285
304
  .color-option {
286
305
  padding: .25rem .33rem; font-size: 12px;
287
306
  }
288
307
  }
308
+
289
309
  .color-options .color-option {
290
310
  // hide any text
291
311
  position: relative;
@@ -293,18 +313,23 @@ color-picker:focus,
293
313
  height: var(--grid-item-size);
294
314
  overflow: hidden;
295
315
  text-indent: 2.1rem;
316
+
317
+ &:active, &:focus {
318
+ outline: none;
319
+ box-shadow: 0 0 0 4px rgba(125,125,125,75%) inset;
320
+ }
296
321
  }
297
- .color-options .color-option:active,
298
- .color-options .color-option:focus {
299
- outline: none;
300
- }
322
+
323
+ // .color-options .color-option:active,
324
+ // .color-options .color-option:focus {
325
+ // outline: none;
326
+ // }
327
+
301
328
  .color-options .color-option::before {
302
329
  position: absolute;
303
- top: 0;
304
- right: 0;
305
- bottom: 0;
306
- left: 0;
330
+ inset: 0;
307
331
  }
332
+
308
333
  .color-options .color-option:hover::before,
309
334
  .color-options .color-option:active::before,
310
335
  .color-options .color-option:focus::before {
@@ -313,13 +338,15 @@ color-picker:focus,
313
338
  mix-blend-mode: difference;
314
339
  }
315
340
 
316
- .color-options .color-option:active,
317
- .color-options .color-option:focus {
318
- box-shadow: 0 0 0 4px rgba(125,125,125,.75) inset;
319
- }
341
+ // .color-options .color-option {
342
+ // &:active, &:focus {
343
+ // outline: none;
344
+ // box-shadow: 0 0 0 4px rgba(125,125,125,75%) inset;
345
+ // }
346
+ // }
320
347
 
321
348
  .color-options .color-option.active {
322
- &:after {
349
+ &::after {
323
350
  position: absolute;
324
351
  top: 50%;
325
352
  left: 50%;
@@ -330,18 +357,19 @@ color-picker:focus,
330
357
  border-radius: 4px;
331
358
  }
332
359
  }
333
- .txt-dark .color-options .color-option.active:after {
360
+
361
+ .txt-dark .color-options .color-option.active::after {
334
362
  box-shadow: 0 0 0 4px var(--white-90);
335
363
  }
336
- .txt-light .color-options .color-option.active:after {
364
+
365
+ .txt-light .color-options .color-option.active::after {
337
366
  box-shadow: 0 0 0 4px var(--black-90);
338
367
  }
339
368
 
340
369
  /* color-form */
341
370
  .color-form {
342
371
  display: flex;
343
- flex-direction: row;
344
- flex-wrap: wrap;
372
+ flex-flow: row wrap;
345
373
  align-items: center;
346
374
  padding: .25rem 0 0;
347
375
  font: 12px sans-serif;
@@ -383,6 +411,7 @@ color-picker:focus,
383
411
  /* visual control */
384
412
  .visual-control {
385
413
  height: 150px;
414
+
386
415
  /* important for mobile devices */
387
416
  touch-action: none;
388
417
  box-shadow: var(--visual-shadow);
@@ -391,6 +420,7 @@ color-picker:focus,
391
420
  .visual-control1 {
392
421
  width: 150px;
393
422
  }
423
+
394
424
  .visual-control2,
395
425
  .visual-control3 {
396
426
  width: 21px;
@@ -428,6 +458,7 @@ color-picker:focus,
428
458
  top: 0;
429
459
  left: 0;
430
460
  height: 7px;
461
+
431
462
  /* important for mobile devices */
432
463
  touch-action: none;
433
464
  user-select: none;
@@ -437,9 +468,11 @@ color-picker:focus,
437
468
  outline: none;
438
469
  will-change: transform;
439
470
  }
471
+
440
472
  .knob:hover {
441
473
  box-shadow: var(--knob-shadow-hover);
442
474
  }
475
+
443
476
  .knob:focus,
444
477
  .knob:active {
445
478
  z-index: 1;
@@ -456,6 +489,7 @@ color-picker:focus,
456
489
  .txt-dark .color-pointer {
457
490
  box-shadow: 0 0 0 5px var(--white-50);
458
491
  }
492
+
459
493
  .txt-light .color-pointer {
460
494
  box-shadow: 0 0 0 5px var(--black-50);
461
495
  }
@@ -463,6 +497,7 @@ color-picker:focus,
463
497
  .txt-dark .color-pointer:hover {
464
498
  box-shadow: 0 0 0 5px var(--white-75);
465
499
  }
500
+
466
501
  .txt-light .color-pointer:hover {
467
502
  box-shadow: 0 0 0 5px var(--black-75);
468
503
  }
@@ -471,6 +506,7 @@ color-picker:focus,
471
506
  .txt-dark .color-pointer:active {
472
507
  box-shadow: 0 0 0 5px var(--white-90);
473
508
  }
509
+
474
510
  .txt-light .color-pointer:focus,
475
511
  .txt-light .color-pointer:active {
476
512
  box-shadow: 0 0 0 5px var(--black-90);
@@ -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
+ }