@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.
Files changed (87) 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 +55 -72
  7. package/compile.js +48 -0
  8. package/cypress/e2e/color-palette.cy.ts +128 -0
  9. package/cypress/e2e/color-picker.cy.ts +920 -0
  10. package/cypress/fixtures/colorNamesFrench.js +3 -0
  11. package/cypress/fixtures/componentLabelsFrench.js +21 -0
  12. package/cypress/fixtures/format.js +3 -0
  13. package/cypress/fixtures/getCEMarkup.js +29 -0
  14. package/cypress/fixtures/getMarkup.js +28 -0
  15. package/cypress/fixtures/getRandomInt.js +6 -0
  16. package/cypress/fixtures/sampleWebcolors.js +18 -0
  17. package/cypress/fixtures/testSample.js +8 -0
  18. package/cypress/plugins/esbuild-istanbul.ts +50 -0
  19. package/cypress/plugins/tsCompile.ts +34 -0
  20. package/cypress/support/commands.ts +0 -0
  21. package/cypress/support/e2e.ts +21 -0
  22. package/cypress/test.html +23 -0
  23. package/cypress.config.ts +29 -0
  24. package/dist/css/color-picker.css +16 -40
  25. package/dist/css/color-picker.min.css +2 -2
  26. package/dist/css/color-picker.rtl.css +16 -40
  27. package/dist/css/color-picker.rtl.min.css +2 -2
  28. package/dist/js/color-picker.cjs +8 -0
  29. package/dist/js/color-picker.cjs.map +1 -0
  30. package/dist/js/color-picker.d.ts +278 -0
  31. package/dist/js/color-picker.js +5 -3570
  32. package/dist/js/color-picker.js.map +1 -0
  33. package/dist/js/color-picker.mjs +2631 -0
  34. package/dist/js/color-picker.mjs.map +1 -0
  35. package/dts.config.ts +15 -0
  36. package/package.json +64 -74
  37. package/src/scss/_variables.scss +0 -1
  38. package/src/scss/color-picker.rtl.scss +4 -0
  39. package/src/scss/color-picker.scss +80 -40
  40. package/src/ts/colorPalette.ts +89 -0
  41. package/src/{js/color-picker.js → ts/index.ts} +489 -486
  42. package/src/ts/interface/colorPickerLabels.ts +20 -0
  43. package/src/ts/interface/colorPickerOptions.ts +11 -0
  44. package/src/ts/interface/paletteOptions.ts +6 -0
  45. package/src/ts/util/colorNames.ts +21 -0
  46. package/src/{js/util/colorPickerLabels.js → ts/util/colorPickerLabels.ts} +4 -2
  47. package/src/ts/util/getColorControls.ts +90 -0
  48. package/src/{js/util/getColorForm.js → ts/util/getColorForm.ts} +28 -18
  49. package/src/{js/util/getColorMenu.js → ts/util/getColorMenu.ts} +21 -30
  50. package/src/ts/util/isValidJSON.ts +19 -0
  51. package/src/{js/util/setMarkup.js → ts/util/setMarkup.ts} +57 -48
  52. package/src/{js/util/vHidden.js → ts/util/vHidden.ts} +0 -0
  53. package/tsconfig.json +29 -0
  54. package/vite.config.ts +34 -0
  55. package/dist/js/color-esm.js +0 -1164
  56. package/dist/js/color-esm.min.js +0 -2
  57. package/dist/js/color-palette-esm.js +0 -1235
  58. package/dist/js/color-palette-esm.min.js +0 -2
  59. package/dist/js/color-palette.js +0 -1243
  60. package/dist/js/color-palette.min.js +0 -2
  61. package/dist/js/color-picker-element-esm.js +0 -3718
  62. package/dist/js/color-picker-element-esm.min.js +0 -2
  63. package/dist/js/color-picker-element.js +0 -3726
  64. package/dist/js/color-picker-element.min.js +0 -2
  65. package/dist/js/color-picker-esm.js +0 -3565
  66. package/dist/js/color-picker-esm.min.js +0 -2
  67. package/dist/js/color-picker.min.js +0 -2
  68. package/dist/js/color.js +0 -1172
  69. package/dist/js/color.min.js +0 -2
  70. package/src/js/color-palette.js +0 -75
  71. package/src/js/color-picker-element.js +0 -107
  72. package/src/js/color.js +0 -1104
  73. package/src/js/index.js +0 -8
  74. package/src/js/util/colorNames.js +0 -6
  75. package/src/js/util/getColorControls.js +0 -103
  76. package/src/js/util/isValidJSON.js +0 -13
  77. package/src/js/util/nonColors.js +0 -5
  78. package/src/js/util/roundPart.js +0 -9
  79. package/src/js/util/setCSSProperties.js +0 -12
  80. package/src/js/util/tabindex.js +0 -3
  81. package/src/js/util/toggleCEAttr.js +0 -70
  82. package/src/js/util/version.js +0 -5
  83. package/src/js/version.js +0 -5
  84. package/types/cp.d.ts +0 -558
  85. package/types/index.d.ts +0 -44
  86. package/types/source/source.ts +0 -4
  87. 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-alpha2",
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.7",
67
+ "@thednp/event-listener": "^2.0.1",
68
+ "@thednp/shorty": "^2.0.0-alpha15"
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.7",
73
+ "@types/istanbul-lib-instrument": "^1.7.4",
74
+ "@typescript-eslint/eslint-plugin": "^5.59.9",
75
+ "@typescript-eslint/parser": "^5.59.9",
76
+ "cypress": "^12.14.0",
77
+ "dts-bundle-generator": "^8.0.1",
78
+ "eslint": "^8.42.0",
79
+ "eslint-plugin-jsdoc": "^46.2.6",
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.8",
88
+ "rimraf": "^5.0.1",
89
+ "sass": "^1.63.3",
90
+ "stylelint": "^15.7.0",
91
+ "stylelint-config-standard": "^33.0.0",
92
+ "stylelint-config-standard-scss": "^9.0.0",
93
+ "stylelint-order": "^6.0.3",
94
+ "stylelint-scss": "^5.0.1",
95
+ "typescript": "^5.1.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,11 @@ color-picker:focus,
62
64
  }
