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