@spectrum-web-components/color-wheel 0.3.11 → 0.3.13-devmode.7
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/package.json +27 -10
- package/sp-color-wheel.dev.js +3 -0
- package/sp-color-wheel.dev.js.map +7 -0
- package/sp-color-wheel.js +3 -14
- package/sp-color-wheel.js.map +7 -1
- package/src/ColorWheel.dev.js +363 -0
- package/src/ColorWheel.dev.js.map +7 -0
- package/src/ColorWheel.js +313 -333
- package/src/ColorWheel.js.map +7 -1
- package/src/color-wheel.css.dev.js +48 -0
- package/src/color-wheel.css.dev.js.map +7 -0
- package/src/color-wheel.css.js +3 -14
- package/src/color-wheel.css.js.map +7 -1
- package/src/index.dev.js +2 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -13
- package/src/index.js.map +7 -1
- package/src/spectrum-color-wheel.css.dev.js +42 -0
- package/src/spectrum-color-wheel.css.dev.js.map +7 -0
- package/src/spectrum-color-wheel.css.js +3 -14
- package/src/spectrum-color-wheel.css.js.map +7 -1
- package/src/types.dev.js +1 -0
- package/src/types.dev.js.map +7 -0
- package/src/types.js +1 -13
- package/src/types.js.map +7 -1
- package/stories/color-wheel.stories.js +51 -62
- package/stories/color-wheel.stories.js.map +7 -1
- package/test/benchmark/basic-test.js +5 -16
- package/test/benchmark/basic-test.js.map +7 -1
- package/test/color-wheel.test-vrt.js +4 -15
- package/test/color-wheel.test-vrt.js.map +7 -1
- package/test/color-wheel.test.js +347 -358
- package/test/color-wheel.test.js.map +7 -1
package/src/ColorWheel.js
CHANGED
|
@@ -1,299 +1,280 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html
|
|
14
|
+
} from "@spectrum-web-components/base";
|
|
15
|
+
import { ifDefined } from "@spectrum-web-components/base/src/directives.js";
|
|
16
|
+
import {
|
|
17
|
+
property,
|
|
18
|
+
query
|
|
19
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
20
|
+
import { streamingListener } from "@spectrum-web-components/base/src/streaming-listener.js";
|
|
21
|
+
import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
|
|
22
|
+
import "@spectrum-web-components/color-handle/sp-color-handle.js";
|
|
23
|
+
import styles from "./color-wheel.css.js";
|
|
24
|
+
import {
|
|
25
|
+
extractHueAndSaturationRegExp,
|
|
26
|
+
replaceHueAndSaturationRegExp
|
|
27
|
+
} from "@spectrum-web-components/color-handle";
|
|
28
|
+
import { TinyColor } from "@ctrl/tinycolor";
|
|
28
29
|
export class ColorWheel extends Focusable {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.disabled = false;
|
|
33
|
+
this.focused = false;
|
|
34
|
+
this.label = "hue";
|
|
35
|
+
this.step = 1;
|
|
36
|
+
this._value = 0;
|
|
37
|
+
this._color = new TinyColor({ h: 0, s: 1, v: 1 });
|
|
38
|
+
this._previousColor = new TinyColor({ h: 0, s: 1, v: 1 });
|
|
39
|
+
this._format = {
|
|
40
|
+
format: "",
|
|
41
|
+
isString: false
|
|
42
|
+
};
|
|
43
|
+
this._altered = 0;
|
|
44
|
+
this._pointerDown = false;
|
|
45
|
+
}
|
|
46
|
+
static get styles() {
|
|
47
|
+
return [styles];
|
|
48
|
+
}
|
|
49
|
+
get value() {
|
|
50
|
+
return this._value;
|
|
51
|
+
}
|
|
52
|
+
set value(hue) {
|
|
53
|
+
const value = Math.min(360, Math.max(0, hue));
|
|
54
|
+
if (value === this.value) {
|
|
55
|
+
return;
|
|
47
56
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
const oldValue = this.value;
|
|
58
|
+
const { s, v } = this._color.toHsv();
|
|
59
|
+
this._color = new TinyColor({ h: value, s, v });
|
|
60
|
+
this._value = value;
|
|
61
|
+
this.requestUpdate("value", oldValue);
|
|
62
|
+
}
|
|
63
|
+
get color() {
|
|
64
|
+
switch (this._format.format) {
|
|
65
|
+
case "rgb":
|
|
66
|
+
return this._format.isString ? this._color.toRgbString() : this._color.toRgb();
|
|
67
|
+
case "prgb":
|
|
68
|
+
return this._format.isString ? this._color.toPercentageRgbString() : this._color.toPercentageRgb();
|
|
69
|
+
case "hex":
|
|
70
|
+
case "hex3":
|
|
71
|
+
case "hex4":
|
|
72
|
+
case "hex6":
|
|
73
|
+
return this._format.isString ? this._color.toHexString() : this._color.toHex();
|
|
74
|
+
case "hex8":
|
|
75
|
+
return this._format.isString ? this._color.toHex8String() : this._color.toHex8();
|
|
76
|
+
case "name":
|
|
77
|
+
return this._color.toName() || this._color.toRgbString();
|
|
78
|
+
case "hsl":
|
|
79
|
+
if (this._format.isString) {
|
|
80
|
+
const hslString = this._color.toHslString();
|
|
81
|
+
return hslString.replace(replaceHueAndSaturationRegExp, `$1${this.value}$2${this._saturation}`);
|
|
82
|
+
} else {
|
|
83
|
+
const { s, l, a } = this._color.toHsl();
|
|
84
|
+
return { h: this.value, s, l, a };
|
|
55
85
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
switch (this._format.format) {
|
|
64
|
-
case 'rgb':
|
|
65
|
-
return this._format.isString
|
|
66
|
-
? this._color.toRgbString()
|
|
67
|
-
: this._color.toRgb();
|
|
68
|
-
case 'prgb':
|
|
69
|
-
return this._format.isString
|
|
70
|
-
? this._color.toPercentageRgbString()
|
|
71
|
-
: this._color.toPercentageRgb();
|
|
72
|
-
case 'hex':
|
|
73
|
-
case 'hex3':
|
|
74
|
-
case 'hex4':
|
|
75
|
-
case 'hex6':
|
|
76
|
-
return this._format.isString
|
|
77
|
-
? this._color.toHexString()
|
|
78
|
-
: this._color.toHex();
|
|
79
|
-
case 'hex8':
|
|
80
|
-
return this._format.isString
|
|
81
|
-
? this._color.toHex8String()
|
|
82
|
-
: this._color.toHex8();
|
|
83
|
-
case 'name':
|
|
84
|
-
return this._color.toName() || this._color.toRgbString();
|
|
85
|
-
case 'hsl':
|
|
86
|
-
if (this._format.isString) {
|
|
87
|
-
const hslString = this._color.toHslString();
|
|
88
|
-
return hslString.replace(replaceHueAndSaturationRegExp, `$1${this.value}$2${this._saturation}`);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
const { s, l, a } = this._color.toHsl();
|
|
92
|
-
return { h: this.value, s, l, a };
|
|
93
|
-
}
|
|
94
|
-
case 'hsv':
|
|
95
|
-
if (this._format.isString) {
|
|
96
|
-
const hsvString = this._color.toHsvString();
|
|
97
|
-
return hsvString.replace(replaceHueAndSaturationRegExp, `$1${this.value}$2${this._saturation}`);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
const { s, v, a } = this._color.toHsv();
|
|
101
|
-
return { h: this.value, s, v, a };
|
|
102
|
-
}
|
|
103
|
-
default:
|
|
104
|
-
return 'No color format applied.';
|
|
86
|
+
case "hsv":
|
|
87
|
+
if (this._format.isString) {
|
|
88
|
+
const hsvString = this._color.toHsvString();
|
|
89
|
+
return hsvString.replace(replaceHueAndSaturationRegExp, `$1${this.value}$2${this._saturation}`);
|
|
90
|
+
} else {
|
|
91
|
+
const { s, v, a } = this._color.toHsv();
|
|
92
|
+
return { h: this.value, s, v, a };
|
|
105
93
|
}
|
|
94
|
+
default:
|
|
95
|
+
return "No color format applied.";
|
|
106
96
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const oldValue = this._color;
|
|
112
|
-
this._color = new TinyColor(color);
|
|
113
|
-
const format = this._color.format;
|
|
114
|
-
let isString = typeof color === 'string' || color instanceof String;
|
|
115
|
-
if (format.startsWith('hex')) {
|
|
116
|
-
isString = color.startsWith('#');
|
|
117
|
-
}
|
|
118
|
-
this._format = {
|
|
119
|
-
format,
|
|
120
|
-
isString,
|
|
121
|
-
};
|
|
122
|
-
if (isString && format.startsWith('hs')) {
|
|
123
|
-
const values = extractHueAndSaturationRegExp.exec(color);
|
|
124
|
-
if (values !== null) {
|
|
125
|
-
const [, h, s] = values;
|
|
126
|
-
this.value = Number(h);
|
|
127
|
-
this._saturation = Number(s);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else if (!isString && format.startsWith('hs')) {
|
|
131
|
-
const colorInput = this._color.originalInput;
|
|
132
|
-
const colorValues = Object.values(colorInput);
|
|
133
|
-
this.value = colorValues[0];
|
|
134
|
-
this._saturation = colorValues[1];
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
const { h } = this._color.toHsv();
|
|
138
|
-
this.value = h;
|
|
139
|
-
}
|
|
140
|
-
this.requestUpdate('color', oldValue);
|
|
97
|
+
}
|
|
98
|
+
set color(color) {
|
|
99
|
+
if (color === this.color) {
|
|
100
|
+
return;
|
|
141
101
|
}
|
|
142
|
-
|
|
143
|
-
|
|
102
|
+
const oldValue = this._color;
|
|
103
|
+
this._color = new TinyColor(color);
|
|
104
|
+
const format = this._color.format;
|
|
105
|
+
let isString = typeof color === "string" || color instanceof String;
|
|
106
|
+
if (format.startsWith("hex")) {
|
|
107
|
+
isString = color.startsWith("#");
|
|
144
108
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
109
|
+
this._format = {
|
|
110
|
+
format,
|
|
111
|
+
isString
|
|
112
|
+
};
|
|
113
|
+
if (isString && format.startsWith("hs")) {
|
|
114
|
+
const values = extractHueAndSaturationRegExp.exec(color);
|
|
115
|
+
if (values !== null) {
|
|
116
|
+
const [, h, s] = values;
|
|
117
|
+
this.value = Number(h);
|
|
118
|
+
this._saturation = Number(s);
|
|
119
|
+
}
|
|
120
|
+
} else if (!isString && format.startsWith("hs")) {
|
|
121
|
+
const colorInput = this._color.originalInput;
|
|
122
|
+
const colorValues = Object.values(colorInput);
|
|
123
|
+
this.value = colorValues[0];
|
|
124
|
+
this._saturation = colorValues[1];
|
|
125
|
+
} else {
|
|
126
|
+
const { h } = this._color.toHsv();
|
|
127
|
+
this.value = h;
|
|
148
128
|
}
|
|
149
|
-
|
|
150
|
-
|
|
129
|
+
this.requestUpdate("color", oldValue);
|
|
130
|
+
}
|
|
131
|
+
get altered() {
|
|
132
|
+
return this._altered;
|
|
133
|
+
}
|
|
134
|
+
set altered(altered) {
|
|
135
|
+
this._altered = altered;
|
|
136
|
+
this.step = Math.max(1, this.altered * 10);
|
|
137
|
+
}
|
|
138
|
+
get focusElement() {
|
|
139
|
+
return this.input;
|
|
140
|
+
}
|
|
141
|
+
handleKeydown(event) {
|
|
142
|
+
const { key } = event;
|
|
143
|
+
this.focused = true;
|
|
144
|
+
this.altered = [event.shiftKey, event.ctrlKey, event.altKey].filter((key2) => !!key2).length;
|
|
145
|
+
let delta = 0;
|
|
146
|
+
switch (key) {
|
|
147
|
+
case "ArrowUp":
|
|
148
|
+
delta = this.step;
|
|
149
|
+
break;
|
|
150
|
+
case "ArrowDown":
|
|
151
|
+
delta = -this.step;
|
|
152
|
+
break;
|
|
153
|
+
case "ArrowLeft":
|
|
154
|
+
delta = this.step * (this.isLTR ? -1 : 1);
|
|
155
|
+
break;
|
|
156
|
+
case "ArrowRight":
|
|
157
|
+
delta = this.step * (this.isLTR ? 1 : -1);
|
|
158
|
+
break;
|
|
159
|
+
default:
|
|
160
|
+
return;
|
|
151
161
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
case 'ArrowRight':
|
|
168
|
-
delta = this.step * (this.isLTR ? 1 : -1);
|
|
169
|
-
break;
|
|
170
|
-
default:
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
event.preventDefault();
|
|
174
|
-
this.value = (360 + this.value + delta) % 360;
|
|
175
|
-
this._previousColor = this._color.clone();
|
|
176
|
-
this._color = new TinyColor(Object.assign(Object.assign({}, this._color.toHsl()), { h: this.value }));
|
|
177
|
-
this.dispatchEvent(new Event('input', {
|
|
178
|
-
bubbles: true,
|
|
179
|
-
composed: true,
|
|
180
|
-
}));
|
|
181
|
-
const applyDefault = this.dispatchEvent(new Event('change', {
|
|
182
|
-
bubbles: true,
|
|
183
|
-
composed: true,
|
|
184
|
-
cancelable: true,
|
|
185
|
-
}));
|
|
186
|
-
if (!applyDefault) {
|
|
187
|
-
this._color = this._previousColor;
|
|
188
|
-
}
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
this.value = (360 + this.value + delta) % 360;
|
|
164
|
+
this._previousColor = this._color.clone();
|
|
165
|
+
this._color = new TinyColor({ ...this._color.toHsl(), h: this.value });
|
|
166
|
+
this.dispatchEvent(new Event("input", {
|
|
167
|
+
bubbles: true,
|
|
168
|
+
composed: true
|
|
169
|
+
}));
|
|
170
|
+
const applyDefault = this.dispatchEvent(new Event("change", {
|
|
171
|
+
bubbles: true,
|
|
172
|
+
composed: true,
|
|
173
|
+
cancelable: true
|
|
174
|
+
}));
|
|
175
|
+
if (!applyDefault) {
|
|
176
|
+
this._color = this._previousColor;
|
|
189
177
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
178
|
+
}
|
|
179
|
+
handleInput(event) {
|
|
180
|
+
const { valueAsNumber } = event.target;
|
|
181
|
+
this.value = valueAsNumber;
|
|
182
|
+
this._color = new TinyColor({ ...this._color.toHsl(), h: this.value });
|
|
183
|
+
}
|
|
184
|
+
handleChange(event) {
|
|
185
|
+
this.handleInput(event);
|
|
186
|
+
this.dispatchEvent(new Event("change", {
|
|
187
|
+
bubbles: true,
|
|
188
|
+
composed: true
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
focus(focusOptions = {}) {
|
|
192
|
+
super.focus(focusOptions);
|
|
193
|
+
this.forwardFocus();
|
|
194
|
+
}
|
|
195
|
+
forwardFocus() {
|
|
196
|
+
this.focused = this.hasVisibleFocusInTree();
|
|
197
|
+
this.input.focus();
|
|
198
|
+
}
|
|
199
|
+
handleFocusin() {
|
|
200
|
+
this.focused = true;
|
|
201
|
+
}
|
|
202
|
+
handleFocusout() {
|
|
203
|
+
if (this._pointerDown) {
|
|
204
|
+
return;
|
|
194
205
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
206
|
+
this.altered = 0;
|
|
207
|
+
this.focused = false;
|
|
208
|
+
}
|
|
209
|
+
handlePointerdown(event) {
|
|
210
|
+
if (event.button !== 0) {
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
return;
|
|
201
213
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
214
|
+
this._pointerDown = true;
|
|
215
|
+
this._previousColor = this._color.clone();
|
|
216
|
+
this.boundingClientRect = this.getBoundingClientRect();
|
|
217
|
+
event.target.setPointerCapture(event.pointerId);
|
|
218
|
+
if (event.pointerType === "mouse") {
|
|
219
|
+
this.focused = true;
|
|
205
220
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
221
|
+
}
|
|
222
|
+
handlePointermove(event) {
|
|
223
|
+
this.value = this.calculateHandlePosition(event);
|
|
224
|
+
this._color = new TinyColor({ ...this._color.toHsl(), h: this.value });
|
|
225
|
+
this.dispatchEvent(new Event("input", {
|
|
226
|
+
bubbles: true,
|
|
227
|
+
composed: true,
|
|
228
|
+
cancelable: true
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
handlePointerup(event) {
|
|
232
|
+
this._pointerDown = false;
|
|
233
|
+
event.target.releasePointerCapture(event.pointerId);
|
|
234
|
+
const applyDefault = this.dispatchEvent(new Event("change", {
|
|
235
|
+
bubbles: true,
|
|
236
|
+
composed: true,
|
|
237
|
+
cancelable: true
|
|
238
|
+
}));
|
|
239
|
+
if (!applyDefault) {
|
|
240
|
+
this._color = this._previousColor;
|
|
209
241
|
}
|
|
210
|
-
|
|
211
|
-
|
|
242
|
+
this.focus();
|
|
243
|
+
if (event.pointerType === "mouse") {
|
|
244
|
+
this.focused = false;
|
|
212
245
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.altered = 0;
|
|
218
|
-
this.focused = false;
|
|
246
|
+
}
|
|
247
|
+
calculateHandlePosition(event) {
|
|
248
|
+
if (!this.boundingClientRect) {
|
|
249
|
+
return this.value;
|
|
219
250
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
handlePointermove(event) {
|
|
234
|
-
this.value = this.calculateHandlePosition(event);
|
|
235
|
-
this._color = new TinyColor(Object.assign(Object.assign({}, this._color.toHsl()), { h: this.value }));
|
|
236
|
-
this.dispatchEvent(new Event('input', {
|
|
237
|
-
bubbles: true,
|
|
238
|
-
composed: true,
|
|
239
|
-
cancelable: true,
|
|
240
|
-
}));
|
|
241
|
-
}
|
|
242
|
-
handlePointerup(event) {
|
|
243
|
-
this._pointerDown = false;
|
|
244
|
-
event.target.releasePointerCapture(event.pointerId);
|
|
245
|
-
const applyDefault = this.dispatchEvent(new Event('change', {
|
|
246
|
-
bubbles: true,
|
|
247
|
-
composed: true,
|
|
248
|
-
cancelable: true,
|
|
249
|
-
}));
|
|
250
|
-
if (!applyDefault) {
|
|
251
|
-
this._color = this._previousColor;
|
|
252
|
-
}
|
|
253
|
-
// Retain focus on input element after mouse up to enable keyboard interactions
|
|
254
|
-
this.focus();
|
|
255
|
-
if (event.pointerType === 'mouse') {
|
|
256
|
-
this.focused = false;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Returns the value under the cursor
|
|
261
|
-
* @param: PointerEvent on slider
|
|
262
|
-
* @return: Slider value that correlates to the position under the pointer
|
|
263
|
-
*/
|
|
264
|
-
calculateHandlePosition(event) {
|
|
265
|
-
/* c8 ignore next 3 */
|
|
266
|
-
if (!this.boundingClientRect) {
|
|
267
|
-
return this.value;
|
|
268
|
-
}
|
|
269
|
-
const rect = this.boundingClientRect;
|
|
270
|
-
const { width, height, left, top } = rect;
|
|
271
|
-
const centerX = left + width / 2;
|
|
272
|
-
const centerY = top + height / 2;
|
|
273
|
-
const pointX = event.clientX - centerX;
|
|
274
|
-
const pointY = event.clientY - centerY;
|
|
275
|
-
const value = (Math.atan2(pointY, pointX) * 180) / Math.PI;
|
|
276
|
-
return (360 + (360 + value)) % 360;
|
|
277
|
-
}
|
|
278
|
-
handleGradientPointerdown(event) {
|
|
279
|
-
if (event.button !== 0 ||
|
|
280
|
-
event.target.classList.contains('innerCircle')) {
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
event.stopPropagation();
|
|
284
|
-
event.preventDefault();
|
|
285
|
-
this.handle.dispatchEvent(new PointerEvent('pointerdown', event));
|
|
286
|
-
this.handlePointermove(event);
|
|
251
|
+
const rect = this.boundingClientRect;
|
|
252
|
+
const { width, height, left, top } = rect;
|
|
253
|
+
const centerX = left + width / 2;
|
|
254
|
+
const centerY = top + height / 2;
|
|
255
|
+
const pointX = event.clientX - centerX;
|
|
256
|
+
const pointY = event.clientY - centerY;
|
|
257
|
+
const value = Math.atan2(pointY, pointX) * 180 / Math.PI;
|
|
258
|
+
return (360 + (360 + value)) % 360;
|
|
259
|
+
}
|
|
260
|
+
handleGradientPointerdown(event) {
|
|
261
|
+
if (event.button !== 0 || event.target.classList.contains("innerCircle")) {
|
|
262
|
+
return;
|
|
287
263
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
264
|
+
event.stopPropagation();
|
|
265
|
+
event.preventDefault();
|
|
266
|
+
this.handle.dispatchEvent(new PointerEvent("pointerdown", event));
|
|
267
|
+
this.handlePointermove(event);
|
|
268
|
+
}
|
|
269
|
+
render() {
|
|
270
|
+
const { width: diameter = 160 } = this.boundingClientRect || {};
|
|
271
|
+
const radius = diameter / 2;
|
|
272
|
+
const trackWidth = 24;
|
|
273
|
+
const innerRadius = radius - trackWidth;
|
|
274
|
+
const innerDiameter = innerRadius * 2;
|
|
275
|
+
const clipPath = `path(evenodd, "M ${radius} ${radius} m -${radius} 0 a ${radius} ${radius} 0 1 0 ${diameter} 0 a ${radius} ${radius} 0 1 0 -${diameter} 0 M ${radius} ${radius} m -${innerRadius} 0 a ${innerRadius} ${innerRadius} 0 1 0 ${innerDiameter} 0 a ${innerRadius} ${innerRadius} 0 1 0 -${innerDiameter} 0")`;
|
|
276
|
+
const handleLocationStyles = `transform: translate(${(radius - 12.5) * Math.cos(this.value * Math.PI / 180)}px, ${(radius - 12.5) * Math.sin(this.value * Math.PI / 180)}px);`;
|
|
277
|
+
return html`
|
|
297
278
|
<slot
|
|
298
279
|
name="gradient"
|
|
299
280
|
@pointerdown=${this.handleGradientPointerdown}
|
|
@@ -302,7 +283,7 @@ export class ColorWheel extends Focusable {
|
|
|
302
283
|
</slot>
|
|
303
284
|
|
|
304
285
|
<sp-color-handle
|
|
305
|
-
tabindex=${ifDefined(this.focused ?
|
|
286
|
+
tabindex=${ifDefined(this.focused ? void 0 : "0")}
|
|
306
287
|
@focus=${this.forwardFocus}
|
|
307
288
|
?focused=${this.focused}
|
|
308
289
|
class="handle"
|
|
@@ -310,10 +291,10 @@ export class ColorWheel extends Focusable {
|
|
|
310
291
|
?disabled=${this.disabled}
|
|
311
292
|
style=${handleLocationStyles}
|
|
312
293
|
${streamingListener({
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
294
|
+
start: ["pointerdown", this.handlePointerdown],
|
|
295
|
+
streamInside: ["pointermove", this.handlePointermove],
|
|
296
|
+
end: [["pointerup", "pointercancel"], this.handlePointerup]
|
|
297
|
+
})}
|
|
317
298
|
></sp-color-handle>
|
|
318
299
|
|
|
319
300
|
<input
|
|
@@ -329,55 +310,54 @@ export class ColorWheel extends Focusable {
|
|
|
329
310
|
@keydown=${this.handleKeydown}
|
|
330
311
|
/>
|
|
331
312
|
`;
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
this.boundingClientRect = entry.contentRect;
|
|
347
|
-
}
|
|
348
|
-
this.requestUpdate();
|
|
349
|
-
});
|
|
313
|
+
}
|
|
314
|
+
firstUpdated(changed) {
|
|
315
|
+
super.firstUpdated(changed);
|
|
316
|
+
this.boundingClientRect = this.getBoundingClientRect();
|
|
317
|
+
this.addEventListener("focusin", this.handleFocusin);
|
|
318
|
+
this.addEventListener("focusout", this.handleFocusout);
|
|
319
|
+
}
|
|
320
|
+
connectedCallback() {
|
|
321
|
+
var _a;
|
|
322
|
+
super.connectedCallback();
|
|
323
|
+
if (!this.observer && window.ResizeObserver) {
|
|
324
|
+
this.observer = new window.ResizeObserver((entries) => {
|
|
325
|
+
for (const entry of entries) {
|
|
326
|
+
this.boundingClientRect = entry.contentRect;
|
|
350
327
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
disconnectedCallback() {
|
|
354
|
-
var _a;
|
|
355
|
-
(_a = this.observer) === null || _a === void 0 ? void 0 : _a.unobserve(this);
|
|
356
|
-
super.disconnectedCallback();
|
|
328
|
+
this.requestUpdate();
|
|
329
|
+
});
|
|
357
330
|
}
|
|
331
|
+
(_a = this.observer) == null ? void 0 : _a.observe(this);
|
|
332
|
+
}
|
|
333
|
+
disconnectedCallback() {
|
|
334
|
+
var _a;
|
|
335
|
+
(_a = this.observer) == null ? void 0 : _a.unobserve(this);
|
|
336
|
+
super.disconnectedCallback();
|
|
337
|
+
}
|
|
358
338
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
], ColorWheel.prototype, "disabled",
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
], ColorWheel.prototype, "focused",
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
], ColorWheel.prototype, "handle",
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
], ColorWheel.prototype, "label",
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
], ColorWheel.prototype, "step",
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
], ColorWheel.prototype, "value",
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
], ColorWheel.prototype, "color",
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
], ColorWheel.prototype, "input",
|
|
383
|
-
//# sourceMappingURL=ColorWheel.js.map
|
|
339
|
+
__decorateClass([
|
|
340
|
+
property({ type: Boolean, reflect: true })
|
|
341
|
+
], ColorWheel.prototype, "disabled", 2);
|
|
342
|
+
__decorateClass([
|
|
343
|
+
property({ type: Boolean, reflect: true })
|
|
344
|
+
], ColorWheel.prototype, "focused", 2);
|
|
345
|
+
__decorateClass([
|
|
346
|
+
query(".handle")
|
|
347
|
+
], ColorWheel.prototype, "handle", 2);
|
|
348
|
+
__decorateClass([
|
|
349
|
+
property({ type: String })
|
|
350
|
+
], ColorWheel.prototype, "label", 2);
|
|
351
|
+
__decorateClass([
|
|
352
|
+
property({ type: Number })
|
|
353
|
+
], ColorWheel.prototype, "step", 2);
|
|
354
|
+
__decorateClass([
|
|
355
|
+
property({ type: Number })
|
|
356
|
+
], ColorWheel.prototype, "value", 1);
|
|
357
|
+
__decorateClass([
|
|
358
|
+
property({ type: String })
|
|
359
|
+
], ColorWheel.prototype, "color", 1);
|
|
360
|
+
__decorateClass([
|
|
361
|
+
query("input")
|
|
362
|
+
], ColorWheel.prototype, "input", 2);
|
|
363
|
+
//# sourceMappingURL=ColorWheel.js.map
|