wj-elements 0.0.11 → 0.0.13
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/dist/localize-20081fd1.js +55 -0
- package/dist/router-links-26e4a166.js +204 -0
- package/dist/style.css +2243 -2
- package/dist/wj-animation.js +35 -23
- package/dist/wj-aside.js +22 -16
- package/dist/wj-avatar.js +49 -30
- package/dist/wj-badge.js +22 -18
- package/dist/wj-breadcrumb.js +102 -50
- package/dist/wj-breadcrumbs.js +36 -19
- package/dist/wj-button-group.js +36 -22
- package/dist/wj-button.js +104 -39
- package/dist/wj-card-content.js +18 -14
- package/dist/wj-card-controls.js +18 -14
- package/dist/wj-card-header.js +20 -14
- package/dist/wj-card-subtitle.js +19 -15
- package/dist/wj-card-title.js +18 -14
- package/dist/wj-card.js +20 -14
- package/dist/wj-carousel-item.js +22 -16
- package/dist/wj-carousel.js +169 -92
- package/dist/wj-checkbox.js +46 -24
- package/dist/wj-chip.js +39 -21
- package/dist/wj-col.js +31 -17
- package/dist/wj-color-picker.js +877 -509
- package/dist/wj-container.js +20 -16
- package/dist/wj-copy-button.js +112 -64
- package/dist/wj-dialog.js +68 -42
- package/dist/wj-divider.js +20 -14
- package/dist/wj-dropdown.js +29 -17
- package/dist/wj-element.js +415 -241
- package/dist/wj-fetchAndParseCSS.js +49 -32
- package/dist/wj-file-upload-item.js +64 -38
- package/dist/wj-file-upload.js +237 -137
- package/dist/wj-footer.js +18 -14
- package/dist/wj-form.js +18 -14
- package/dist/wj-format-digital.js +40 -25
- package/dist/wj-grid.js +20 -16
- package/dist/wj-header.js +22 -16
- package/dist/wj-icon-picker.js +122 -68
- package/dist/wj-icon.js +144 -64
- package/dist/wj-img-comparer.js +72 -41
- package/dist/wj-img.js +31 -19
- package/dist/wj-infinite-scroll.js +90 -52
- package/dist/wj-input-file.js +50 -27
- package/dist/wj-input.js +169 -70
- package/dist/wj-item.js +34 -17
- package/dist/wj-label.js +21 -19
- package/dist/wj-list.js +20 -15
- package/dist/wj-main.js +18 -14
- package/dist/wj-masonry.js +140 -83
- package/dist/wj-master.js +492 -350
- package/dist/wj-menu-button.js +19 -15
- package/dist/wj-menu-item.js +150 -64
- package/dist/wj-menu-label.js +21 -17
- package/dist/wj-menu.js +24 -18
- package/dist/wj-popup.js +1140 -712
- package/dist/wj-progress-bar.js +100 -40
- package/dist/wj-radio-group.js +38 -25
- package/dist/wj-radio.js +46 -22
- package/dist/wj-rate.js +121 -71
- package/dist/wj-relative-time.js +48 -24
- package/dist/wj-route.js +11 -8
- package/dist/wj-router-link.js +22 -17
- package/dist/wj-router-outlet.js +135 -71
- package/dist/wj-routerx.js +1124 -641
- package/dist/wj-row.js +21 -19
- package/dist/wj-slider.js +97 -55
- package/dist/wj-split-view.js +81 -43
- package/dist/wj-store.js +195 -110
- package/dist/wj-textarea.js +86 -37
- package/dist/wj-thumbnail.js +19 -15
- package/dist/wj-toast.js +87 -34
- package/dist/wj-toggle.js +42 -24
- package/dist/wj-toolbar-action.js +27 -16
- package/dist/wj-toolbar.js +26 -19
- package/dist/wj-tooltip.js +40 -24
- package/dist/wj-visually-hidden.js +18 -14
- package/package.json +1 -1
- package/dist/localize-762a9f0f.js +0 -43
- package/dist/router-links-e0087f84.js +0 -146
package/dist/wj-color-picker.js
CHANGED
|
@@ -1,94 +1,130 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import WJElement, { event } from "./wj-element.js";
|
|
5
8
|
import "./wj-store.js";
|
|
6
|
-
function
|
|
9
|
+
function _typeof(obj) {
|
|
7
10
|
"@babel/helpers - typeof";
|
|
8
|
-
return
|
|
9
|
-
return typeof
|
|
10
|
-
} : function(
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
}
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
12
|
+
return typeof obj2;
|
|
13
|
+
} : function(obj2) {
|
|
14
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
15
|
+
}, _typeof(obj);
|
|
16
|
+
}
|
|
17
|
+
var trimLeft = /^\s+/;
|
|
18
|
+
var trimRight = /\s+$/;
|
|
19
|
+
function tinycolor(color, opts) {
|
|
20
|
+
color = color ? color : "";
|
|
21
|
+
opts = opts || {};
|
|
22
|
+
if (color instanceof tinycolor) {
|
|
23
|
+
return color;
|
|
24
|
+
}
|
|
25
|
+
if (!(this instanceof tinycolor)) {
|
|
26
|
+
return new tinycolor(color, opts);
|
|
27
|
+
}
|
|
28
|
+
var rgb = inputToRGB(color);
|
|
29
|
+
this._originalInput = color, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format;
|
|
30
|
+
this._gradientType = opts.gradientType;
|
|
31
|
+
if (this._r < 1)
|
|
32
|
+
this._r = Math.round(this._r);
|
|
33
|
+
if (this._g < 1)
|
|
34
|
+
this._g = Math.round(this._g);
|
|
35
|
+
if (this._b < 1)
|
|
36
|
+
this._b = Math.round(this._b);
|
|
37
|
+
this._ok = rgb.ok;
|
|
38
|
+
}
|
|
39
|
+
tinycolor.prototype = {
|
|
40
|
+
isDark: function isDark() {
|
|
25
41
|
return this.getBrightness() < 128;
|
|
26
42
|
},
|
|
27
|
-
isLight: function() {
|
|
43
|
+
isLight: function isLight() {
|
|
28
44
|
return !this.isDark();
|
|
29
45
|
},
|
|
30
|
-
isValid: function() {
|
|
46
|
+
isValid: function isValid() {
|
|
31
47
|
return this._ok;
|
|
32
48
|
},
|
|
33
|
-
getOriginalInput: function() {
|
|
49
|
+
getOriginalInput: function getOriginalInput() {
|
|
34
50
|
return this._originalInput;
|
|
35
51
|
},
|
|
36
|
-
getFormat: function() {
|
|
52
|
+
getFormat: function getFormat() {
|
|
37
53
|
return this._format;
|
|
38
54
|
},
|
|
39
|
-
getAlpha: function() {
|
|
55
|
+
getAlpha: function getAlpha() {
|
|
40
56
|
return this._a;
|
|
41
57
|
},
|
|
42
|
-
getBrightness: function() {
|
|
43
|
-
var
|
|
44
|
-
return (
|
|
58
|
+
getBrightness: function getBrightness() {
|
|
59
|
+
var rgb = this.toRgb();
|
|
60
|
+
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1e3;
|
|
45
61
|
},
|
|
46
|
-
getLuminance: function() {
|
|
47
|
-
var
|
|
48
|
-
|
|
62
|
+
getLuminance: function getLuminance() {
|
|
63
|
+
var rgb = this.toRgb();
|
|
64
|
+
var RsRGB, GsRGB, BsRGB, R, G, B;
|
|
65
|
+
RsRGB = rgb.r / 255;
|
|
66
|
+
GsRGB = rgb.g / 255;
|
|
67
|
+
BsRGB = rgb.b / 255;
|
|
68
|
+
if (RsRGB <= 0.03928)
|
|
69
|
+
R = RsRGB / 12.92;
|
|
70
|
+
else
|
|
71
|
+
R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
72
|
+
if (GsRGB <= 0.03928)
|
|
73
|
+
G = GsRGB / 12.92;
|
|
74
|
+
else
|
|
75
|
+
G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
76
|
+
if (BsRGB <= 0.03928)
|
|
77
|
+
B = BsRGB / 12.92;
|
|
78
|
+
else
|
|
79
|
+
B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
80
|
+
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
49
81
|
},
|
|
50
|
-
setAlpha: function(
|
|
51
|
-
|
|
82
|
+
setAlpha: function setAlpha(value) {
|
|
83
|
+
this._a = boundAlpha(value);
|
|
84
|
+
this._roundA = Math.round(100 * this._a) / 100;
|
|
85
|
+
return this;
|
|
52
86
|
},
|
|
53
|
-
toHsv: function() {
|
|
54
|
-
var
|
|
87
|
+
toHsv: function toHsv() {
|
|
88
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
55
89
|
return {
|
|
56
|
-
h:
|
|
57
|
-
s:
|
|
58
|
-
v:
|
|
90
|
+
h: hsv.h * 360,
|
|
91
|
+
s: hsv.s,
|
|
92
|
+
v: hsv.v,
|
|
59
93
|
a: this._a
|
|
60
94
|
};
|
|
61
95
|
},
|
|
62
|
-
toHsvString: function() {
|
|
63
|
-
var
|
|
64
|
-
|
|
96
|
+
toHsvString: function toHsvString() {
|
|
97
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
98
|
+
var h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100);
|
|
99
|
+
return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
|
|
65
100
|
},
|
|
66
|
-
toHsl: function() {
|
|
67
|
-
var
|
|
101
|
+
toHsl: function toHsl() {
|
|
102
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
68
103
|
return {
|
|
69
|
-
h:
|
|
70
|
-
s:
|
|
71
|
-
l:
|
|
104
|
+
h: hsl.h * 360,
|
|
105
|
+
s: hsl.s,
|
|
106
|
+
l: hsl.l,
|
|
72
107
|
a: this._a
|
|
73
108
|
};
|
|
74
109
|
},
|
|
75
|
-
toHslString: function() {
|
|
76
|
-
var
|
|
77
|
-
|
|
110
|
+
toHslString: function toHslString() {
|
|
111
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
112
|
+
var h = Math.round(hsl.h * 360), s = Math.round(hsl.s * 100), l = Math.round(hsl.l * 100);
|
|
113
|
+
return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
|
|
78
114
|
},
|
|
79
|
-
toHex: function(
|
|
80
|
-
return
|
|
115
|
+
toHex: function toHex(allow3Char) {
|
|
116
|
+
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
|
81
117
|
},
|
|
82
|
-
toHexString: function(
|
|
83
|
-
return "#" + this.toHex(
|
|
118
|
+
toHexString: function toHexString(allow3Char) {
|
|
119
|
+
return "#" + this.toHex(allow3Char);
|
|
84
120
|
},
|
|
85
|
-
toHex8: function(
|
|
86
|
-
return
|
|
121
|
+
toHex8: function toHex8(allow4Char) {
|
|
122
|
+
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
|
|
87
123
|
},
|
|
88
|
-
toHex8String: function(
|
|
89
|
-
return "#" + this.toHex8(
|
|
124
|
+
toHex8String: function toHex8String(allow4Char) {
|
|
125
|
+
return "#" + this.toHex8(allow4Char);
|
|
90
126
|
},
|
|
91
|
-
toRgb: function() {
|
|
127
|
+
toRgb: function toRgb() {
|
|
92
128
|
return {
|
|
93
129
|
r: Math.round(this._r),
|
|
94
130
|
g: Math.round(this._g),
|
|
@@ -96,339 +132,513 @@ s.prototype = {
|
|
|
96
132
|
a: this._a
|
|
97
133
|
};
|
|
98
134
|
},
|
|
99
|
-
toRgbString: function() {
|
|
135
|
+
toRgbString: function toRgbString() {
|
|
100
136
|
return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
|
|
101
137
|
},
|
|
102
|
-
toPercentageRgb: function() {
|
|
138
|
+
toPercentageRgb: function toPercentageRgb() {
|
|
103
139
|
return {
|
|
104
|
-
r: Math.round(
|
|
105
|
-
g: Math.round(
|
|
106
|
-
b: Math.round(
|
|
140
|
+
r: Math.round(bound01(this._r, 255) * 100) + "%",
|
|
141
|
+
g: Math.round(bound01(this._g, 255) * 100) + "%",
|
|
142
|
+
b: Math.round(bound01(this._b, 255) * 100) + "%",
|
|
107
143
|
a: this._a
|
|
108
144
|
};
|
|
109
145
|
},
|
|
110
|
-
toPercentageRgbString: function() {
|
|
111
|
-
return this._a == 1 ? "rgb(" + Math.round(
|
|
146
|
+
toPercentageRgbString: function toPercentageRgbString() {
|
|
147
|
+
return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
|
|
112
148
|
},
|
|
113
|
-
toName: function() {
|
|
114
|
-
|
|
149
|
+
toName: function toName() {
|
|
150
|
+
if (this._a === 0) {
|
|
151
|
+
return "transparent";
|
|
152
|
+
}
|
|
153
|
+
if (this._a < 1) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
|
115
157
|
},
|
|
116
|
-
toFilter: function(
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
158
|
+
toFilter: function toFilter(secondColor) {
|
|
159
|
+
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
|
|
160
|
+
var secondHex8String = hex8String;
|
|
161
|
+
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
162
|
+
if (secondColor) {
|
|
163
|
+
var s = tinycolor(secondColor);
|
|
164
|
+
secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
|
|
121
165
|
}
|
|
122
|
-
return "progid:DXImageTransform.Microsoft.gradient(" +
|
|
166
|
+
return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
|
|
123
167
|
},
|
|
124
|
-
toString: function(
|
|
125
|
-
var
|
|
126
|
-
|
|
127
|
-
var
|
|
128
|
-
|
|
168
|
+
toString: function toString(format) {
|
|
169
|
+
var formatSet = !!format;
|
|
170
|
+
format = format || this._format;
|
|
171
|
+
var formattedString = false;
|
|
172
|
+
var hasAlpha = this._a < 1 && this._a >= 0;
|
|
173
|
+
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
|
|
174
|
+
if (needsAlphaFormat) {
|
|
175
|
+
if (format === "name" && this._a === 0) {
|
|
176
|
+
return this.toName();
|
|
177
|
+
}
|
|
178
|
+
return this.toRgbString();
|
|
179
|
+
}
|
|
180
|
+
if (format === "rgb") {
|
|
181
|
+
formattedString = this.toRgbString();
|
|
182
|
+
}
|
|
183
|
+
if (format === "prgb") {
|
|
184
|
+
formattedString = this.toPercentageRgbString();
|
|
185
|
+
}
|
|
186
|
+
if (format === "hex" || format === "hex6") {
|
|
187
|
+
formattedString = this.toHexString();
|
|
188
|
+
}
|
|
189
|
+
if (format === "hex3") {
|
|
190
|
+
formattedString = this.toHexString(true);
|
|
191
|
+
}
|
|
192
|
+
if (format === "hex4") {
|
|
193
|
+
formattedString = this.toHex8String(true);
|
|
194
|
+
}
|
|
195
|
+
if (format === "hex8") {
|
|
196
|
+
formattedString = this.toHex8String();
|
|
197
|
+
}
|
|
198
|
+
if (format === "name") {
|
|
199
|
+
formattedString = this.toName();
|
|
200
|
+
}
|
|
201
|
+
if (format === "hsl") {
|
|
202
|
+
formattedString = this.toHslString();
|
|
203
|
+
}
|
|
204
|
+
if (format === "hsv") {
|
|
205
|
+
formattedString = this.toHsvString();
|
|
206
|
+
}
|
|
207
|
+
return formattedString || this.toHexString();
|
|
129
208
|
},
|
|
130
|
-
clone: function() {
|
|
131
|
-
return
|
|
209
|
+
clone: function clone() {
|
|
210
|
+
return tinycolor(this.toString());
|
|
132
211
|
},
|
|
133
|
-
_applyModification: function(
|
|
134
|
-
var
|
|
135
|
-
|
|
212
|
+
_applyModification: function _applyModification(fn, args) {
|
|
213
|
+
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
|
214
|
+
this._r = color._r;
|
|
215
|
+
this._g = color._g;
|
|
216
|
+
this._b = color._b;
|
|
217
|
+
this.setAlpha(color._a);
|
|
218
|
+
return this;
|
|
136
219
|
},
|
|
137
|
-
lighten: function() {
|
|
138
|
-
return this._applyModification(
|
|
220
|
+
lighten: function lighten() {
|
|
221
|
+
return this._applyModification(_lighten, arguments);
|
|
139
222
|
},
|
|
140
|
-
brighten: function() {
|
|
141
|
-
return this._applyModification(
|
|
223
|
+
brighten: function brighten() {
|
|
224
|
+
return this._applyModification(_brighten, arguments);
|
|
142
225
|
},
|
|
143
|
-
darken: function() {
|
|
144
|
-
return this._applyModification(
|
|
226
|
+
darken: function darken() {
|
|
227
|
+
return this._applyModification(_darken, arguments);
|
|
145
228
|
},
|
|
146
|
-
desaturate: function() {
|
|
147
|
-
return this._applyModification(
|
|
229
|
+
desaturate: function desaturate() {
|
|
230
|
+
return this._applyModification(_desaturate, arguments);
|
|
148
231
|
},
|
|
149
|
-
saturate: function() {
|
|
150
|
-
return this._applyModification(
|
|
232
|
+
saturate: function saturate() {
|
|
233
|
+
return this._applyModification(_saturate, arguments);
|
|
151
234
|
},
|
|
152
|
-
greyscale: function() {
|
|
153
|
-
return this._applyModification(
|
|
235
|
+
greyscale: function greyscale() {
|
|
236
|
+
return this._applyModification(_greyscale, arguments);
|
|
154
237
|
},
|
|
155
|
-
spin: function() {
|
|
156
|
-
return this._applyModification(
|
|
238
|
+
spin: function spin() {
|
|
239
|
+
return this._applyModification(_spin, arguments);
|
|
157
240
|
},
|
|
158
|
-
_applyCombination: function(
|
|
159
|
-
return
|
|
241
|
+
_applyCombination: function _applyCombination(fn, args) {
|
|
242
|
+
return fn.apply(null, [this].concat([].slice.call(args)));
|
|
160
243
|
},
|
|
161
|
-
analogous: function() {
|
|
162
|
-
return this._applyCombination(
|
|
244
|
+
analogous: function analogous() {
|
|
245
|
+
return this._applyCombination(_analogous, arguments);
|
|
163
246
|
},
|
|
164
|
-
complement: function() {
|
|
165
|
-
return this._applyCombination(
|
|
247
|
+
complement: function complement() {
|
|
248
|
+
return this._applyCombination(_complement, arguments);
|
|
166
249
|
},
|
|
167
|
-
monochromatic: function() {
|
|
168
|
-
return this._applyCombination(
|
|
250
|
+
monochromatic: function monochromatic() {
|
|
251
|
+
return this._applyCombination(_monochromatic, arguments);
|
|
169
252
|
},
|
|
170
|
-
splitcomplement: function() {
|
|
171
|
-
return this._applyCombination(
|
|
253
|
+
splitcomplement: function splitcomplement() {
|
|
254
|
+
return this._applyCombination(_splitcomplement, arguments);
|
|
172
255
|
},
|
|
173
256
|
// Disabled until https://github.com/bgrins/TinyColor/issues/254
|
|
174
257
|
// polyad: function (number) {
|
|
175
258
|
// return this._applyCombination(polyad, [number]);
|
|
176
259
|
// },
|
|
177
|
-
triad: function() {
|
|
178
|
-
return this._applyCombination(
|
|
260
|
+
triad: function triad() {
|
|
261
|
+
return this._applyCombination(polyad, [3]);
|
|
179
262
|
},
|
|
180
|
-
tetrad: function() {
|
|
181
|
-
return this._applyCombination(
|
|
263
|
+
tetrad: function tetrad() {
|
|
264
|
+
return this._applyCombination(polyad, [4]);
|
|
182
265
|
}
|
|
183
266
|
};
|
|
184
|
-
|
|
185
|
-
if (
|
|
186
|
-
var
|
|
187
|
-
for (var i in
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
267
|
+
tinycolor.fromRatio = function(color, opts) {
|
|
268
|
+
if (_typeof(color) == "object") {
|
|
269
|
+
var newColor = {};
|
|
270
|
+
for (var i in color) {
|
|
271
|
+
if (color.hasOwnProperty(i)) {
|
|
272
|
+
if (i === "a") {
|
|
273
|
+
newColor[i] = color[i];
|
|
274
|
+
} else {
|
|
275
|
+
newColor[i] = convertToPercentage(color[i]);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
color = newColor;
|
|
280
|
+
}
|
|
281
|
+
return tinycolor(color, opts);
|
|
192
282
|
};
|
|
193
|
-
function
|
|
194
|
-
var
|
|
283
|
+
function inputToRGB(color) {
|
|
284
|
+
var rgb = {
|
|
195
285
|
r: 0,
|
|
196
286
|
g: 0,
|
|
197
287
|
b: 0
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
288
|
+
};
|
|
289
|
+
var a = 1;
|
|
290
|
+
var s = null;
|
|
291
|
+
var v = null;
|
|
292
|
+
var l = null;
|
|
293
|
+
var ok = false;
|
|
294
|
+
var format = false;
|
|
295
|
+
if (typeof color == "string") {
|
|
296
|
+
color = stringInputToObject(color);
|
|
297
|
+
}
|
|
298
|
+
if (_typeof(color) == "object") {
|
|
299
|
+
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
|
300
|
+
rgb = rgbToRgb(color.r, color.g, color.b);
|
|
301
|
+
ok = true;
|
|
302
|
+
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
|
303
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
|
304
|
+
s = convertToPercentage(color.s);
|
|
305
|
+
v = convertToPercentage(color.v);
|
|
306
|
+
rgb = hsvToRgb(color.h, s, v);
|
|
307
|
+
ok = true;
|
|
308
|
+
format = "hsv";
|
|
309
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
|
310
|
+
s = convertToPercentage(color.s);
|
|
311
|
+
l = convertToPercentage(color.l);
|
|
312
|
+
rgb = hslToRgb(color.h, s, l);
|
|
313
|
+
ok = true;
|
|
314
|
+
format = "hsl";
|
|
315
|
+
}
|
|
316
|
+
if (color.hasOwnProperty("a")) {
|
|
317
|
+
a = color.a;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
a = boundAlpha(a);
|
|
321
|
+
return {
|
|
322
|
+
ok,
|
|
323
|
+
format: color.format || format,
|
|
324
|
+
r: Math.min(255, Math.max(rgb.r, 0)),
|
|
325
|
+
g: Math.min(255, Math.max(rgb.g, 0)),
|
|
326
|
+
b: Math.min(255, Math.max(rgb.b, 0)),
|
|
327
|
+
a
|
|
206
328
|
};
|
|
207
329
|
}
|
|
208
|
-
function
|
|
330
|
+
function rgbToRgb(r, g, b) {
|
|
209
331
|
return {
|
|
210
|
-
r:
|
|
211
|
-
g:
|
|
212
|
-
b:
|
|
332
|
+
r: bound01(r, 255) * 255,
|
|
333
|
+
g: bound01(g, 255) * 255,
|
|
334
|
+
b: bound01(b, 255) * 255
|
|
213
335
|
};
|
|
214
336
|
}
|
|
215
|
-
function
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
337
|
+
function rgbToHsl(r, g, b) {
|
|
338
|
+
r = bound01(r, 255);
|
|
339
|
+
g = bound01(g, 255);
|
|
340
|
+
b = bound01(b, 255);
|
|
341
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
342
|
+
var h, s, l = (max + min) / 2;
|
|
343
|
+
if (max == min) {
|
|
344
|
+
h = s = 0;
|
|
345
|
+
} else {
|
|
346
|
+
var d = max - min;
|
|
347
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
348
|
+
switch (max) {
|
|
226
349
|
case r:
|
|
227
|
-
|
|
350
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
228
351
|
break;
|
|
229
|
-
case
|
|
230
|
-
|
|
352
|
+
case g:
|
|
353
|
+
h = (b - r) / d + 2;
|
|
354
|
+
break;
|
|
355
|
+
case b:
|
|
356
|
+
h = (r - g) / d + 4;
|
|
231
357
|
break;
|
|
232
358
|
}
|
|
233
|
-
|
|
359
|
+
h /= 6;
|
|
234
360
|
}
|
|
235
361
|
return {
|
|
236
|
-
h
|
|
237
|
-
s
|
|
238
|
-
l
|
|
362
|
+
h,
|
|
363
|
+
s,
|
|
364
|
+
l
|
|
239
365
|
};
|
|
240
366
|
}
|
|
241
|
-
function
|
|
242
|
-
var
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
367
|
+
function hslToRgb(h, s, l) {
|
|
368
|
+
var r, g, b;
|
|
369
|
+
h = bound01(h, 360);
|
|
370
|
+
s = bound01(s, 100);
|
|
371
|
+
l = bound01(l, 100);
|
|
372
|
+
function hue2rgb(p2, q2, t) {
|
|
373
|
+
if (t < 0)
|
|
374
|
+
t += 1;
|
|
375
|
+
if (t > 1)
|
|
376
|
+
t -= 1;
|
|
377
|
+
if (t < 1 / 6)
|
|
378
|
+
return p2 + (q2 - p2) * 6 * t;
|
|
379
|
+
if (t < 1 / 2)
|
|
380
|
+
return q2;
|
|
381
|
+
if (t < 2 / 3)
|
|
382
|
+
return p2 + (q2 - p2) * (2 / 3 - t) * 6;
|
|
383
|
+
return p2;
|
|
246
384
|
}
|
|
247
|
-
if (
|
|
248
|
-
|
|
249
|
-
else {
|
|
250
|
-
var
|
|
251
|
-
|
|
385
|
+
if (s === 0) {
|
|
386
|
+
r = g = b = l;
|
|
387
|
+
} else {
|
|
388
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
389
|
+
var p = 2 * l - q;
|
|
390
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
391
|
+
g = hue2rgb(p, q, h);
|
|
392
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
252
393
|
}
|
|
253
394
|
return {
|
|
254
|
-
r:
|
|
255
|
-
g:
|
|
256
|
-
b:
|
|
395
|
+
r: r * 255,
|
|
396
|
+
g: g * 255,
|
|
397
|
+
b: b * 255
|
|
257
398
|
};
|
|
258
399
|
}
|
|
259
|
-
function
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
400
|
+
function rgbToHsv(r, g, b) {
|
|
401
|
+
r = bound01(r, 255);
|
|
402
|
+
g = bound01(g, 255);
|
|
403
|
+
b = bound01(b, 255);
|
|
404
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
405
|
+
var h, s, v = max;
|
|
406
|
+
var d = max - min;
|
|
407
|
+
s = max === 0 ? 0 : d / max;
|
|
408
|
+
if (max == min) {
|
|
409
|
+
h = 0;
|
|
410
|
+
} else {
|
|
411
|
+
switch (max) {
|
|
269
412
|
case r:
|
|
270
|
-
|
|
413
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
414
|
+
break;
|
|
415
|
+
case g:
|
|
416
|
+
h = (b - r) / d + 2;
|
|
271
417
|
break;
|
|
272
|
-
case
|
|
273
|
-
|
|
418
|
+
case b:
|
|
419
|
+
h = (r - g) / d + 4;
|
|
274
420
|
break;
|
|
275
421
|
}
|
|
276
|
-
|
|
422
|
+
h /= 6;
|
|
277
423
|
}
|
|
278
424
|
return {
|
|
279
|
-
h
|
|
280
|
-
s
|
|
281
|
-
v
|
|
425
|
+
h,
|
|
426
|
+
s,
|
|
427
|
+
v
|
|
282
428
|
};
|
|
283
429
|
}
|
|
284
|
-
function
|
|
285
|
-
|
|
286
|
-
|
|
430
|
+
function hsvToRgb(h, s, v) {
|
|
431
|
+
h = bound01(h, 360) * 6;
|
|
432
|
+
s = bound01(s, 100);
|
|
433
|
+
v = bound01(v, 100);
|
|
434
|
+
var i = Math.floor(h), f = h - i, p = v * (1 - s), q = v * (1 - f * s), t = v * (1 - (1 - f) * s), mod = i % 6, r = [v, q, p, p, t, v][mod], g = [t, v, v, q, p, p][mod], b = [p, p, t, v, v, q][mod];
|
|
287
435
|
return {
|
|
288
|
-
r:
|
|
436
|
+
r: r * 255,
|
|
289
437
|
g: g * 255,
|
|
290
|
-
b:
|
|
438
|
+
b: b * 255
|
|
291
439
|
};
|
|
292
440
|
}
|
|
293
|
-
function
|
|
294
|
-
var
|
|
295
|
-
|
|
441
|
+
function rgbToHex(r, g, b, allow3Char) {
|
|
442
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
443
|
+
if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
|
|
444
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
445
|
+
}
|
|
446
|
+
return hex.join("");
|
|
296
447
|
}
|
|
297
|
-
function
|
|
298
|
-
var
|
|
299
|
-
|
|
448
|
+
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
449
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
|
|
450
|
+
if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
|
|
451
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
|
|
452
|
+
}
|
|
453
|
+
return hex.join("");
|
|
300
454
|
}
|
|
301
|
-
function
|
|
302
|
-
var
|
|
303
|
-
return
|
|
455
|
+
function rgbaToArgbHex(r, g, b, a) {
|
|
456
|
+
var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
457
|
+
return hex.join("");
|
|
304
458
|
}
|
|
305
|
-
|
|
306
|
-
|
|
459
|
+
tinycolor.equals = function(color1, color2) {
|
|
460
|
+
if (!color1 || !color2)
|
|
461
|
+
return false;
|
|
462
|
+
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
307
463
|
};
|
|
308
|
-
|
|
309
|
-
return
|
|
464
|
+
tinycolor.random = function() {
|
|
465
|
+
return tinycolor.fromRatio({
|
|
310
466
|
r: Math.random(),
|
|
311
467
|
g: Math.random(),
|
|
312
468
|
b: Math.random()
|
|
313
469
|
});
|
|
314
470
|
};
|
|
315
|
-
function
|
|
316
|
-
|
|
317
|
-
var
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
return
|
|
346
|
-
}
|
|
347
|
-
function
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
471
|
+
function _desaturate(color, amount) {
|
|
472
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
473
|
+
var hsl = tinycolor(color).toHsl();
|
|
474
|
+
hsl.s -= amount / 100;
|
|
475
|
+
hsl.s = clamp01(hsl.s);
|
|
476
|
+
return tinycolor(hsl);
|
|
477
|
+
}
|
|
478
|
+
function _saturate(color, amount) {
|
|
479
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
480
|
+
var hsl = tinycolor(color).toHsl();
|
|
481
|
+
hsl.s += amount / 100;
|
|
482
|
+
hsl.s = clamp01(hsl.s);
|
|
483
|
+
return tinycolor(hsl);
|
|
484
|
+
}
|
|
485
|
+
function _greyscale(color) {
|
|
486
|
+
return tinycolor(color).desaturate(100);
|
|
487
|
+
}
|
|
488
|
+
function _lighten(color, amount) {
|
|
489
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
490
|
+
var hsl = tinycolor(color).toHsl();
|
|
491
|
+
hsl.l += amount / 100;
|
|
492
|
+
hsl.l = clamp01(hsl.l);
|
|
493
|
+
return tinycolor(hsl);
|
|
494
|
+
}
|
|
495
|
+
function _brighten(color, amount) {
|
|
496
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
497
|
+
var rgb = tinycolor(color).toRgb();
|
|
498
|
+
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
|
499
|
+
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
|
500
|
+
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
|
501
|
+
return tinycolor(rgb);
|
|
502
|
+
}
|
|
503
|
+
function _darken(color, amount) {
|
|
504
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
505
|
+
var hsl = tinycolor(color).toHsl();
|
|
506
|
+
hsl.l -= amount / 100;
|
|
507
|
+
hsl.l = clamp01(hsl.l);
|
|
508
|
+
return tinycolor(hsl);
|
|
509
|
+
}
|
|
510
|
+
function _spin(color, amount) {
|
|
511
|
+
var hsl = tinycolor(color).toHsl();
|
|
512
|
+
var hue = (hsl.h + amount) % 360;
|
|
513
|
+
hsl.h = hue < 0 ? 360 + hue : hue;
|
|
514
|
+
return tinycolor(hsl);
|
|
515
|
+
}
|
|
516
|
+
function _complement(color) {
|
|
517
|
+
var hsl = tinycolor(color).toHsl();
|
|
518
|
+
hsl.h = (hsl.h + 180) % 360;
|
|
519
|
+
return tinycolor(hsl);
|
|
520
|
+
}
|
|
521
|
+
function polyad(color, number) {
|
|
522
|
+
if (isNaN(number) || number <= 0) {
|
|
353
523
|
throw new Error("Argument to polyad must be a positive number");
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
524
|
+
}
|
|
525
|
+
var hsl = tinycolor(color).toHsl();
|
|
526
|
+
var result = [tinycolor(color)];
|
|
527
|
+
var step = 360 / number;
|
|
528
|
+
for (var i = 1; i < number; i++) {
|
|
529
|
+
result.push(tinycolor({
|
|
530
|
+
h: (hsl.h + i * step) % 360,
|
|
531
|
+
s: hsl.s,
|
|
532
|
+
l: hsl.l
|
|
359
533
|
}));
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
534
|
+
}
|
|
535
|
+
return result;
|
|
536
|
+
}
|
|
537
|
+
function _splitcomplement(color) {
|
|
538
|
+
var hsl = tinycolor(color).toHsl();
|
|
539
|
+
var h = hsl.h;
|
|
540
|
+
return [tinycolor(color), tinycolor({
|
|
541
|
+
h: (h + 72) % 360,
|
|
542
|
+
s: hsl.s,
|
|
543
|
+
l: hsl.l
|
|
544
|
+
}), tinycolor({
|
|
545
|
+
h: (h + 216) % 360,
|
|
546
|
+
s: hsl.s,
|
|
547
|
+
l: hsl.l
|
|
372
548
|
})];
|
|
373
549
|
}
|
|
374
|
-
function
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
550
|
+
function _analogous(color, results, slices) {
|
|
551
|
+
results = results || 6;
|
|
552
|
+
slices = slices || 30;
|
|
553
|
+
var hsl = tinycolor(color).toHsl();
|
|
554
|
+
var part = 360 / slices;
|
|
555
|
+
var ret = [tinycolor(color)];
|
|
556
|
+
for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; ) {
|
|
557
|
+
hsl.h = (hsl.h + part) % 360;
|
|
558
|
+
ret.push(tinycolor(hsl));
|
|
559
|
+
}
|
|
560
|
+
return ret;
|
|
380
561
|
}
|
|
381
|
-
function
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
562
|
+
function _monochromatic(color, results) {
|
|
563
|
+
results = results || 6;
|
|
564
|
+
var hsv = tinycolor(color).toHsv();
|
|
565
|
+
var h = hsv.h, s = hsv.s, v = hsv.v;
|
|
566
|
+
var ret = [];
|
|
567
|
+
var modification = 1 / results;
|
|
568
|
+
while (results--) {
|
|
569
|
+
ret.push(tinycolor({
|
|
570
|
+
h,
|
|
571
|
+
s,
|
|
572
|
+
v
|
|
573
|
+
}));
|
|
574
|
+
v = (v + modification) % 1;
|
|
575
|
+
}
|
|
576
|
+
return ret;
|
|
577
|
+
}
|
|
578
|
+
tinycolor.mix = function(color1, color2, amount) {
|
|
579
|
+
amount = amount === 0 ? 0 : amount || 50;
|
|
580
|
+
var rgb1 = tinycolor(color1).toRgb();
|
|
581
|
+
var rgb2 = tinycolor(color2).toRgb();
|
|
582
|
+
var p = amount / 100;
|
|
583
|
+
var rgba = {
|
|
584
|
+
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
|
585
|
+
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
|
586
|
+
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
|
587
|
+
a: (rgb2.a - rgb1.a) * p + rgb1.a
|
|
398
588
|
};
|
|
399
|
-
return
|
|
589
|
+
return tinycolor(rgba);
|
|
400
590
|
};
|
|
401
|
-
|
|
402
|
-
var
|
|
403
|
-
|
|
591
|
+
tinycolor.readability = function(color1, color2) {
|
|
592
|
+
var c1 = tinycolor(color1);
|
|
593
|
+
var c2 = tinycolor(color2);
|
|
594
|
+
return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
|
|
404
595
|
};
|
|
405
|
-
|
|
406
|
-
var
|
|
407
|
-
|
|
596
|
+
tinycolor.isReadable = function(color1, color2, wcag2) {
|
|
597
|
+
var readability = tinycolor.readability(color1, color2);
|
|
598
|
+
var wcag2Parms, out;
|
|
599
|
+
out = false;
|
|
600
|
+
wcag2Parms = validateWCAG2Parms(wcag2);
|
|
601
|
+
switch (wcag2Parms.level + wcag2Parms.size) {
|
|
408
602
|
case "AAsmall":
|
|
409
603
|
case "AAAlarge":
|
|
410
|
-
|
|
604
|
+
out = readability >= 4.5;
|
|
411
605
|
break;
|
|
412
606
|
case "AAlarge":
|
|
413
|
-
|
|
607
|
+
out = readability >= 3;
|
|
414
608
|
break;
|
|
415
609
|
case "AAAsmall":
|
|
416
|
-
|
|
610
|
+
out = readability >= 7;
|
|
417
611
|
break;
|
|
418
612
|
}
|
|
419
|
-
return
|
|
613
|
+
return out;
|
|
420
614
|
};
|
|
421
|
-
|
|
422
|
-
var
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
615
|
+
tinycolor.mostReadable = function(baseColor, colorList, args) {
|
|
616
|
+
var bestColor = null;
|
|
617
|
+
var bestScore = 0;
|
|
618
|
+
var readability;
|
|
619
|
+
var includeFallbackColors, level, size;
|
|
620
|
+
args = args || {};
|
|
621
|
+
includeFallbackColors = args.includeFallbackColors;
|
|
622
|
+
level = args.level;
|
|
623
|
+
size = args.size;
|
|
624
|
+
for (var i = 0; i < colorList.length; i++) {
|
|
625
|
+
readability = tinycolor.readability(baseColor, colorList[i]);
|
|
626
|
+
if (readability > bestScore) {
|
|
627
|
+
bestScore = readability;
|
|
628
|
+
bestColor = tinycolor(colorList[i]);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
if (tinycolor.isReadable(baseColor, bestColor, {
|
|
632
|
+
level,
|
|
633
|
+
size
|
|
634
|
+
}) || !includeFallbackColors) {
|
|
635
|
+
return bestColor;
|
|
636
|
+
} else {
|
|
637
|
+
args.includeFallbackColors = false;
|
|
638
|
+
return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
|
|
639
|
+
}
|
|
430
640
|
};
|
|
431
|
-
var
|
|
641
|
+
var names = tinycolor.names = {
|
|
432
642
|
aliceblue: "f0f8ff",
|
|
433
643
|
antiquewhite: "faebd7",
|
|
434
644
|
aqua: "0ff",
|
|
@@ -578,70 +788,94 @@ var j = s.names = {
|
|
|
578
788
|
whitesmoke: "f5f5f5",
|
|
579
789
|
yellow: "ff0",
|
|
580
790
|
yellowgreen: "9acd32"
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
791
|
+
};
|
|
792
|
+
var hexNames = tinycolor.hexNames = flip(names);
|
|
793
|
+
function flip(o) {
|
|
794
|
+
var flipped = {};
|
|
795
|
+
for (var i in o) {
|
|
796
|
+
if (o.hasOwnProperty(i)) {
|
|
797
|
+
flipped[o[i]] = i;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return flipped;
|
|
587
801
|
}
|
|
588
|
-
function
|
|
589
|
-
|
|
802
|
+
function boundAlpha(a) {
|
|
803
|
+
a = parseFloat(a);
|
|
804
|
+
if (isNaN(a) || a < 0 || a > 1) {
|
|
805
|
+
a = 1;
|
|
806
|
+
}
|
|
807
|
+
return a;
|
|
590
808
|
}
|
|
591
|
-
function
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
809
|
+
function bound01(n, max) {
|
|
810
|
+
if (isOnePointZero(n))
|
|
811
|
+
n = "100%";
|
|
812
|
+
var processPercent = isPercentage(n);
|
|
813
|
+
n = Math.min(max, Math.max(0, parseFloat(n)));
|
|
814
|
+
if (processPercent) {
|
|
815
|
+
n = parseInt(n * max, 10) / 100;
|
|
816
|
+
}
|
|
817
|
+
if (Math.abs(n - max) < 1e-6) {
|
|
818
|
+
return 1;
|
|
819
|
+
}
|
|
820
|
+
return n % max / parseFloat(max);
|
|
595
821
|
}
|
|
596
|
-
function
|
|
597
|
-
return Math.min(1, Math.max(0,
|
|
822
|
+
function clamp01(val) {
|
|
823
|
+
return Math.min(1, Math.max(0, val));
|
|
598
824
|
}
|
|
599
|
-
function
|
|
600
|
-
return parseInt(
|
|
825
|
+
function parseIntFromHex(val) {
|
|
826
|
+
return parseInt(val, 16);
|
|
601
827
|
}
|
|
602
|
-
function
|
|
603
|
-
return typeof
|
|
828
|
+
function isOnePointZero(n) {
|
|
829
|
+
return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
|
|
604
830
|
}
|
|
605
|
-
function
|
|
606
|
-
return typeof
|
|
831
|
+
function isPercentage(n) {
|
|
832
|
+
return typeof n === "string" && n.indexOf("%") != -1;
|
|
607
833
|
}
|
|
608
|
-
function
|
|
609
|
-
return
|
|
834
|
+
function pad2(c) {
|
|
835
|
+
return c.length == 1 ? "0" + c : "" + c;
|
|
610
836
|
}
|
|
611
|
-
function
|
|
612
|
-
|
|
837
|
+
function convertToPercentage(n) {
|
|
838
|
+
if (n <= 1) {
|
|
839
|
+
n = n * 100 + "%";
|
|
840
|
+
}
|
|
841
|
+
return n;
|
|
613
842
|
}
|
|
614
|
-
function
|
|
615
|
-
return Math.round(parseFloat(
|
|
843
|
+
function convertDecimalToHex(d) {
|
|
844
|
+
return Math.round(parseFloat(d) * 255).toString(16);
|
|
616
845
|
}
|
|
617
|
-
function
|
|
618
|
-
return
|
|
846
|
+
function convertHexToDecimal(h) {
|
|
847
|
+
return parseIntFromHex(h) / 255;
|
|
619
848
|
}
|
|
620
|
-
var
|
|
621
|
-
var
|
|
849
|
+
var matchers = function() {
|
|
850
|
+
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
|
851
|
+
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
|
852
|
+
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
853
|
+
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
854
|
+
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
622
855
|
return {
|
|
623
|
-
CSS_UNIT: new RegExp(
|
|
624
|
-
rgb: new RegExp("rgb" +
|
|
625
|
-
rgba: new RegExp("rgba" +
|
|
626
|
-
hsl: new RegExp("hsl" +
|
|
627
|
-
hsla: new RegExp("hsla" +
|
|
628
|
-
hsv: new RegExp("hsv" +
|
|
629
|
-
hsva: new RegExp("hsva" +
|
|
856
|
+
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
857
|
+
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
858
|
+
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
|
859
|
+
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
|
860
|
+
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
|
861
|
+
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
|
862
|
+
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
|
630
863
|
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
631
864
|
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
632
865
|
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
633
866
|
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
|
634
867
|
};
|
|
635
868
|
}();
|
|
636
|
-
function
|
|
637
|
-
return !!
|
|
638
|
-
}
|
|
639
|
-
function
|
|
640
|
-
|
|
641
|
-
var
|
|
642
|
-
if (
|
|
643
|
-
|
|
644
|
-
|
|
869
|
+
function isValidCSSUnit(color) {
|
|
870
|
+
return !!matchers.CSS_UNIT.exec(color);
|
|
871
|
+
}
|
|
872
|
+
function stringInputToObject(color) {
|
|
873
|
+
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
|
|
874
|
+
var named = false;
|
|
875
|
+
if (names[color]) {
|
|
876
|
+
color = names[color];
|
|
877
|
+
named = true;
|
|
878
|
+
} else if (color == "transparent") {
|
|
645
879
|
return {
|
|
646
880
|
r: 0,
|
|
647
881
|
g: 0,
|
|
@@ -649,139 +883,214 @@ function ue(t) {
|
|
|
649
883
|
a: 0,
|
|
650
884
|
format: "name"
|
|
651
885
|
};
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
886
|
+
}
|
|
887
|
+
var match;
|
|
888
|
+
if (match = matchers.rgb.exec(color)) {
|
|
889
|
+
return {
|
|
890
|
+
r: match[1],
|
|
891
|
+
g: match[2],
|
|
892
|
+
b: match[3]
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
if (match = matchers.rgba.exec(color)) {
|
|
896
|
+
return {
|
|
897
|
+
r: match[1],
|
|
898
|
+
g: match[2],
|
|
899
|
+
b: match[3],
|
|
900
|
+
a: match[4]
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
if (match = matchers.hsl.exec(color)) {
|
|
904
|
+
return {
|
|
905
|
+
h: match[1],
|
|
906
|
+
s: match[2],
|
|
907
|
+
l: match[3]
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
if (match = matchers.hsla.exec(color)) {
|
|
911
|
+
return {
|
|
912
|
+
h: match[1],
|
|
913
|
+
s: match[2],
|
|
914
|
+
l: match[3],
|
|
915
|
+
a: match[4]
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
if (match = matchers.hsv.exec(color)) {
|
|
919
|
+
return {
|
|
920
|
+
h: match[1],
|
|
921
|
+
s: match[2],
|
|
922
|
+
v: match[3]
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
if (match = matchers.hsva.exec(color)) {
|
|
926
|
+
return {
|
|
927
|
+
h: match[1],
|
|
928
|
+
s: match[2],
|
|
929
|
+
v: match[3],
|
|
930
|
+
a: match[4]
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
if (match = matchers.hex8.exec(color)) {
|
|
934
|
+
return {
|
|
935
|
+
r: parseIntFromHex(match[1]),
|
|
936
|
+
g: parseIntFromHex(match[2]),
|
|
937
|
+
b: parseIntFromHex(match[3]),
|
|
938
|
+
a: convertHexToDecimal(match[4]),
|
|
939
|
+
format: named ? "name" : "hex8"
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
if (match = matchers.hex6.exec(color)) {
|
|
943
|
+
return {
|
|
944
|
+
r: parseIntFromHex(match[1]),
|
|
945
|
+
g: parseIntFromHex(match[2]),
|
|
946
|
+
b: parseIntFromHex(match[3]),
|
|
947
|
+
format: named ? "name" : "hex"
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
if (match = matchers.hex4.exec(color)) {
|
|
951
|
+
return {
|
|
952
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
953
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
954
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
955
|
+
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
956
|
+
format: named ? "name" : "hex8"
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
if (match = matchers.hex3.exec(color)) {
|
|
960
|
+
return {
|
|
961
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
962
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
963
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
964
|
+
format: named ? "name" : "hex"
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
return false;
|
|
968
|
+
}
|
|
969
|
+
function validateWCAG2Parms(parms) {
|
|
970
|
+
var level, size;
|
|
971
|
+
parms = parms || {
|
|
707
972
|
level: "AA",
|
|
708
973
|
size: "small"
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
|
|
974
|
+
};
|
|
975
|
+
level = (parms.level || "AA").toUpperCase();
|
|
976
|
+
size = (parms.size || "small").toLowerCase();
|
|
977
|
+
if (level !== "AA" && level !== "AAA") {
|
|
978
|
+
level = "AA";
|
|
979
|
+
}
|
|
980
|
+
if (size !== "small" && size !== "large") {
|
|
981
|
+
size = "small";
|
|
982
|
+
}
|
|
983
|
+
return {
|
|
984
|
+
level,
|
|
985
|
+
size
|
|
712
986
|
};
|
|
713
987
|
}
|
|
714
|
-
const
|
|
715
|
-
|
|
716
|
-
class fe extends B {
|
|
988
|
+
const styles = '/*\n[ Wj Color Picker ]\n*/\n:host {\n --wj-color-picker-value: #ff0000;\n --wj-color-picker-size: 1rem;\n --wj-color-picker-radius: 4px;\n}\n\n.anchor {\n width: var(--wj-color-picker-size);\n height: var(--wj-color-picker-size);\n background: var(--wj-color-picker-value);\n}\n\n.picker {\n width: 200px;\n min-height: 90px;\n box-shadow: 0 0 5px rgba(0, 0, 0, 0.05), 0 5px 20px rgba(0, 0, 0, 0.1);\n border-radius: var(--wj-border-radius-small);\n border-width: 1px;\n border-style: var(--wj-border-style);\n border-color: var(--wj-border-color);\n background: var(--wj-background);\n}\n\n.color-area {\n display: block;\n position: relative;\n height: 100px;\n color: var(--wj-color-picker-area);\n background-image: linear-gradient(rgba(0, 0, 0, 0), #000), linear-gradient(90deg, #fff, currentColor);\n cursor: crosshair;\n border-radius: var(--wj-color-picker-radius) var(--wj-color-picker-radius) 0 0;\n border-bottom: 1px solid var(--wj-border-color);\n}\n\n.wrapper {\n display: inline-table;\n width: calc(100% - 2rem);\n margin: 1rem;\n}\n\n.hue {\n border-radius: 0.25rem;\n background-image: linear-gradient(to right, rgb(255, 0, 0) 0%, rgb(255, 255, 0) 17%, rgb(0, 255, 0) 33%, rgb(0, 255, 255) 50%, rgb(0, 0, 255) 67%, rgb(255, 0, 255) 83%, rgb(255, 0, 0) 100%);\n width: 100%;\n height: 8px;\n margin: 0.75rem 0 1rem;\n}\n\n.hue::part(slider) {\n --wj-slider-color: transparent;\n --wj-slider-thumb-color: white;\n --wj-slider-thumb-shadow: 0 0 0 1px var(--wj-border-color);\n --wj-slider-thumb-shadow-active: var(--wj-slider-thumb-shadow);\n --wj-slider-track-color: transparent;\n}\n\n.alpha-wrapper {\n border-radius: 0.25rem;\n width: 100%;\n height: 8px;\n margin: 0.75rem 0 1rem;\n background-image: repeating-linear-gradient(45deg, #aaa 25%, transparent 25%, transparent 75%, #aaa 75%, #aaa), repeating-linear-gradient(45deg, #aaa 25%, #fff 25%, #fff 75%, #aaa 75%, #aaa);\n background-position: 0 0, 4px 4px;\n background-size: 8px 8px;\n}\n\n.alpha {\n color: var(--wj-color-picker-value);\n display: block;\n height: 100%;\n width: 100%;\n border-radius: inherit;\n background-image: linear-gradient(90deg, rgba(0, 0, 0, 0), currentColor);\n}\n\n.alpha::part(slider) {\n --wj-slider-color: transparent;\n --wj-slider-thumb-color: white;\n --wj-slider-thumb-shadow: 0 0 0 1px var(--wj-border-color);\n --wj-slider-thumb-shadow-active: var(--wj-slider-thumb-shadow);\n --wj-slider-track-color: transparent;\n --wj-slider-track-height: 8px;\n}\n\n.input-wrapper {\n display: grid;\n align-items: center;\n grid-template-columns: 1fr auto;\n}\n\n.color-preview {\n width: 30px !important;\n height: 30px !important;\n border-radius: 50%;\n position: relative;\n margin-right: 1rem;\n}\n.color-preview:before, .color-preview:after {\n content: "";\n position: absolute;\n height: 100%;\n width: 100%;\n left: 0;\n top: 0;\n border: 1px solid #fff;\n border-radius: 50%;\n}\n.color-preview:before {\n background-image: repeating-linear-gradient(45deg, #aaa 25%, transparent 25%, transparent 75%, #aaa 75%, #aaa), repeating-linear-gradient(45deg, #aaa 25%, #fff 25%, #fff 75%, #aaa 75%, #aaa);\n background-position: 0 0, 4px 4px;\n background-size: 8px 8px;\n}\n.color-preview:after {\n background: var(--wj-color-picker-value);\n}\n\nwj-input {\n --wj-input-border-radius: 1rem;\n --wj-input-margin-bottom: 0;\n}\n\nwj-input::part(input) {\n text-align: center;\n}\n\n.swatches {\n margin-top: 1rem;\n display: flex;\n justify-content: center;\n flex-wrap: wrap;\n}\n\n.swatch {\n background: var(--wj-color-picker-swatch);\n position: relative;\n width: 20px;\n height: 20px;\n margin: 0 4px 6px 4px;\n padding: 0;\n border: 0;\n border-radius: 50%;\n color: inherit;\n white-space: nowrap;\n overflow: hidden;\n cursor: pointer;\n}\n\n.marker {\n position: absolute;\n width: 12px;\n height: 12px;\n margin: -6px 0 0 -6px;\n border: 1px solid #fff;\n border-radius: 50%;\n background-color: var(--wj-color-picker-value);\n cursor: pointer;\n}';
|
|
989
|
+
class ColorPicker extends WJElement {
|
|
717
990
|
constructor() {
|
|
718
991
|
super();
|
|
719
|
-
|
|
720
|
-
|
|
992
|
+
__publicField(this, "className", "ColorPicker");
|
|
993
|
+
__publicField(this, "moveMarker", (event2) => {
|
|
721
994
|
this.colorAreaDimension = this.dimension();
|
|
722
|
-
const
|
|
723
|
-
let
|
|
724
|
-
|
|
995
|
+
const pointer = this.getPointerPosition(event2);
|
|
996
|
+
let x = pointer.pageX - this.colorAreaDimension.x;
|
|
997
|
+
let y = pointer.pageY - this.colorAreaDimension.y;
|
|
998
|
+
this.setColor(this.setColorAtPosition(x, y), "marker");
|
|
999
|
+
this.setMarkerPosition(x, y);
|
|
725
1000
|
});
|
|
726
1001
|
/*
|
|
727
1002
|
* @desc nanstavenie pozicie markera podla farby
|
|
728
1003
|
* @param color
|
|
729
1004
|
* @returns {{x: number, y: number}}
|
|
730
1005
|
*/
|
|
731
|
-
|
|
732
|
-
let
|
|
1006
|
+
__publicField(this, "setMarkerPositionByColor", (color = "red") => {
|
|
1007
|
+
let hsva = tinycolor(color).toHsv();
|
|
733
1008
|
return {
|
|
734
|
-
x: this.colorAreaDimension.width *
|
|
735
|
-
y: this.colorAreaDimension.height - this.colorAreaDimension.height *
|
|
1009
|
+
x: this.colorAreaDimension.width * hsva.s,
|
|
1010
|
+
y: this.colorAreaDimension.height - this.colorAreaDimension.height * hsva.v
|
|
736
1011
|
};
|
|
737
1012
|
});
|
|
738
1013
|
/*
|
|
739
1014
|
* Set css variable color value
|
|
740
1015
|
*/
|
|
741
|
-
|
|
742
|
-
let
|
|
743
|
-
if (
|
|
744
|
-
|
|
745
|
-
|
|
1016
|
+
__publicField(this, "setColor", (color = null, type = "") => {
|
|
1017
|
+
let currentColor = color;
|
|
1018
|
+
if (currentColor === null && type === "") {
|
|
1019
|
+
currentColor = tinycolor(this.input.value);
|
|
1020
|
+
this.colorArea.style.setProperty("--wj-color-picker-area", currentColor.toHexString());
|
|
1021
|
+
}
|
|
1022
|
+
if (type === "marker") {
|
|
1023
|
+
this.alphaSlider.value = 100;
|
|
1024
|
+
this.alphaSlider.style.setProperty("--wj-color-picker-value", currentColor.toHexString());
|
|
1025
|
+
this.colorPreview.style.setProperty("--wj-color-picker-value", currentColor.toHex8String());
|
|
1026
|
+
this.picker.style.setProperty("--wj-color-picker-value", currentColor.toHexString());
|
|
1027
|
+
this.marker.style.setProperty("--wj-color-picker-value", currentColor.toHex8String());
|
|
1028
|
+
}
|
|
1029
|
+
if (type === "hue") {
|
|
1030
|
+
let markerColorByPosition = this.setColorAtPosition(this.markerPosition.x, this.markerPosition.y, this.alphaSlider.value);
|
|
1031
|
+
currentColor = tinycolor(this.getHSVA(this.hueSlider.value, this.alphaSlider.value));
|
|
1032
|
+
this.colorPreview.style.setProperty("--wj-color-picker-value", markerColorByPosition.toHex8String());
|
|
1033
|
+
this.marker.style.setProperty("--wj-color-picker-value", markerColorByPosition.toHexString());
|
|
1034
|
+
this.alphaSlider.style.setProperty("--wj-color-picker-value", currentColor.toHexString());
|
|
1035
|
+
this.colorArea.style.setProperty("--wj-color-picker-area", currentColor.toHexString());
|
|
1036
|
+
this.input.value = markerColorByPosition.toHex8String();
|
|
746
1037
|
}
|
|
747
|
-
if (
|
|
748
|
-
|
|
749
|
-
let
|
|
750
|
-
|
|
1038
|
+
if (type === "alpha") {
|
|
1039
|
+
currentColor = tinycolor(this.input.value);
|
|
1040
|
+
let hsv = currentColor.toHsv();
|
|
1041
|
+
hsv.a = this.alphaSlider.value / 100;
|
|
1042
|
+
currentColor = tinycolor(hsv);
|
|
1043
|
+
this.colorPreview.style.setProperty("--wj-color-picker-value", currentColor.toHex8String());
|
|
751
1044
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
1045
|
+
if (type === "swatch") {
|
|
1046
|
+
this.colorPreview.style.setProperty("--wj-color-picker-value", currentColor.toHex8String());
|
|
1047
|
+
this.marker.style.setProperty("--wj-color-picker-value", currentColor.toHexString());
|
|
1048
|
+
this.alphaSlider.style.setProperty("--wj-color-picker-value", currentColor.toHexString());
|
|
1049
|
+
this.colorArea.style.setProperty("--wj-color-picker-area", currentColor.toHex8String());
|
|
1050
|
+
this.markerPosition = this.setMarkerPositionByColor(currentColor.toHex8String());
|
|
1051
|
+
this.setMarkerPosition(this.markerPosition.x, this.markerPosition.y);
|
|
1052
|
+
}
|
|
1053
|
+
this.input.value = currentColor.toHex8String();
|
|
1054
|
+
this.anchor.style.setProperty("--wj-color-picker-value", currentColor.toHexString());
|
|
1055
|
+
this.value = {
|
|
1056
|
+
"hex8": currentColor.toHex8String(),
|
|
1057
|
+
"hex": currentColor.toHexString(),
|
|
1058
|
+
"rgb": currentColor.toRgbString(),
|
|
1059
|
+
"rgba": currentColor.toRgbString(),
|
|
1060
|
+
"hsl": currentColor.toHslString(),
|
|
1061
|
+
"hsla": currentColor.toHslString(),
|
|
1062
|
+
"hsv": currentColor.toHsvString(),
|
|
1063
|
+
"hsva": currentColor.toHsvString(),
|
|
1064
|
+
"name": currentColor.toName(),
|
|
1065
|
+
"format": currentColor.getFormat()
|
|
1066
|
+
};
|
|
1067
|
+
event.dispatchCustomEvent(this, "wj-color-picker:select", this.value);
|
|
764
1068
|
});
|
|
765
1069
|
/*
|
|
766
1070
|
* Set hue sliders
|
|
767
1071
|
*/
|
|
768
|
-
|
|
769
|
-
this.hueSlider.value = e.detail.value
|
|
1072
|
+
__publicField(this, "setHue", (e) => {
|
|
1073
|
+
this.hueSlider.value = e.detail.value;
|
|
1074
|
+
this.setColor(null, "hue");
|
|
770
1075
|
});
|
|
771
1076
|
/*
|
|
772
1077
|
* Set alpha sliders
|
|
773
1078
|
*/
|
|
774
|
-
|
|
775
|
-
this.alphaSlider.value = e.detail.value
|
|
1079
|
+
__publicField(this, "setAlpha", (e) => {
|
|
1080
|
+
this.alphaSlider.value = e.detail.value;
|
|
1081
|
+
this.setColor(null, "alpha");
|
|
776
1082
|
});
|
|
777
1083
|
/*
|
|
778
1084
|
* Get HSVA color order by hue and alpha
|
|
779
1085
|
*/
|
|
780
|
-
|
|
1086
|
+
__publicField(this, "getHSVA", (hue, alpha) => {
|
|
1087
|
+
return `hsva(${hue}, 100%, 100%, ${alpha / 100})`;
|
|
1088
|
+
});
|
|
781
1089
|
this._markerPosition = {
|
|
782
1090
|
markerX: "0",
|
|
783
1091
|
markerY: "0"
|
|
784
|
-
}
|
|
1092
|
+
};
|
|
1093
|
+
this._swatches = [
|
|
785
1094
|
"#264653",
|
|
786
1095
|
"#2a9d8f",
|
|
787
1096
|
"#e9c46a",
|
|
@@ -795,20 +1104,20 @@ class fe extends B {
|
|
|
795
1104
|
"rgba(0,119,182,0.8)"
|
|
796
1105
|
];
|
|
797
1106
|
}
|
|
798
|
-
set markerPosition(
|
|
799
|
-
this._markerPosition =
|
|
1107
|
+
set markerPosition(value) {
|
|
1108
|
+
this._markerPosition = value;
|
|
800
1109
|
}
|
|
801
1110
|
get markerPosition() {
|
|
802
1111
|
return this._markerPosition;
|
|
803
1112
|
}
|
|
804
|
-
set swatches(
|
|
805
|
-
this.setAttribute("swatches",
|
|
1113
|
+
set swatches(value) {
|
|
1114
|
+
this.setAttribute("swatches", value.split(","));
|
|
806
1115
|
}
|
|
807
1116
|
get swatches() {
|
|
808
1117
|
return this._swatches;
|
|
809
1118
|
}
|
|
810
1119
|
static get cssStyleSheet() {
|
|
811
|
-
return
|
|
1120
|
+
return styles;
|
|
812
1121
|
}
|
|
813
1122
|
static get observedAttributes() {
|
|
814
1123
|
return [];
|
|
@@ -816,54 +1125,109 @@ class fe extends B {
|
|
|
816
1125
|
setupAttributes() {
|
|
817
1126
|
this.isShadowRoot = "open";
|
|
818
1127
|
}
|
|
819
|
-
draw(
|
|
820
|
-
let
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
let
|
|
835
|
-
|
|
836
|
-
let
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
1128
|
+
draw(context, store, params) {
|
|
1129
|
+
let fragment = document.createDocumentFragment();
|
|
1130
|
+
let native = document.createElement("div");
|
|
1131
|
+
native.classList.add("native-color-picker");
|
|
1132
|
+
let anchor = document.createElement("div");
|
|
1133
|
+
anchor.setAttribute("slot", "anchor");
|
|
1134
|
+
anchor.setAttribute("part", "anchor");
|
|
1135
|
+
anchor.classList.add("anchor");
|
|
1136
|
+
let picker = document.createElement("div");
|
|
1137
|
+
picker.classList.add("picker");
|
|
1138
|
+
let marker = document.createElement("div");
|
|
1139
|
+
marker.classList.add("marker");
|
|
1140
|
+
let colorArea = document.createElement("div");
|
|
1141
|
+
colorArea.classList.add("color-area");
|
|
1142
|
+
colorArea.addEventListener("click", this.moveMarker);
|
|
1143
|
+
let wrapper = document.createElement("div");
|
|
1144
|
+
wrapper.classList.add("wrapper");
|
|
1145
|
+
let hueSlider = document.createElement("wj-slider");
|
|
1146
|
+
hueSlider.setAttribute("min", "0");
|
|
1147
|
+
hueSlider.setAttribute("max", "360");
|
|
1148
|
+
hueSlider.classList.add("hue");
|
|
1149
|
+
hueSlider.addEventListener("wj:slider-move", this.setHue);
|
|
1150
|
+
let alphaWrapper = document.createElement("div");
|
|
1151
|
+
alphaWrapper.classList.add("alpha-wrapper");
|
|
1152
|
+
let alphaSlider = document.createElement("wj-slider");
|
|
1153
|
+
alphaSlider.setAttribute("min", "0");
|
|
1154
|
+
alphaSlider.setAttribute("max", "100");
|
|
1155
|
+
alphaSlider.setAttribute("value", "50");
|
|
1156
|
+
alphaSlider.classList.add("alpha");
|
|
1157
|
+
alphaSlider.addEventListener("wj:slider-move", this.setAlpha);
|
|
1158
|
+
let inputWrapper = document.createElement("div");
|
|
1159
|
+
inputWrapper.classList.add("input-wrapper");
|
|
1160
|
+
let colorPreview = document.createElement("div");
|
|
1161
|
+
colorPreview.classList.add("color-preview");
|
|
1162
|
+
let input = document.createElement("wj-input");
|
|
1163
|
+
input.classList.add("input");
|
|
1164
|
+
input.setAttribute("variant", "standard");
|
|
1165
|
+
input.value = "#ff0000";
|
|
1166
|
+
colorArea.appendChild(marker);
|
|
1167
|
+
alphaWrapper.appendChild(alphaSlider);
|
|
1168
|
+
inputWrapper.appendChild(colorPreview);
|
|
1169
|
+
inputWrapper.appendChild(input);
|
|
1170
|
+
wrapper.appendChild(hueSlider);
|
|
1171
|
+
wrapper.appendChild(alphaWrapper);
|
|
1172
|
+
wrapper.appendChild(inputWrapper);
|
|
1173
|
+
picker.appendChild(colorArea);
|
|
1174
|
+
picker.appendChild(wrapper);
|
|
1175
|
+
this.createSwatches(wrapper);
|
|
1176
|
+
let popup = document.createElement("wj-popup");
|
|
1177
|
+
popup.setAttribute("placement", this.placement || "bottom-start");
|
|
1178
|
+
popup.setAttribute("offset", this.offset);
|
|
1179
|
+
popup.setAttribute("manual", "");
|
|
1180
|
+
popup.appendChild(anchor);
|
|
1181
|
+
popup.appendChild(picker);
|
|
1182
|
+
native.appendChild(popup);
|
|
1183
|
+
fragment.appendChild(native);
|
|
1184
|
+
this.popup = popup;
|
|
1185
|
+
this.anchor = anchor;
|
|
1186
|
+
this.picker = picker;
|
|
1187
|
+
this.marker = marker;
|
|
1188
|
+
this.colorArea = colorArea;
|
|
1189
|
+
this.hueSlider = hueSlider;
|
|
1190
|
+
this.alphaSlider = alphaSlider;
|
|
1191
|
+
this.colorPreview = colorPreview;
|
|
1192
|
+
this.input = input;
|
|
1193
|
+
return fragment;
|
|
1194
|
+
}
|
|
1195
|
+
createSwatches(node) {
|
|
848
1196
|
if (this.swatches.length === 0)
|
|
849
1197
|
return;
|
|
850
|
-
let
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
1198
|
+
let swatches = document.createElement("div");
|
|
1199
|
+
swatches.classList.add("swatches");
|
|
1200
|
+
this.swatches.forEach((swatch) => {
|
|
1201
|
+
let button = document.createElement("button");
|
|
1202
|
+
button.classList.add("swatch");
|
|
1203
|
+
button.style.setProperty("--wj-color-picker-swatch", swatch);
|
|
1204
|
+
button.addEventListener("click", (e) => {
|
|
1205
|
+
this.setSliders(swatch);
|
|
1206
|
+
this.setColor(tinycolor(swatch), "swatch");
|
|
1207
|
+
});
|
|
1208
|
+
swatches.appendChild(button);
|
|
1209
|
+
});
|
|
1210
|
+
node.appendChild(swatches);
|
|
1211
|
+
}
|
|
1212
|
+
setSliders(color) {
|
|
1213
|
+
let hsva = tinycolor(color).toHsv();
|
|
1214
|
+
this.hueSlider.value = hsva.h;
|
|
1215
|
+
this.alphaSlider.value = hsva.a * 100;
|
|
861
1216
|
}
|
|
862
1217
|
afterDraw() {
|
|
863
|
-
this.init =
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
1218
|
+
this.init = false;
|
|
1219
|
+
this.addEventListener("wj-popup:show", (e) => {
|
|
1220
|
+
if (!this.init) {
|
|
1221
|
+
window.setTimeout(() => {
|
|
1222
|
+
this.colorAreaDimension = this.dimension();
|
|
1223
|
+
this.markerPosition = this.setMarkerPositionByColor(this.input.value);
|
|
1224
|
+
this.setMarkerPosition(this.markerPosition.x, this.markerPosition.y);
|
|
1225
|
+
if (this.input.value != "")
|
|
1226
|
+
this.alphaSlider.value = 100;
|
|
1227
|
+
this.setColor();
|
|
1228
|
+
}, 0);
|
|
1229
|
+
this.init = true;
|
|
1230
|
+
}
|
|
867
1231
|
});
|
|
868
1232
|
}
|
|
869
1233
|
dimension() {
|
|
@@ -875,12 +1239,12 @@ class fe extends B {
|
|
|
875
1239
|
};
|
|
876
1240
|
}
|
|
877
1241
|
disconnectedCallback() {
|
|
878
|
-
this.init =
|
|
1242
|
+
this.init = false;
|
|
879
1243
|
}
|
|
880
|
-
getPointerPosition(
|
|
1244
|
+
getPointerPosition(event2) {
|
|
881
1245
|
return {
|
|
882
|
-
pageX:
|
|
883
|
-
pageY:
|
|
1246
|
+
pageX: event2.changedTouches ? event2.changedTouches[0].pageX : event2.clientX,
|
|
1247
|
+
pageY: event2.changedTouches ? event2.changedTouches[0].pageY : event2.clientY
|
|
884
1248
|
};
|
|
885
1249
|
}
|
|
886
1250
|
/*
|
|
@@ -888,11 +1252,15 @@ class fe extends B {
|
|
|
888
1252
|
* @param x
|
|
889
1253
|
* @param y
|
|
890
1254
|
*/
|
|
891
|
-
setMarkerPosition(
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
1255
|
+
setMarkerPosition(x, y) {
|
|
1256
|
+
x = x < 0 ? 0 : x > this.colorAreaDimension.width ? this.colorAreaDimension.width : x;
|
|
1257
|
+
y = y < 0 ? 0 : y > this.colorAreaDimension.height ? this.colorAreaDimension.height : y;
|
|
1258
|
+
this.markerPosition = {
|
|
1259
|
+
x,
|
|
1260
|
+
y
|
|
1261
|
+
};
|
|
1262
|
+
this.marker.style.left = `${x}px`;
|
|
1263
|
+
this.marker.style.top = `${y}px`;
|
|
896
1264
|
}
|
|
897
1265
|
/*
|
|
898
1266
|
* nastavenie farby podla pozicie markera
|
|
@@ -900,17 +1268,17 @@ class fe extends B {
|
|
|
900
1268
|
* @param y
|
|
901
1269
|
* @returns {tinycolor}
|
|
902
1270
|
*/
|
|
903
|
-
setColorAtPosition(
|
|
904
|
-
const
|
|
1271
|
+
setColorAtPosition(x, y, alpha = 100) {
|
|
1272
|
+
const hsva = {
|
|
905
1273
|
h: this.hueSlider.value * 1,
|
|
906
|
-
s:
|
|
907
|
-
v: 100 -
|
|
908
|
-
a:
|
|
1274
|
+
s: x / this.colorAreaDimension.width * 100,
|
|
1275
|
+
v: 100 - y / this.colorAreaDimension.height * 100,
|
|
1276
|
+
a: alpha / 100
|
|
909
1277
|
};
|
|
910
|
-
return
|
|
1278
|
+
return tinycolor(hsva);
|
|
911
1279
|
}
|
|
912
1280
|
}
|
|
913
|
-
customElements.get("wj-color-picker") || window.customElements.define("wj-color-picker",
|
|
1281
|
+
customElements.get("wj-color-picker") || window.customElements.define("wj-color-picker", ColorPicker);
|
|
914
1282
|
export {
|
|
915
|
-
|
|
1283
|
+
ColorPicker
|
|
916
1284
|
};
|