@spectrum-web-components/color-area 0.5.0-devmode.0 → 0.5.1
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 +6 -30
- package/package.json +5 -4
- package/sp-color-area.dev.js +1 -0
- package/sp-color-area.dev.js.map +1 -1
- package/sp-color-area.js +1 -2
- package/sp-color-area.js.map +2 -2
- package/src/ColorArea.d.ts +2 -5
- package/src/ColorArea.dev.js +73 -121
- package/src/ColorArea.dev.js.map +2 -2
- package/src/ColorArea.js +8 -440
- package/src/ColorArea.js.map +3 -3
- package/src/color-area.css.dev.js +1 -0
- package/src/color-area.css.dev.js.map +1 -1
- package/src/color-area.css.js +2 -4
- package/src/color-area.css.js.map +2 -2
- package/src/index.dev.js +1 -0
- package/src/index.dev.js.map +1 -1
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/spectrum-color-area.css.dev.js +1 -0
- package/src/spectrum-color-area.css.dev.js.map +1 -1
- package/src/spectrum-color-area.css.js +2 -4
- package/src/spectrum-color-area.css.js.map +2 -2
- package/src/types.dev.js +1 -0
- package/src/types.js +1 -0
- package/stories/color-area.stories.js +16 -3
- package/stories/color-area.stories.js.map +2 -2
- package/test/benchmark/basic-test.js +1 -0
- package/test/benchmark/basic-test.js.map +1 -1
- package/test/color-area.test-vrt.js +1 -0
- package/test/color-area.test-vrt.js.map +1 -1
- package/test/color-area.test.js +186 -104
- package/test/color-area.test.js.map +2 -2
package/custom-elements.json
CHANGED
|
@@ -93,21 +93,18 @@
|
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
95
|
"kind": "field",
|
|
96
|
-
"name": "
|
|
97
|
-
"
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
"privacy": "public",
|
|
101
|
-
"attribute": "hue"
|
|
96
|
+
"name": "colorController",
|
|
97
|
+
"privacy": "private",
|
|
98
|
+
"default": "new ColorController(this, {\n extractColorFromState: () => ({\n h: this.hue,\n s: this.x,\n v: 1 - this.y,\n }),\n applyColorToState: ({ s, v }) => {\n this.x = s;\n this.y = 1 - v;\n },\n })"
|
|
102
99
|
},
|
|
103
100
|
{
|
|
104
101
|
"kind": "field",
|
|
105
|
-
"name": "
|
|
102
|
+
"name": "hue",
|
|
106
103
|
"type": {
|
|
107
104
|
"text": "number"
|
|
108
105
|
},
|
|
109
|
-
"privacy": "
|
|
110
|
-
"
|
|
106
|
+
"privacy": "public",
|
|
107
|
+
"attribute": "hue"
|
|
111
108
|
},
|
|
112
109
|
{
|
|
113
110
|
"kind": "field",
|
|
@@ -127,27 +124,6 @@
|
|
|
127
124
|
"privacy": "public",
|
|
128
125
|
"attribute": "color"
|
|
129
126
|
},
|
|
130
|
-
{
|
|
131
|
-
"kind": "field",
|
|
132
|
-
"name": "_color",
|
|
133
|
-
"privacy": "private",
|
|
134
|
-
"default": "new TinyColor({ h: 0, s: 1, v: 1 })"
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
"kind": "field",
|
|
138
|
-
"name": "_previousColor",
|
|
139
|
-
"privacy": "private",
|
|
140
|
-
"default": "new TinyColor({ h: 0, s: 1, v: 1 })"
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
"kind": "field",
|
|
144
|
-
"name": "_format",
|
|
145
|
-
"type": {
|
|
146
|
-
"text": "{ format: string; isString: boolean }"
|
|
147
|
-
},
|
|
148
|
-
"privacy": "private",
|
|
149
|
-
"default": "{\n format: '',\n isString: false,\n }"
|
|
150
|
-
},
|
|
151
127
|
{
|
|
152
128
|
"kind": "field",
|
|
153
129
|
"name": "activeAxis",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/color-area",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -62,8 +62,9 @@
|
|
|
62
62
|
],
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@ctrl/tinycolor": "^3.3.3",
|
|
65
|
-
"@spectrum-web-components/base": "^0.
|
|
66
|
-
"@spectrum-web-components/color-handle": "^0.4.
|
|
65
|
+
"@spectrum-web-components/base": "^0.7.0",
|
|
66
|
+
"@spectrum-web-components/color-handle": "^0.4.1",
|
|
67
|
+
"@spectrum-web-components/reactive-controllers": "^0.3.1",
|
|
67
68
|
"tslib": "^2.0.0"
|
|
68
69
|
},
|
|
69
70
|
"devDependencies": {
|
|
@@ -75,5 +76,5 @@
|
|
|
75
76
|
"./sp-*.js",
|
|
76
77
|
"./**/*.dev.js"
|
|
77
78
|
],
|
|
78
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "15588c72c774b17cfac605b20ac52a27d123bd03"
|
|
79
80
|
}
|
package/sp-color-area.dev.js
CHANGED
package/sp-color-area.dev.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["sp-color-area.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { ColorArea } from './src/ColorArea.dev.js'\n\ncustomElements.define('sp-color-area', ColorArea);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-color-area': ColorArea;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAYA;
|
|
5
|
+
"mappings": ";AAYA,SAAS,iBAAiB;AAE1B,eAAe,OAAO,iBAAiB,SAAS;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/sp-color-area.js
CHANGED
package/sp-color-area.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["sp-color-area.ts"],
|
|
4
4
|
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { ColorArea } from './src/ColorArea.js';\n\ncustomElements.define('sp-color-area', ColorArea);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-color-area': ColorArea;\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "aAYA,OAAS,aAAAA,MAAiB,qBAE1B,eAAe,OAAO,gBAAiBA,CAAS",
|
|
6
|
+
"names": ["ColorArea"]
|
|
7
7
|
}
|
package/src/ColorArea.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
-
import { ColorValue } from '@spectrum-web-components/color-handle';
|
|
3
2
|
import '@spectrum-web-components/color-handle/sp-color-handle.js';
|
|
3
|
+
import { ColorValue } from '@spectrum-web-components/reactive-controllers/src/Color.js';
|
|
4
4
|
/**
|
|
5
5
|
* @element sp-color-area
|
|
6
6
|
* @slot gradient - a custom gradient visually outlining the available color values
|
|
@@ -15,15 +15,12 @@ export declare class ColorArea extends SpectrumElement {
|
|
|
15
15
|
labelX: string;
|
|
16
16
|
labelY: string;
|
|
17
17
|
private handle;
|
|
18
|
+
private colorController;
|
|
18
19
|
get hue(): number;
|
|
19
20
|
set hue(value: number);
|
|
20
|
-
private _hue;
|
|
21
21
|
get value(): ColorValue;
|
|
22
22
|
get color(): ColorValue;
|
|
23
23
|
set color(color: ColorValue);
|
|
24
|
-
private _color;
|
|
25
|
-
private _previousColor;
|
|
26
|
-
private _format;
|
|
27
24
|
private activeAxis;
|
|
28
25
|
get x(): number;
|
|
29
26
|
set x(x: number);
|
package/src/ColorArea.dev.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
@@ -19,12 +20,10 @@ import {
|
|
|
19
20
|
query
|
|
20
21
|
} from "@spectrum-web-components/base/src/decorators.js";
|
|
21
22
|
import { streamingListener } from "@spectrum-web-components/base/src/streaming-listener.js";
|
|
22
|
-
import {
|
|
23
|
-
extractHueAndSaturationRegExp,
|
|
24
|
-
replaceHueRegExp
|
|
25
|
-
} from "@spectrum-web-components/color-handle";
|
|
26
23
|
import "@spectrum-web-components/color-handle/sp-color-handle.js";
|
|
27
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
ColorController
|
|
26
|
+
} from "@spectrum-web-components/reactive-controllers/src/Color.js";
|
|
28
27
|
import styles from "./color-area.css.js";
|
|
29
28
|
export class ColorArea extends SpectrumElement {
|
|
30
29
|
constructor() {
|
|
@@ -33,13 +32,17 @@ export class ColorArea extends SpectrumElement {
|
|
|
33
32
|
this.focused = false;
|
|
34
33
|
this.labelX = "saturation";
|
|
35
34
|
this.labelY = "luminosity";
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
this.colorController = new ColorController(this, {
|
|
36
|
+
extractColorFromState: () => ({
|
|
37
|
+
h: this.hue,
|
|
38
|
+
s: this.x,
|
|
39
|
+
v: 1 - this.y
|
|
40
|
+
}),
|
|
41
|
+
applyColorToState: ({ s, v }) => {
|
|
42
|
+
this.x = s;
|
|
43
|
+
this.y = 1 - v;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
43
46
|
this.activeAxis = "x";
|
|
44
47
|
this._x = 1;
|
|
45
48
|
this._y = 0;
|
|
@@ -52,88 +55,19 @@ export class ColorArea extends SpectrumElement {
|
|
|
52
55
|
return [styles];
|
|
53
56
|
}
|
|
54
57
|
get hue() {
|
|
55
|
-
return this.
|
|
58
|
+
return this.colorController.hue;
|
|
56
59
|
}
|
|
57
60
|
set hue(value) {
|
|
58
|
-
|
|
59
|
-
if (hue === this.hue) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const oldValue = this.hue;
|
|
63
|
-
const { s, v } = this._color.toHsv();
|
|
64
|
-
this._color = new TinyColor({ h: hue, s, v });
|
|
65
|
-
this._hue = hue;
|
|
66
|
-
this.requestUpdate("hue", oldValue);
|
|
61
|
+
this.colorController.hue = value;
|
|
67
62
|
}
|
|
68
63
|
get value() {
|
|
69
|
-
return this.color;
|
|
64
|
+
return this.colorController.color;
|
|
70
65
|
}
|
|
71
66
|
get color() {
|
|
72
|
-
|
|
73
|
-
case "rgb":
|
|
74
|
-
return this._format.isString ? this._color.toRgbString() : this._color.toRgb();
|
|
75
|
-
case "prgb":
|
|
76
|
-
return this._format.isString ? this._color.toPercentageRgbString() : this._color.toPercentageRgb();
|
|
77
|
-
case "hex8":
|
|
78
|
-
return this._format.isString ? this._color.toHex8String() : this._color.toHex8();
|
|
79
|
-
case "name":
|
|
80
|
-
return this._color.toName() || this._color.toRgbString();
|
|
81
|
-
case "hsl":
|
|
82
|
-
if (this._format.isString) {
|
|
83
|
-
const hslString = this._color.toHslString();
|
|
84
|
-
return hslString.replace(replaceHueRegExp, `$1${this.hue}`);
|
|
85
|
-
} else {
|
|
86
|
-
const { s, l, a } = this._color.toHsl();
|
|
87
|
-
return { h: this.hue, s, l, a };
|
|
88
|
-
}
|
|
89
|
-
case "hsv":
|
|
90
|
-
if (this._format.isString) {
|
|
91
|
-
const hsvString = this._color.toHsvString();
|
|
92
|
-
return hsvString.replace(replaceHueRegExp, `$1${this.hue}`);
|
|
93
|
-
} else {
|
|
94
|
-
const { s, v, a } = this._color.toHsv();
|
|
95
|
-
return { h: this.hue, s, v, a };
|
|
96
|
-
}
|
|
97
|
-
case "hex":
|
|
98
|
-
case "hex3":
|
|
99
|
-
case "hex4":
|
|
100
|
-
case "hex6":
|
|
101
|
-
default:
|
|
102
|
-
return this._format.isString ? this._color.toHexString() : this._color.toHex();
|
|
103
|
-
}
|
|
67
|
+
return this.colorController.color;
|
|
104
68
|
}
|
|
105
69
|
set color(color) {
|
|
106
|
-
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const oldValue = this._color;
|
|
110
|
-
this._color = new TinyColor(color);
|
|
111
|
-
const format = this._color.format;
|
|
112
|
-
let isString = typeof color === "string" || color instanceof String;
|
|
113
|
-
if (format.startsWith("hex")) {
|
|
114
|
-
isString = color.startsWith("#");
|
|
115
|
-
}
|
|
116
|
-
this._format = {
|
|
117
|
-
format,
|
|
118
|
-
isString
|
|
119
|
-
};
|
|
120
|
-
const { h, s, v } = this._color.toHsv();
|
|
121
|
-
let originalHue = void 0;
|
|
122
|
-
if (isString && format.startsWith("hs")) {
|
|
123
|
-
const values = extractHueAndSaturationRegExp.exec(color);
|
|
124
|
-
if (values !== null) {
|
|
125
|
-
const [, h2] = values;
|
|
126
|
-
originalHue = Number(h2);
|
|
127
|
-
}
|
|
128
|
-
} else if (!isString && format.startsWith("hs")) {
|
|
129
|
-
const colorInput = this._color.originalInput;
|
|
130
|
-
const colorValues = Object.values(colorInput);
|
|
131
|
-
originalHue = colorValues[0];
|
|
132
|
-
}
|
|
133
|
-
this.hue = originalHue || h;
|
|
134
|
-
this.x = s;
|
|
135
|
-
this.y = 1 - v;
|
|
136
|
-
this.requestUpdate("color", oldValue);
|
|
70
|
+
this.colorController.color = color;
|
|
137
71
|
}
|
|
138
72
|
get x() {
|
|
139
73
|
return this._x;
|
|
@@ -191,7 +125,9 @@ export class ColorArea extends SpectrumElement {
|
|
|
191
125
|
handleKeydown(event) {
|
|
192
126
|
const { code } = event;
|
|
193
127
|
this.focused = true;
|
|
194
|
-
this.altered = [event.shiftKey, event.ctrlKey, event.altKey].filter(
|
|
128
|
+
this.altered = [event.shiftKey, event.ctrlKey, event.altKey].filter(
|
|
129
|
+
(key) => !!key
|
|
130
|
+
).length;
|
|
195
131
|
const isArrowKey = code.search("Arrow") === 0;
|
|
196
132
|
if (isArrowKey) {
|
|
197
133
|
event.preventDefault();
|
|
@@ -230,20 +166,24 @@ export class ColorArea extends SpectrumElement {
|
|
|
230
166
|
}
|
|
231
167
|
this.x = Math.min(1, Math.max(this.x + deltaX, 0));
|
|
232
168
|
this.y = Math.min(1, Math.max(this.y + deltaY, 0));
|
|
233
|
-
this.
|
|
234
|
-
this.
|
|
169
|
+
this.colorController.savePreviousColor();
|
|
170
|
+
this.colorController.applyColorFromState();
|
|
235
171
|
if (deltaX != 0 || deltaY != 0) {
|
|
236
|
-
this.dispatchEvent(
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
172
|
+
this.dispatchEvent(
|
|
173
|
+
new Event("input", {
|
|
174
|
+
bubbles: true,
|
|
175
|
+
composed: true
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
const applyDefault = this.dispatchEvent(
|
|
179
|
+
new Event("change", {
|
|
180
|
+
bubbles: true,
|
|
181
|
+
composed: true,
|
|
182
|
+
cancelable: true
|
|
183
|
+
})
|
|
184
|
+
);
|
|
245
185
|
if (!applyDefault) {
|
|
246
|
-
this.
|
|
186
|
+
this.colorController.restorePreviousColor();
|
|
247
187
|
}
|
|
248
188
|
}
|
|
249
189
|
}
|
|
@@ -255,15 +195,17 @@ export class ColorArea extends SpectrumElement {
|
|
|
255
195
|
handleInput(event) {
|
|
256
196
|
const { valueAsNumber, name } = event.target;
|
|
257
197
|
this[name] = valueAsNumber;
|
|
258
|
-
this.
|
|
198
|
+
this.colorController.applyColorFromState();
|
|
259
199
|
}
|
|
260
200
|
handleChange(event) {
|
|
261
201
|
this.handleInput(event);
|
|
262
|
-
this.dispatchEvent(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
202
|
+
this.dispatchEvent(
|
|
203
|
+
new Event("change", {
|
|
204
|
+
bubbles: true,
|
|
205
|
+
composed: true,
|
|
206
|
+
cancelable: true
|
|
207
|
+
})
|
|
208
|
+
);
|
|
267
209
|
}
|
|
268
210
|
handlePointerdown(event) {
|
|
269
211
|
if (event.button !== 0) {
|
|
@@ -271,7 +213,7 @@ export class ColorArea extends SpectrumElement {
|
|
|
271
213
|
return;
|
|
272
214
|
}
|
|
273
215
|
this._pointerDown = true;
|
|
274
|
-
this.
|
|
216
|
+
this.colorController.savePreviousColor();
|
|
275
217
|
this.boundingClientRect = this.getBoundingClientRect();
|
|
276
218
|
event.target.setPointerCapture(event.pointerId);
|
|
277
219
|
if (event.pointerType === "mouse") {
|
|
@@ -280,30 +222,34 @@ export class ColorArea extends SpectrumElement {
|
|
|
280
222
|
}
|
|
281
223
|
handlePointermove(event) {
|
|
282
224
|
const [x, y] = this.calculateHandlePosition(event);
|
|
283
|
-
this._color = new TinyColor({ h: this.hue, s: x, v: 1 - y });
|
|
284
225
|
this.x = x;
|
|
285
226
|
this.y = y;
|
|
286
|
-
this.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
227
|
+
this.colorController.applyColorFromState();
|
|
228
|
+
this.dispatchEvent(
|
|
229
|
+
new Event("input", {
|
|
230
|
+
bubbles: true,
|
|
231
|
+
composed: true,
|
|
232
|
+
cancelable: true
|
|
233
|
+
})
|
|
234
|
+
);
|
|
291
235
|
}
|
|
292
236
|
handlePointerup(event) {
|
|
293
237
|
event.preventDefault();
|
|
294
238
|
this._pointerDown = false;
|
|
295
239
|
event.target.releasePointerCapture(event.pointerId);
|
|
296
|
-
const applyDefault = this.dispatchEvent(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
240
|
+
const applyDefault = this.dispatchEvent(
|
|
241
|
+
new Event("change", {
|
|
242
|
+
bubbles: true,
|
|
243
|
+
composed: true,
|
|
244
|
+
cancelable: true
|
|
245
|
+
})
|
|
246
|
+
);
|
|
301
247
|
this.inputX.focus();
|
|
302
248
|
if (event.pointerType === "mouse") {
|
|
303
249
|
this.focused = false;
|
|
304
250
|
}
|
|
305
251
|
if (!applyDefault) {
|
|
306
|
-
this.
|
|
252
|
+
this.colorController.restorePreviousColor();
|
|
307
253
|
}
|
|
308
254
|
}
|
|
309
255
|
calculateHandlePosition(event) {
|
|
@@ -317,8 +263,14 @@ export class ColorArea extends SpectrumElement {
|
|
|
317
263
|
const offsetY = event.clientY;
|
|
318
264
|
const width = rect.width;
|
|
319
265
|
const height = rect.height;
|
|
320
|
-
const percentX = Math.max(
|
|
321
|
-
|
|
266
|
+
const percentX = Math.max(
|
|
267
|
+
0,
|
|
268
|
+
Math.min(1, (offsetX - minOffsetX) / width)
|
|
269
|
+
);
|
|
270
|
+
const percentY = Math.max(
|
|
271
|
+
0,
|
|
272
|
+
Math.min(1, (offsetY - minOffsetY) / height)
|
|
273
|
+
);
|
|
322
274
|
return [percentX, percentY];
|
|
323
275
|
}
|
|
324
276
|
handleAreaPointerdown(event) {
|
|
@@ -349,7 +301,7 @@ export class ColorArea extends SpectrumElement {
|
|
|
349
301
|
@focus=${this.forwardFocus}
|
|
350
302
|
?focused=${this.focused}
|
|
351
303
|
class="handle"
|
|
352
|
-
color=${this.
|
|
304
|
+
color=${this.colorController.getHslString()}
|
|
353
305
|
?disabled=${this.disabled}
|
|
354
306
|
style="transform: translate(${this.x * width}px, ${this.y * height}px);"
|
|
355
307
|
${streamingListener({
|
package/src/ColorArea.dev.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["ColorArea.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { streamingListener } from '@spectrum-web-components/base/src/streaming-listener.js';\nimport { SWCResizeObserverEntry, WithSWCResizeObserver } from './types';\nimport {\n ColorHandle,\n ColorValue,\n extractHueAndSaturationRegExp,\n replaceHueRegExp,\n} from '@spectrum-web-components/color-handle';\nimport '@spectrum-web-components/color-handle/sp-color-handle.js';\nimport { TinyColor } from '@ctrl/tinycolor';\n\nimport styles from './color-area.css.js';\n\n/**\n * @element sp-color-area\n * @slot gradient - a custom gradient visually outlining the available color values\n * @fires input - The value of the Color Area has changed.\n * @fires change - An alteration to the value of the Color Area has been committed by the user.\n */\nexport class ColorArea extends SpectrumElement {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ type: Boolean, reflect: true })\n public disabled = false;\n\n @property({ type: Boolean, reflect: true })\n public focused = false;\n\n @property({ type: String })\n public label: string | undefined;\n\n @property({ type: String, attribute: 'label-x' })\n public labelX = 'saturation';\n\n @property({ type: String, attribute: 'label-y' })\n public labelY = 'luminosity';\n\n @query('.handle')\n private handle!: ColorHandle;\n\n @property({ type: Number })\n public get hue(): number {\n return this._hue;\n }\n\n public set hue(value: number) {\n const hue = Math.min(360, Math.max(0, value));\n if (hue === this.hue) {\n return;\n }\n const oldValue = this.hue;\n const { s, v } = this._color.toHsv();\n this._color = new TinyColor({ h: hue, s, v });\n this._hue = hue;\n this.requestUpdate('hue', oldValue);\n }\n\n private _hue = 0;\n\n @property({ type: String })\n public get value(): ColorValue {\n return this.color;\n }\n\n @property({ type: String })\n public get color(): ColorValue {\n switch (this._format.format) {\n case 'rgb':\n return this._format.isString\n ? this._color.toRgbString()\n : this._color.toRgb();\n case 'prgb':\n return this._format.isString\n ? this._color.toPercentageRgbString()\n : this._color.toPercentageRgb();\n case 'hex8':\n return this._format.isString\n ? this._color.toHex8String()\n : this._color.toHex8();\n case 'name':\n return this._color.toName() || this._color.toRgbString();\n case 'hsl':\n if (this._format.isString) {\n const hslString = this._color.toHslString();\n return hslString.replace(replaceHueRegExp, `$1${this.hue}`);\n } else {\n const { s, l, a } = this._color.toHsl();\n return { h: this.hue, s, l, a };\n }\n case 'hsv':\n if (this._format.isString) {\n const hsvString = this._color.toHsvString();\n return hsvString.replace(replaceHueRegExp, `$1${this.hue}`);\n } else {\n const { s, v, a } = this._color.toHsv();\n return { h: this.hue, s, v, a };\n }\n case 'hex':\n case 'hex3':\n case 'hex4':\n case 'hex6':\n default:\n return this._format.isString\n ? this._color.toHexString()\n : this._color.toHex();\n }\n }\n\n public set color(color: ColorValue) {\n if (color === this.color) {\n return;\n }\n const oldValue = this._color;\n this._color = new TinyColor(color);\n const format = this._color.format;\n let isString = typeof color === 'string' || color instanceof String;\n\n if (format.startsWith('hex')) {\n isString = (color as string).startsWith('#');\n }\n\n this._format = {\n format,\n isString,\n };\n\n const { h, s, v } = this._color.toHsv();\n let originalHue: number | undefined = undefined;\n\n if (isString && format.startsWith('hs')) {\n const values = extractHueAndSaturationRegExp.exec(color as string);\n\n if (values !== null) {\n const [, h] = values;\n originalHue = Number(h);\n }\n } else if (!isString && format.startsWith('hs')) {\n const colorInput = this._color.originalInput;\n const colorValues = Object.values(colorInput);\n originalHue = colorValues[0];\n }\n\n this.hue = originalHue || h;\n this.x = s;\n this.y = 1 - v;\n this.requestUpdate('color', oldValue);\n }\n\n private _color = new TinyColor({ h: 0, s: 1, v: 1 });\n\n private _previousColor = new TinyColor({ h: 0, s: 1, v: 1 });\n\n private _format: { format: string; isString: boolean } = {\n format: '',\n isString: false,\n };\n\n @property({ attribute: false })\n private activeAxis = 'x';\n\n @property({ type: Number })\n public get x(): number {\n return this._x;\n }\n\n public set x(x: number) {\n if (x === this.x) {\n return;\n }\n const oldValue = this.x;\n if (this.inputX) {\n // Use the native `input[type='range']` control to validate this value after `firstUpdate`\n this.inputX.value = x.toString();\n this._x = this.inputX.valueAsNumber;\n } else {\n this._x = x;\n }\n this.requestUpdate('x', oldValue);\n }\n\n private _x = 1;\n\n @property({ type: Number })\n public get y(): number {\n return this._y;\n }\n\n public set y(y: number) {\n if (y === this.y) {\n return;\n }\n const oldValue = this.y;\n if (this.inputY) {\n // Use the native `input[type='range']` control to validate this value after `firstUpdate`\n this.inputY.value = y.toString();\n this._y = this.inputY.valueAsNumber;\n } else {\n this._y = y;\n }\n this.requestUpdate('y', oldValue);\n }\n\n private _y = 0;\n\n @property({ type: Number })\n public step = 0.01;\n\n @query('[name=\"x\"]')\n public inputX!: HTMLInputElement;\n\n @query('[name=\"y\"]')\n public inputY!: HTMLInputElement;\n\n private altered = 0;\n\n private activeKeys = new Set();\n\n public override focus(focusOptions: FocusOptions = {}): void {\n super.focus(focusOptions);\n this.forwardFocus();\n }\n\n private forwardFocus(): void {\n this.focused = this.hasVisibleFocusInTree();\n if (this.activeAxis === 'x') {\n this.inputX.focus();\n } else {\n this.inputY.focus();\n }\n }\n\n private handleFocusin(): void {\n this.focused = true;\n }\n\n private handleFocusout(): void {\n if (this._pointerDown) {\n return;\n }\n this.focused = false;\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n this.focused = true;\n this.altered = [event.shiftKey, event.ctrlKey, event.altKey].filter(\n (key) => !!key\n ).length;\n const isArrowKey = code.search('Arrow') === 0;\n if (isArrowKey) {\n event.preventDefault();\n this.activeKeys.add(code);\n this.handleKeypress();\n }\n }\n\n private handleKeypress(): void {\n let deltaX = 0;\n let deltaY = 0;\n const step = Math.max(this.step, this.altered * 5 * this.step);\n this.activeKeys.forEach((code) => {\n switch (code) {\n case 'ArrowUp':\n deltaY = step * -1;\n break;\n case 'ArrowDown':\n deltaY = step * 1;\n break;\n case 'ArrowLeft':\n deltaX = step * -1;\n break;\n case 'ArrowRight':\n deltaX = step * 1;\n break;\n /* c8 ignore next 2 */\n default:\n break;\n }\n });\n if (deltaX != 0) {\n this.activeAxis = 'x';\n this.inputX.focus();\n } else if (deltaY != 0) {\n this.activeAxis = 'y';\n this.inputY.focus();\n }\n this.x = Math.min(1, Math.max(this.x + deltaX, 0));\n this.y = Math.min(1, Math.max(this.y + deltaY, 0));\n\n this._previousColor = this._color.clone();\n this._color = new TinyColor({ h: this.hue, s: this.x, v: 1 - this.y });\n\n if (deltaX != 0 || deltaY != 0) {\n this.dispatchEvent(\n new Event('input', {\n bubbles: true,\n composed: true,\n })\n );\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n if (!applyDefault) {\n this._color = this._previousColor;\n }\n }\n }\n\n private handleKeyup(event: KeyboardEvent): void {\n event.preventDefault();\n const { code } = event;\n this.activeKeys.delete(code);\n }\n\n private handleInput(event: Event & { target: HTMLInputElement }): void {\n const { valueAsNumber, name } = event.target;\n\n this[name as 'x' | 'y'] = valueAsNumber;\n this._color = new TinyColor({ h: this.hue, s: this.x, v: 1 - this.y });\n }\n\n private handleChange(event: Event & { target: HTMLInputElement }): void {\n this.handleInput(event);\n this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n }\n\n private boundingClientRect!: DOMRect;\n private _pointerDown = false;\n\n private handlePointerdown(event: PointerEvent): void {\n if (event.button !== 0) {\n event.preventDefault();\n return;\n }\n this._pointerDown = true;\n this._previousColor = this._color.clone();\n this.boundingClientRect = this.getBoundingClientRect();\n (event.target as HTMLElement).setPointerCapture(event.pointerId);\n if (event.pointerType === 'mouse') {\n this.focused = true;\n }\n }\n\n private handlePointermove(event: PointerEvent): void {\n const [x, y] = this.calculateHandlePosition(event);\n this._color = new TinyColor({ h: this.hue, s: x, v: 1 - y });\n\n this.x = x;\n this.y = y;\n this.dispatchEvent(\n new Event('input', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n }\n\n private handlePointerup(event: PointerEvent): void {\n event.preventDefault();\n this._pointerDown = false;\n (event.target as HTMLElement).releasePointerCapture(event.pointerId);\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n this.inputX.focus();\n if (event.pointerType === 'mouse') {\n this.focused = false;\n }\n if (!applyDefault) {\n this._color = this._previousColor;\n }\n }\n\n /**\n * Returns the value under the cursor\n * @param: PointerEvent on slider\n * @return: Slider value that correlates to the position under the pointer\n */\n private calculateHandlePosition(event: PointerEvent): [number, number] {\n /* c8 ignore next 3 */\n if (!this.boundingClientRect) {\n return [this.x, this.y];\n }\n const rect = this.boundingClientRect;\n const minOffsetX = rect.left;\n const minOffsetY = rect.top;\n const offsetX = event.clientX;\n const offsetY = event.clientY;\n const width = rect.width;\n const height = rect.height;\n\n const percentX = Math.max(\n 0,\n Math.min(1, (offsetX - minOffsetX) / width)\n );\n const percentY = Math.max(\n 0,\n Math.min(1, (offsetY - minOffsetY) / height)\n );\n\n return [percentX, percentY];\n }\n\n private handleAreaPointerdown(event: PointerEvent): void {\n if (event.button !== 0) {\n return;\n }\n event.stopPropagation();\n event.preventDefault();\n this.handle.dispatchEvent(new PointerEvent('pointerdown', event));\n this.handlePointermove(event);\n }\n\n protected override render(): TemplateResult {\n const { width = 0, height = 0 } = this.boundingClientRect || {};\n\n return html`\n <div\n @pointerdown=${this.handleAreaPointerdown}\n class=\"gradient\"\n style=\"background:\n linear-gradient(to top, black 0%, hsla(${this\n .hue}, 100%, 0.01%, 0) 100%),\n linear-gradient(to right, white 0%, hsla(${this\n .hue}, 100%, 0.01%, 0) 100%), hsl(${this.hue}, 100%, 50%);\"\n >\n <slot name=\"gradient\"></slot>\n </div>\n\n <sp-color-handle\n tabindex=${ifDefined(this.focused ? undefined : '0')}\n @focus=${this.forwardFocus}\n ?focused=${this.focused}\n class=\"handle\"\n color=${this._color.toHslString()}\n ?disabled=${this.disabled}\n style=\"transform: translate(${this.x * width}px, ${this.y *\n height}px);\"\n ${streamingListener({\n start: ['pointerdown', this.handlePointerdown],\n streamInside: ['pointermove', this.handlePointermove],\n end: [['pointerup', 'pointercancel'], this.handlePointerup],\n })}\n ></sp-color-handle>\n\n <div>\n <input\n type=\"range\"\n class=\"slider\"\n name=\"x\"\n aria-label=${this.label ?? this.labelX}\n min=\"0\"\n max=\"1\"\n step=${this.step}\n tabindex=\"-1\"\n .value=${String(this.x)}\n @input=${this.handleInput}\n @change=${this.handleChange}\n />\n </div>\n <div>\n <input\n type=\"range\"\n class=\"slider\"\n name=\"y\"\n aria-label=${this.label ?? this.labelY}\n min=\"0\"\n max=\"1\"\n step=${this.step}\n tabindex=\"-1\"\n .value=${String(this.y)}\n @input=${this.handleInput}\n @change=${this.handleChange}\n />\n </div>\n `;\n }\n\n protected override firstUpdated(changed: PropertyValues): void {\n super.firstUpdated(changed);\n this.boundingClientRect = this.getBoundingClientRect();\n\n this.addEventListener('focusin', this.handleFocusin);\n this.addEventListener('focusout', this.handleFocusout);\n this.addEventListener('keyup', this.handleKeyup);\n this.addEventListener('keydown', this.handleKeydown);\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (this.x !== this.inputX.valueAsNumber) {\n this._x = this.inputX.valueAsNumber;\n }\n if (this.y !== this.inputY.valueAsNumber) {\n this._y = this.inputY.valueAsNumber;\n }\n if (changed.has('focused') && this.focused) {\n // Lazily bind the `input[type=\"range\"]` elements in shadow roots\n // so that browsers with certain settings (Webkit) aren't allowed\n // multiple tab stops within the Color Area.\n const parentX = this.inputX.parentElement as HTMLDivElement;\n const parentY = this.inputY.parentElement as HTMLDivElement;\n if (!parentX.shadowRoot && !parentY.shadowRoot) {\n parentX.attachShadow({ mode: 'open' });\n parentY.attachShadow({ mode: 'open' });\n const slot = '<div tabindex=\"-1\"><slot></slot></div>';\n (parentX.shadowRoot as unknown as ShadowRoot).innerHTML = slot;\n (parentY.shadowRoot as unknown as ShadowRoot).innerHTML = slot;\n }\n }\n }\n\n private observer?: WithSWCResizeObserver['ResizeObserver'];\n\n public override connectedCallback(): void {\n super.connectedCallback();\n if (\n !this.observer &&\n (window as unknown as WithSWCResizeObserver).ResizeObserver\n ) {\n this.observer = new (\n window as unknown as WithSWCResizeObserver\n ).ResizeObserver((entries: SWCResizeObserverEntry[]) => {\n for (const entry of entries) {\n this.boundingClientRect = entry.contentRect;\n }\n this.requestUpdate();\n });\n }\n this.observer?.observe(this);\n }\n\n public override disconnectedCallback(): void {\n this.observer?.unobserve(this);\n super.disconnectedCallback();\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { ifDefined } from '@spectrum-web-components/base/src/directives.js';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\nimport { streamingListener } from '@spectrum-web-components/base/src/streaming-listener.js';\nimport { SWCResizeObserverEntry, WithSWCResizeObserver } from './types';\nimport type { ColorHandle } from '@spectrum-web-components/color-handle';\nimport '@spectrum-web-components/color-handle/sp-color-handle.js';\nimport {\n ColorController,\n ColorValue,\n} from '@spectrum-web-components/reactive-controllers/src/Color.js';\n\nimport styles from './color-area.css.js';\n\n/**\n * @element sp-color-area\n * @slot gradient - a custom gradient visually outlining the available color values\n * @fires input - The value of the Color Area has changed.\n * @fires change - An alteration to the value of the Color Area has been committed by the user.\n */\nexport class ColorArea extends SpectrumElement {\n public static override get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ type: Boolean, reflect: true })\n public disabled = false;\n\n @property({ type: Boolean, reflect: true })\n public focused = false;\n\n @property({ type: String })\n public label: string | undefined;\n\n @property({ type: String, attribute: 'label-x' })\n public labelX = 'saturation';\n\n @property({ type: String, attribute: 'label-y' })\n public labelY = 'luminosity';\n\n @query('.handle')\n private handle!: ColorHandle;\n\n private colorController = new ColorController(this, {\n extractColorFromState: () => ({\n h: this.hue,\n s: this.x,\n v: 1 - this.y,\n }),\n applyColorToState: ({ s, v }) => {\n this.x = s;\n this.y = 1 - v;\n },\n });\n\n @property({ type: Number })\n public get hue(): number {\n return this.colorController.hue;\n }\n\n public set hue(value: number) {\n this.colorController.hue = value;\n }\n\n @property({ type: String })\n public get value(): ColorValue {\n return this.colorController.color;\n }\n\n @property({ type: String })\n public get color(): ColorValue {\n return this.colorController.color;\n }\n\n public set color(color: ColorValue) {\n this.colorController.color = color;\n }\n\n @property({ attribute: false })\n private activeAxis = 'x';\n\n @property({ type: Number })\n public get x(): number {\n return this._x;\n }\n\n public set x(x: number) {\n if (x === this.x) {\n return;\n }\n const oldValue = this.x;\n if (this.inputX) {\n // Use the native `input[type='range']` control to validate this value after `firstUpdate`\n this.inputX.value = x.toString();\n this._x = this.inputX.valueAsNumber;\n } else {\n this._x = x;\n }\n this.requestUpdate('x', oldValue);\n }\n\n private _x = 1;\n\n @property({ type: Number })\n public get y(): number {\n return this._y;\n }\n\n public set y(y: number) {\n if (y === this.y) {\n return;\n }\n const oldValue = this.y;\n if (this.inputY) {\n // Use the native `input[type='range']` control to validate this value after `firstUpdate`\n this.inputY.value = y.toString();\n this._y = this.inputY.valueAsNumber;\n } else {\n this._y = y;\n }\n this.requestUpdate('y', oldValue);\n }\n\n private _y = 0;\n\n @property({ type: Number })\n public step = 0.01;\n\n @query('[name=\"x\"]')\n public inputX!: HTMLInputElement;\n\n @query('[name=\"y\"]')\n public inputY!: HTMLInputElement;\n\n private altered = 0;\n\n private activeKeys = new Set();\n\n public override focus(focusOptions: FocusOptions = {}): void {\n super.focus(focusOptions);\n this.forwardFocus();\n }\n\n private forwardFocus(): void {\n this.focused = this.hasVisibleFocusInTree();\n if (this.activeAxis === 'x') {\n this.inputX.focus();\n } else {\n this.inputY.focus();\n }\n }\n\n private handleFocusin(): void {\n this.focused = true;\n }\n\n private handleFocusout(): void {\n if (this._pointerDown) {\n return;\n }\n this.focused = false;\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n this.focused = true;\n this.altered = [event.shiftKey, event.ctrlKey, event.altKey].filter(\n (key) => !!key\n ).length;\n const isArrowKey = code.search('Arrow') === 0;\n if (isArrowKey) {\n event.preventDefault();\n this.activeKeys.add(code);\n this.handleKeypress();\n }\n }\n\n private handleKeypress(): void {\n let deltaX = 0;\n let deltaY = 0;\n const step = Math.max(this.step, this.altered * 5 * this.step);\n this.activeKeys.forEach((code) => {\n switch (code) {\n case 'ArrowUp':\n deltaY = step * -1;\n break;\n case 'ArrowDown':\n deltaY = step * 1;\n break;\n case 'ArrowLeft':\n deltaX = step * -1;\n break;\n case 'ArrowRight':\n deltaX = step * 1;\n break;\n /* c8 ignore next 2 */\n default:\n break;\n }\n });\n if (deltaX != 0) {\n this.activeAxis = 'x';\n this.inputX.focus();\n } else if (deltaY != 0) {\n this.activeAxis = 'y';\n this.inputY.focus();\n }\n this.x = Math.min(1, Math.max(this.x + deltaX, 0));\n this.y = Math.min(1, Math.max(this.y + deltaY, 0));\n\n this.colorController.savePreviousColor();\n this.colorController.applyColorFromState();\n\n if (deltaX != 0 || deltaY != 0) {\n this.dispatchEvent(\n new Event('input', {\n bubbles: true,\n composed: true,\n })\n );\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n if (!applyDefault) {\n this.colorController.restorePreviousColor();\n }\n }\n }\n\n private handleKeyup(event: KeyboardEvent): void {\n event.preventDefault();\n const { code } = event;\n this.activeKeys.delete(code);\n }\n\n private handleInput(event: Event & { target: HTMLInputElement }): void {\n const { valueAsNumber, name } = event.target;\n\n this[name as 'x' | 'y'] = valueAsNumber;\n this.colorController.applyColorFromState();\n }\n\n private handleChange(event: Event & { target: HTMLInputElement }): void {\n this.handleInput(event);\n this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n }\n\n private boundingClientRect!: DOMRect;\n private _pointerDown = false;\n\n private handlePointerdown(event: PointerEvent): void {\n if (event.button !== 0) {\n event.preventDefault();\n return;\n }\n this._pointerDown = true;\n this.colorController.savePreviousColor();\n this.boundingClientRect = this.getBoundingClientRect();\n (event.target as HTMLElement).setPointerCapture(event.pointerId);\n if (event.pointerType === 'mouse') {\n this.focused = true;\n }\n }\n\n private handlePointermove(event: PointerEvent): void {\n const [x, y] = this.calculateHandlePosition(event);\n\n this.x = x;\n this.y = y;\n this.colorController.applyColorFromState();\n this.dispatchEvent(\n new Event('input', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n }\n\n private handlePointerup(event: PointerEvent): void {\n event.preventDefault();\n this._pointerDown = false;\n (event.target as HTMLElement).releasePointerCapture(event.pointerId);\n const applyDefault = this.dispatchEvent(\n new Event('change', {\n bubbles: true,\n composed: true,\n cancelable: true,\n })\n );\n this.inputX.focus();\n if (event.pointerType === 'mouse') {\n this.focused = false;\n }\n if (!applyDefault) {\n this.colorController.restorePreviousColor();\n }\n }\n\n /**\n * Returns the value under the cursor\n * @param: PointerEvent on slider\n * @return: Slider value that correlates to the position under the pointer\n */\n private calculateHandlePosition(event: PointerEvent): [number, number] {\n /* c8 ignore next 3 */\n if (!this.boundingClientRect) {\n return [this.x, this.y];\n }\n const rect = this.boundingClientRect;\n const minOffsetX = rect.left;\n const minOffsetY = rect.top;\n const offsetX = event.clientX;\n const offsetY = event.clientY;\n const width = rect.width;\n const height = rect.height;\n\n const percentX = Math.max(\n 0,\n Math.min(1, (offsetX - minOffsetX) / width)\n );\n const percentY = Math.max(\n 0,\n Math.min(1, (offsetY - minOffsetY) / height)\n );\n\n return [percentX, percentY];\n }\n\n private handleAreaPointerdown(event: PointerEvent): void {\n if (event.button !== 0) {\n return;\n }\n event.stopPropagation();\n event.preventDefault();\n this.handle.dispatchEvent(new PointerEvent('pointerdown', event));\n this.handlePointermove(event);\n }\n\n protected override render(): TemplateResult {\n const { width = 0, height = 0 } = this.boundingClientRect || {};\n\n return html`\n <div\n @pointerdown=${this.handleAreaPointerdown}\n class=\"gradient\"\n style=\"background:\n linear-gradient(to top, black 0%, hsla(${this\n .hue}, 100%, 0.01%, 0) 100%),\n linear-gradient(to right, white 0%, hsla(${this\n .hue}, 100%, 0.01%, 0) 100%), hsl(${this.hue}, 100%, 50%);\"\n >\n <slot name=\"gradient\"></slot>\n </div>\n\n <sp-color-handle\n tabindex=${ifDefined(this.focused ? undefined : '0')}\n @focus=${this.forwardFocus}\n ?focused=${this.focused}\n class=\"handle\"\n color=${this.colorController.getHslString()}\n ?disabled=${this.disabled}\n style=\"transform: translate(${this.x * width}px, ${this.y *\n height}px);\"\n ${streamingListener({\n start: ['pointerdown', this.handlePointerdown],\n streamInside: ['pointermove', this.handlePointermove],\n end: [['pointerup', 'pointercancel'], this.handlePointerup],\n })}\n ></sp-color-handle>\n\n <div>\n <input\n type=\"range\"\n class=\"slider\"\n name=\"x\"\n aria-label=${this.label ?? this.labelX}\n min=\"0\"\n max=\"1\"\n step=${this.step}\n tabindex=\"-1\"\n .value=${String(this.x)}\n @input=${this.handleInput}\n @change=${this.handleChange}\n />\n </div>\n <div>\n <input\n type=\"range\"\n class=\"slider\"\n name=\"y\"\n aria-label=${this.label ?? this.labelY}\n min=\"0\"\n max=\"1\"\n step=${this.step}\n tabindex=\"-1\"\n .value=${String(this.y)}\n @input=${this.handleInput}\n @change=${this.handleChange}\n />\n </div>\n `;\n }\n\n protected override firstUpdated(changed: PropertyValues): void {\n super.firstUpdated(changed);\n this.boundingClientRect = this.getBoundingClientRect();\n\n this.addEventListener('focusin', this.handleFocusin);\n this.addEventListener('focusout', this.handleFocusout);\n this.addEventListener('keyup', this.handleKeyup);\n this.addEventListener('keydown', this.handleKeydown);\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (this.x !== this.inputX.valueAsNumber) {\n this._x = this.inputX.valueAsNumber;\n }\n if (this.y !== this.inputY.valueAsNumber) {\n this._y = this.inputY.valueAsNumber;\n }\n if (changed.has('focused') && this.focused) {\n // Lazily bind the `input[type=\"range\"]` elements in shadow roots\n // so that browsers with certain settings (Webkit) aren't allowed\n // multiple tab stops within the Color Area.\n const parentX = this.inputX.parentElement as HTMLDivElement;\n const parentY = this.inputY.parentElement as HTMLDivElement;\n if (!parentX.shadowRoot && !parentY.shadowRoot) {\n parentX.attachShadow({ mode: 'open' });\n parentY.attachShadow({ mode: 'open' });\n const slot = '<div tabindex=\"-1\"><slot></slot></div>';\n (parentX.shadowRoot as unknown as ShadowRoot).innerHTML = slot;\n (parentY.shadowRoot as unknown as ShadowRoot).innerHTML = slot;\n }\n }\n }\n\n private observer?: WithSWCResizeObserver['ResizeObserver'];\n\n public override connectedCallback(): void {\n super.connectedCallback();\n if (\n !this.observer &&\n (window as unknown as WithSWCResizeObserver).ResizeObserver\n ) {\n this.observer = new (\n window as unknown as WithSWCResizeObserver\n ).ResizeObserver((entries: SWCResizeObserverEntry[]) => {\n for (const entry of entries) {\n this.boundingClientRect = entry.contentRect;\n }\n this.requestUpdate();\n });\n }\n this.observer?.observe(this);\n }\n\n public override disconnectedCall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