@umbraco-ui/uui-color-picker 1.6.0 → 1.7.0
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.
- package/lib/index.js +37 -31
- package/lib/uui-color-picker.element.d.ts +2 -0
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -12,25 +12,12 @@ var r={grad:.9,turn:360,rad:360/(2*Math.PI)},t=function(r){return "string"==type
|
|
|
12
12
|
|
|
13
13
|
function namesPlugin(e,f){var a={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},r={};for(var d in a)r[a[d]]=d;var l={};e.prototype.toName=function(f){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return "transparent";var d,i,n=r[this.toHex()];if(n)return n;if(null==f?void 0:f.closest){var o=this.toRgb(),t=1/0,b="black";if(!l.length)for(var c in a)l[c]=new e(a[c]).toRgb();for(var g in a){var u=(d=o,i=l[g],Math.pow(d.r-i.r,2)+Math.pow(d.g-i.g,2)+Math.pow(d.b-i.b,2));u<t&&(t=u,b=g);}return b}};f.string.push([function(f){var r=f.toLowerCase(),d="transparent"===r?"#0000":a[r];return d?new e(d).toRgb():null},"name"]);}
|
|
14
14
|
|
|
15
|
-
var __defProp$1 = Object.defineProperty;
|
|
16
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
17
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
18
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
19
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
20
|
-
var __spreadValues = (a, b) => {
|
|
21
|
-
for (var prop in b || (b = {}))
|
|
22
|
-
if (__hasOwnProp.call(b, prop))
|
|
23
|
-
__defNormalProp(a, prop, b[prop]);
|
|
24
|
-
if (__getOwnPropSymbols)
|
|
25
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
26
|
-
if (__propIsEnum.call(b, prop))
|
|
27
|
-
__defNormalProp(a, prop, b[prop]);
|
|
28
|
-
}
|
|
29
|
-
return a;
|
|
30
|
-
};
|
|
31
15
|
class UUIColorPickerChangeEvent extends UUIEvent {
|
|
32
16
|
constructor(evName, eventInit = {}) {
|
|
33
|
-
super(evName,
|
|
17
|
+
super(evName, {
|
|
18
|
+
...{ bubbles: true },
|
|
19
|
+
...eventInit
|
|
20
|
+
});
|
|
34
21
|
}
|
|
35
22
|
}
|
|
36
23
|
UUIColorPickerChangeEvent.CHANGE = "change";
|
|
@@ -150,9 +137,8 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
|
|
|
150
137
|
this._syncValues();
|
|
151
138
|
}
|
|
152
139
|
handleAlphaChange(event) {
|
|
153
|
-
var _a;
|
|
154
140
|
event.stopPropagation();
|
|
155
|
-
|
|
141
|
+
this._swatches?.resetSelection();
|
|
156
142
|
const element = event.target;
|
|
157
143
|
const newColor = {
|
|
158
144
|
h: this.hue,
|
|
@@ -163,9 +149,8 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
|
|
|
163
149
|
this.setColor(newColor);
|
|
164
150
|
}
|
|
165
151
|
handleHueChange(event) {
|
|
166
|
-
var _a;
|
|
167
152
|
event.stopPropagation();
|
|
168
|
-
|
|
153
|
+
this._swatches?.resetSelection();
|
|
169
154
|
const element = event.target;
|
|
170
155
|
const newColor = {
|
|
171
156
|
h: element.value,
|
|
@@ -176,9 +161,8 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
|
|
|
176
161
|
this.setColor(newColor);
|
|
177
162
|
}
|
|
178
163
|
handleGridChange(event) {
|
|
179
|
-
var _a;
|
|
180
164
|
event.stopPropagation();
|
|
181
|
-
|
|
165
|
+
this._swatches?.resetSelection();
|
|
182
166
|
const element = event.target;
|
|
183
167
|
const newColor = {
|
|
184
168
|
h: this.hue,
|
|
@@ -189,8 +173,7 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
|
|
|
189
173
|
this.setColor(newColor);
|
|
190
174
|
}
|
|
191
175
|
handleInputChange(event) {
|
|
192
|
-
|
|
193
|
-
(_a = this._swatches) == null ? void 0 : _a.resetSelection();
|
|
176
|
+
this._swatches?.resetSelection();
|
|
194
177
|
const target = event.target;
|
|
195
178
|
if (target.value) {
|
|
196
179
|
this.setColor(target.value);
|
|
@@ -201,11 +184,10 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
|
|
|
201
184
|
event.stopPropagation();
|
|
202
185
|
}
|
|
203
186
|
handleInputKeyDown(event) {
|
|
204
|
-
var _a;
|
|
205
187
|
if (event.key === "Enter") {
|
|
206
188
|
if (this.inputValue) {
|
|
207
189
|
this.setColor(this.inputValue);
|
|
208
|
-
|
|
190
|
+
this._swatches?.resetSelection();
|
|
209
191
|
this.inputValue = this.value;
|
|
210
192
|
setTimeout(() => this._input.select());
|
|
211
193
|
} else {
|
|
@@ -241,12 +223,17 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
|
|
|
241
223
|
});
|
|
242
224
|
}
|
|
243
225
|
setColor(colorString) {
|
|
244
|
-
|
|
245
|
-
const { h,
|
|
226
|
+
const colord2 = new j(colorString);
|
|
227
|
+
const { h, s, l, a } = colord2.toHsl();
|
|
246
228
|
this.hue = h;
|
|
247
229
|
this.saturation = s;
|
|
248
230
|
this.lightness = l;
|
|
249
231
|
this.alpha = this.opacity ? a * 100 : 100;
|
|
232
|
+
const hslaColor = colorString;
|
|
233
|
+
if (hslaColor && hslaColor.h) {
|
|
234
|
+
this.hue = hslaColor.h;
|
|
235
|
+
}
|
|
236
|
+
this._colord = colord2;
|
|
250
237
|
this._syncValues();
|
|
251
238
|
this.dispatchEvent(
|
|
252
239
|
new UUIColorPickerChangeEvent(UUIColorPickerChangeEvent.CHANGE)
|
|
@@ -259,6 +246,16 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
|
|
|
259
246
|
}
|
|
260
247
|
return this.uppercase ? string.toUpperCase() : string.toLowerCase();
|
|
261
248
|
}
|
|
249
|
+
/** Generates a hex string from HSL values. Hue must be 0-360. All other arguments must be 0-100. */
|
|
250
|
+
getHexString(hue, saturation, lightness, alpha = 100) {
|
|
251
|
+
const color = w(
|
|
252
|
+
`hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha / 100})`
|
|
253
|
+
);
|
|
254
|
+
if (!color.isValid()) {
|
|
255
|
+
return "";
|
|
256
|
+
}
|
|
257
|
+
return color.toHex();
|
|
258
|
+
}
|
|
262
259
|
_syncValues() {
|
|
263
260
|
this.inputValue = this.getFormattedValue(this.format);
|
|
264
261
|
this.value = this.inputValue;
|
|
@@ -274,6 +271,7 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
|
|
|
274
271
|
aria-disabled=${this.disabled ? "true" : "false"}>
|
|
275
272
|
<uui-color-area
|
|
276
273
|
.value="${this.value}"
|
|
274
|
+
.hue="${Math.round(this.hue)}"
|
|
277
275
|
?disabled=${this.disabled}
|
|
278
276
|
@change=${this.handleGridChange}>
|
|
279
277
|
</uui-color-area>
|
|
@@ -292,7 +290,11 @@ let UUIColorPickerElement = class extends LabelMixin("label", LitElement) {
|
|
|
292
290
|
class="opacity-slider"
|
|
293
291
|
.value=${Math.round(this.alpha)}
|
|
294
292
|
type="opacity"
|
|
295
|
-
.color=${this.
|
|
293
|
+
.color=${this.getHexString(
|
|
294
|
+
this.hue,
|
|
295
|
+
this.saturation,
|
|
296
|
+
this.lightness
|
|
297
|
+
)}
|
|
296
298
|
?disabled=${this.disabled}
|
|
297
299
|
@change=${this.handleAlphaChange}>
|
|
298
300
|
</uui-color-slider>
|
|
@@ -466,7 +468,11 @@ UUIColorPickerElement.styles = [
|
|
|
466
468
|
linear-gradient(45deg, transparent 75%, var(--uui-palette-grey,#c4c4c4) 75%),
|
|
467
469
|
linear-gradient(45deg, var(--uui-palette-grey,#c4c4c4) 25%, transparent 25%);
|
|
468
470
|
background-size: 10px 10px;
|
|
469
|
-
background-position:
|
|
471
|
+
background-position:
|
|
472
|
+
0 0,
|
|
473
|
+
0 0,
|
|
474
|
+
-5px -5px,
|
|
475
|
+
5px 5px;
|
|
470
476
|
}
|
|
471
477
|
|
|
472
478
|
.color-picker__preview-color--copied {
|
|
@@ -110,6 +110,8 @@ export declare class UUIColorPickerElement extends UUIColorPickerElement_base {
|
|
|
110
110
|
handleEyeDropper(): void;
|
|
111
111
|
setColor(colorString: string | HslaColor): boolean;
|
|
112
112
|
setLetterCase(string: string): string;
|
|
113
|
+
/** Generates a hex string from HSL values. Hue must be 0-360. All other arguments must be 0-100. */
|
|
114
|
+
private getHexString;
|
|
113
115
|
private _syncValues;
|
|
114
116
|
private _renderColorPicker;
|
|
115
117
|
private _renderSwatches;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umbraco-ui/uui-color-picker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Umbraco",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"custom-elements.json"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@umbraco-ui/uui-base": "1.
|
|
34
|
-
"@umbraco-ui/uui-popover-container": "1.
|
|
33
|
+
"@umbraco-ui/uui-base": "1.7.0",
|
|
34
|
+
"@umbraco-ui/uui-popover-container": "1.7.0",
|
|
35
35
|
"colord": "^2.9.3"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build": "npm run analyze && tsc --build
|
|
38
|
+
"build": "npm run analyze && tsc --build && rollup -c rollup.config.js",
|
|
39
39
|
"clean": "tsc --build --clean && rimraf -g dist lib/*.js lib/**/*.js *.tgz lib/**/*.d.ts custom-elements.json",
|
|
40
40
|
"analyze": "web-component-analyzer **/*.element.ts --outFile custom-elements.json"
|
|
41
41
|
},
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"homepage": "https://uui.umbraco.com/?path=/story/uui-color-picker",
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "1f139dc2b4ed9ba7b9fb1af5e934589d7c4d8f06"
|
|
47
47
|
}
|