63
65
 
64
66
  .color-dropdown.picker { left: 0; }
65
- .color-dropdown.menu { right: 0; }
67
+
68
+ .color-dropdown.menu {
69
+ right: 0;
70
+ max-height: 230px;
71
+ }
66
72
 
67
73
  .open .color-dropdown.top {
68
74
  top: auto;
@@ -100,10 +106,12 @@ color-picker:focus,
100
106
  border-radius: .25rem;
101
107
  outline: none;
102
108
  appearance: none;
109
+
103
110
  // transition-duration: .33s;
104
111
  // transition-property: box-shadow, border;
105
112
  transition: var(--btn-transition);
106
113
  }
114
+
107
115
  .btn-appearance:focus,
108
116
  .btn-appearance:hover {
109
117
  box-shadow: 0 0 0 3px var(--black-15);
@@ -111,26 +119,31 @@ color-picker:focus,
111
119
 
112
120
  /* color-preview */
113
121
  .color-preview {
114
- box-shadow: 0 0 0 1px rgba(120,120,120,.33) inset;
122
+ box-shadow: 0 0 0 1px rgba(120,120,120,33%) inset;
115
123
  direction: ltr; /* color value can never be rtl */
116
124
  }
117
125
 
118
126
  .txt-dark .color-preview {
119
127
  color: var(--white-75);
120
128
  }
129
+
121
130
  .txt-dark .color-preview:focus {
122
131
  box-shadow: 0 0 0 1px #fff inset, 0 0 0 3px var(--black-15);
123
132
  }
133
+
124
134
  .txt-dark .color-preview::placeholder {
125
135
  color: var(--white-50);
126
136
  }
137
+
127
138
  .txt-light .color-preview {
128
139
  color: var(--black-75);
129
140
  }
141
+
130
142
  .txt-light .color-preview:focus {
131
143
  color: var(--black-75);
132
144
  box-shadow: 0 0 0 1px #000 inset, 0 0 0 3px var(--black-15);
133
145
  }
146
+
134
147
  .txt-light .color-preview::placeholder {
135
148
  color: var(--black-50);
136
149
  }
@@ -163,20 +176,23 @@ color-picker:focus,
163
176
  border: 0;
164
177
  border-radius: 0 .25rem .25rem 0;
165
178
  }
179
+
166
180
  .txt-light .menu-toggle {
167
181
  background: var(--black-50);
182
+
183
+ &:focus {
184
+ background: var(--black-75);
185
+ }
168
186
  }
169
- .txt-light .menu-toggle:focus,
170
- .txt-light .menu-toggle:focus {
171
- background: var(--black-75);
172
- }
187
+
173
188
  .txt-dark .menu-toggle {
174
189
  background: var(--white-33);
190
+
191
+ &:focus {
192
+ background: var(--white-50);
193
+ }
175
194
  }
176
- .txt-dark .menu-toggle:focus,
177
- .txt-dark .menu-toggle:focus {
178
- background: var(--white-50);
179
- }
195
+
180
196
  .menu-toggle svg {
181
197
  width: auto;
182
198
  height: 100%;
@@ -188,6 +204,7 @@ color-picker:focus,
188
204
  overflow-y: auto;
189
205
  scrollbar-width: thin;
190
206
  }
207
+
191
208
  .scrollable::-webkit-scrollbar {
192
209
  width: .5rem;
193
210
  }
@@ -214,8 +231,9 @@ color-picker:focus,
214
231
  /* color-defaults */
215
232
  .color-defaults {
216
233
  display: none;
217
- flex-wrap: wrap;
218
- flex-flow: column;
234
+
235
+ // flex-wrap: ;
236
+ flex-flow: column wrap;
219
237
  margin: 0;
220
238
  list-style: none;
221
239
  padding-inline: 0; // Firefox
@@ -226,9 +244,9 @@ color-picker:focus,
226
244
  display: flex;
227
245
  }
228
246
 
229
- .color-dropdown.menu {
230
- max-height: 230px;
231
- }
247
+ // .color-dropdown.menu {
248
+ // max-height: 230px;
249
+ // }
232
250
 
233
251
  .color-defaults .color-option {
234
252
  padding: .25rem .5rem;
@@ -259,6 +277,7 @@ color-picker:focus,
259
277
  --grid-gap: .25rem; // grid vertical / horizontal spacing
260
278
  --grid-height: auto; // default height
261
279
  --grid-hover-height: auto; // height on hover
280
+
262
281
  display: grid;
263
282
  padding: 0;
264
283
  margin: 0;
@@ -267,25 +286,30 @@ color-picker:focus,
267
286
  grid-template-rows: repeat(auto-fill, var(--grid-item-size));
268
287
  gap: var(--grid-gap);
269
288
  }
289
+
270
290
  .color-options.scrollable {
271
291
  height: var(--grid-height);
272
292
  margin: 0 -.5rem 0 0; // 0.5rem is the scrollbar width
273
293
  overflow-y: scroll;
274
294
  transition: var(--options-transition);
275
295
  }
296
+
276
297
  .color-options.scrollable:hover {
277
298
  height: var(--grid-hover-height);
278
299
  }
300
+
279
301
  .color-options + .color-defaults {
280
302
  margin-top: .25rem;
281
303
  }
304
+
282
305
  .multiline + .color-defaults {
283
- flex-direction: row;
284
- flex-wrap: wrap;
306
+ flex-flow: row wrap;
307
+
285
308
  .color-option {
286
309
  padding: .25rem .33rem; font-size: 12px;
287
310
  }
288
311
  }
312
+
289
313
  .color-options .color-option {
290
314
  // hide any text
291
315
  position: relative;
@@ -293,18 +317,23 @@ color-picker:focus,
293
317
  height: var(--grid-item-size);
294
318
  overflow: hidden;
295
319
  text-indent: 2.1rem;
320
+
321
+ &:active, &:focus {
322
+ outline: none;
323
+ box-shadow: 0 0 0 4px rgba(125,125,125,75%) inset;
324
+ }
296
325
  }
297
- .color-options .color-option:active,
298
- .color-options .color-option:focus {
299
- outline: none;
300
- }
326
+
327
+ // .color-options .color-option:active,
328
+ // .color-options .color-option:focus {
329
+ // outline: none;
330
+ // }
331
+
301
332
  .color-options .color-option::before {
302
333
  position: absolute;
303
- top: 0;
304
- right: 0;
305
- bottom: 0;
306
- left: 0;
334
+ inset: 0;
307
335
  }
336
+
308
337
  .color-options .color-option:hover::before,
309
338
  .color-options .color-option:active::before,
310
339
  .color-options .color-option:focus::before {
@@ -313,13 +342,15 @@ color-picker:focus,
313
342
  mix-blend-mode: difference;
314
343
  }
315
344
 
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
- }
345
+ // .color-options .color-option {
346
+ // &:active, &:focus {
347
+ // outline: none;
348
+ // box-shadow: 0 0 0 4px rgba(125,125,125,75%) inset;
349
+ // }
350
+ // }
320
351
 
321
352
  .color-options .color-option.active {
322
- &:after {
353
+ &::after {
323
354
  position: absolute;
324
355
  top: 50%;
325
356
  left: 50%;
@@ -330,18 +361,19 @@ color-picker:focus,
330
361
  border-radius: 4px;
331
362
  }
332
363
  }
333
- .txt-dark .color-options .color-option.active:after {
364
+
365
+ .txt-dark .color-options .color-option.active::after {
334
366
  box-shadow: 0 0 0 4px var(--white-90);
335
367
  }
336
- .txt-light .color-options .color-option.active:after {
368
+
369
+ .txt-light .color-options .color-option.active::after {
337
370
  box-shadow: 0 0 0 4px var(--black-90);
338
371
  }
339
372
 
340
373
  /* color-form */
341
374
  .color-form {
342
375
  display: flex;
343
- flex-direction: row;
344
- flex-wrap: wrap;
376
+ flex-flow: row wrap;
345
377
  align-items: center;
346
378
  padding: .25rem 0 0;
347
379
  font: 12px sans-serif;
@@ -383,6 +415,7 @@ color-picker:focus,
383
415
  /* visual control */
384
416
  .visual-control {
385
417
  height: 150px;
418
+
386
419
  /* important for mobile devices */
387
420
  touch-action: none;
388
421
  box-shadow: var(--visual-shadow);
@@ -391,18 +424,19 @@ color-picker:focus,
391
424
  .visual-control1 {
392
425
  width: 150px;
393
426
  }
427
+
394
428
  .visual-control2,
395
429
  .visual-control3 {
396
430
  width: 21px;
397
431
  cursor: ns-resize;
398
432
  }
399
433
 
400
- @media (min-width: 578px) {
434
+ @media (width >= 578px) {
401
435
  .visual-control { height: 230px; }
402
436
  .visual-control1 { width: 230px; }
403
437
  }
404
438
 
405
- @media (min-width: 1200px) {
439
+ @media (width >= 1200px) {
406
440
  .visual-control { height: 300px; }
407
441
  .visual-control1 { width: 300px; }
408
442
  }
@@ -428,6 +462,7 @@ color-picker:focus,
428
462
  top: 0;
429
463
  left: 0;
430
464
  height: 7px;
465
+
431
466
  /* important for mobile devices */
432
467
  touch-action: none;
433
468
  user-select: none;
@@ -437,9 +472,11 @@ color-picker:focus,
437
472
  outline: none;
438
473
  will-change: transform;
439
474
  }
475
+
440
476
  .knob:hover {
441
477
  box-shadow: var(--knob-shadow-hover);
442
478
  }
479
+
443
480
  .knob:focus,
444
481
  .knob:active {
445
482
  z-index: 1;
@@ -456,6 +493,7 @@ color-picker:focus,
456
493
  .txt-dark .color-pointer {
457
494
  box-shadow: 0 0 0 5px var(--white-50);
458
495
  }
496
+
459
497
  .txt-light .color-pointer {
460
498
  box-shadow: 0 0 0 5px var(--black-50);
461
499
  }
@@ -463,6 +501,7 @@ color-picker:focus,
463
501
  .txt-dark .color-pointer:hover {
464
502
  box-shadow: 0 0 0 5px var(--white-75);
465
503
  }
504
+
466
505
  .txt-light .color-pointer:hover {
467
506
  box-shadow: 0 0 0 5px var(--black-75);
468
507
  }
@@ -471,6 +510,7 @@ color-picker:focus,
471
510
  .txt-dark .color-pointer:active {
472
511
  box-shadow: 0 0 0 5px var(--white-90);
473
512
  }
513
+
474
514
  .txt-light .color-pointer:focus,
475
515
  .txt-light .color-pointer:active {
476
516
  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
+ }