@spectrum-web-components/color-area 0.4.10 → 0.4.11
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 +25 -8
- package/sp-color-area.dev.js +3 -0
- package/sp-color-area.dev.js.map +7 -0
- package/sp-color-area.js +3 -14
- package/sp-color-area.js.map +7 -1
- package/src/ColorArea.dev.js +486 -0
- package/src/ColorArea.dev.js.map +7 -0
- package/src/ColorArea.js +411 -440
- package/src/ColorArea.js.map +7 -1
- package/src/color-area.css.dev.js +38 -0
- package/src/color-area.css.dev.js.map +7 -0
- package/src/color-area.css.js +3 -14
- package/src/color-area.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-area.css.dev.js +38 -0
- package/src/spectrum-color-area.css.dev.js.map +7 -0
- package/src/spectrum-color-area.css.js +3 -14
- package/src/spectrum-color-area.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-area.stories.js +90 -95
- package/stories/color-area.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-area.test-vrt.js +4 -15
- package/test/color-area.test-vrt.js.map +7 -1
- package/test/color-area.test.js +481 -490
- package/test/color-area.test.js.map +7 -1
package/custom-elements.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"modules": [
|
|
5
5
|
{
|
|
6
6
|
"kind": "javascript-module",
|
|
7
|
-
"path": "sp-color-area.
|
|
7
|
+
"path": "sp-color-area.js",
|
|
8
8
|
"declarations": [],
|
|
9
9
|
"exports": [
|
|
10
10
|
{
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
"kind": "javascript-module",
|
|
22
|
-
"path": "src/ColorArea.
|
|
22
|
+
"path": "src/ColorArea.js",
|
|
23
23
|
"declarations": [
|
|
24
24
|
{
|
|
25
25
|
"kind": "class",
|
|
@@ -600,7 +600,7 @@
|
|
|
600
600
|
"name": "ColorArea",
|
|
601
601
|
"declaration": {
|
|
602
602
|
"name": "ColorArea",
|
|
603
|
-
"module": "src/ColorArea.
|
|
603
|
+
"module": "src/ColorArea.js"
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/color-area",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.11",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -20,11 +20,28 @@
|
|
|
20
20
|
"module": "src/index.js",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
|
-
".":
|
|
24
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"development": "./src/index.dev.js",
|
|
25
|
+
"default": "./src/index.js"
|
|
26
|
+
},
|
|
25
27
|
"./package.json": "./package.json",
|
|
26
|
-
"./
|
|
27
|
-
|
|
28
|
+
"./src/ColorArea.js": {
|
|
29
|
+
"development": "./src/ColorArea.dev.js",
|
|
30
|
+
"default": "./src/ColorArea.js"
|
|
31
|
+
},
|
|
32
|
+
"./src/color-area.css.js": "./src/color-area.css.js",
|
|
33
|
+
"./src/index.js": {
|
|
34
|
+
"development": "./src/index.dev.js",
|
|
35
|
+
"default": "./src/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./src/types.js": {
|
|
38
|
+
"development": "./src/types.dev.js",
|
|
39
|
+
"default": "./src/types.js"
|
|
40
|
+
},
|
|
41
|
+
"./sp-color-area.js": {
|
|
42
|
+
"development": "./sp-color-area.dev.js",
|
|
43
|
+
"default": "./sp-color-area.js"
|
|
44
|
+
}
|
|
28
45
|
},
|
|
29
46
|
"scripts": {
|
|
30
47
|
"test": "echo \"Error: run tests from mono-repo root.\" && exit 1"
|
|
@@ -45,8 +62,8 @@
|
|
|
45
62
|
],
|
|
46
63
|
"dependencies": {
|
|
47
64
|
"@ctrl/tinycolor": "^3.3.3",
|
|
48
|
-
"@spectrum-web-components/base": "^0.
|
|
49
|
-
"@spectrum-web-components/color-handle": "^0.3.
|
|
65
|
+
"@spectrum-web-components/base": "^0.6.0",
|
|
66
|
+
"@spectrum-web-components/color-handle": "^0.3.11",
|
|
50
67
|
"tslib": "^2.0.0"
|
|
51
68
|
},
|
|
52
69
|
"devDependencies": {
|
|
@@ -57,5 +74,5 @@
|
|
|
57
74
|
"sideEffects": [
|
|
58
75
|
"./sp-*.js"
|
|
59
76
|
],
|
|
60
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "50cac779bbb0d6735c2061f1eceb86b9daf9b22b"
|
|
61
78
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-color-area.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 { 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;AAEA,eAAe,OAAO,iBAAiB,SAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-color-area.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
import { ColorArea } from './src/ColorArea.js';
|
|
13
|
-
customElements.define('sp-color-area', ColorArea);
|
|
14
|
-
//# sourceMappingURL=sp-color-area.js.map
|
|
1
|
+
import { ColorArea } from "./src/ColorArea.js";
|
|
2
|
+
customElements.define("sp-color-area", ColorArea);
|
|
3
|
+
//# sourceMappingURL=sp-color-area.js.map
|
package/sp-color-area.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["sp-color-area.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 { 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": "AAYA;AAEA,eAAe,OAAO,iBAAiB,SAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,486 @@
|
|
|
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
|
+
SpectrumElement
|
|
15
|
+
} from "@spectrum-web-components/base";
|
|
16
|
+
import { ifDefined } from "@spectrum-web-components/base/src/directives.js";
|
|
17
|
+
import {
|
|
18
|
+
property,
|
|
19
|
+
query
|
|
20
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
21
|
+
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
|
+
import "@spectrum-web-components/color-handle/sp-color-handle.js";
|
|
27
|
+
import { TinyColor } from "@ctrl/tinycolor";
|
|
28
|
+
import styles from "./color-area.css.js";
|
|
29
|
+
export class ColorArea extends SpectrumElement {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.disabled = false;
|
|
33
|
+
this.focused = false;
|
|
34
|
+
this.labelX = "saturation";
|
|
35
|
+
this.labelY = "luminosity";
|
|
36
|
+
this._hue = 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.activeAxis = "x";
|
|
44
|
+
this._x = 1;
|
|
45
|
+
this._y = 0;
|
|
46
|
+
this.step = 0.01;
|
|
47
|
+
this.altered = 0;
|
|
48
|
+
this.activeKeys = /* @__PURE__ */ new Set();
|
|
49
|
+
this._pointerDown = false;
|
|
50
|
+
}
|
|
51
|
+
static get styles() {
|
|
52
|
+
return [styles];
|
|
53
|
+
}
|
|
54
|
+
get hue() {
|
|
55
|
+
return this._hue;
|
|
56
|
+
}
|
|
57
|
+
set hue(value) {
|
|
58
|
+
const hue = Math.min(360, Math.max(0, value));
|
|
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);
|
|
67
|
+
}
|
|
68
|
+
get value() {
|
|
69
|
+
return this.color;
|
|
70
|
+
}
|
|
71
|
+
get color() {
|
|
72
|
+
switch (this._format.format) {
|
|
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
|
+
}
|
|
104
|
+
}
|
|
105
|
+
set color(color) {
|
|
106
|
+
if (color === this.color) {
|
|
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);
|
|
137
|
+
}
|
|
138
|
+
get x() {
|
|
139
|
+
return this._x;
|
|
140
|
+
}
|
|
141
|
+
set x(x) {
|
|
142
|
+
if (x === this.x) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const oldValue = this.x;
|
|
146
|
+
if (this.inputX) {
|
|
147
|
+
this.inputX.value = x.toString();
|
|
148
|
+
this._x = this.inputX.valueAsNumber;
|
|
149
|
+
} else {
|
|
150
|
+
this._x = x;
|
|
151
|
+
}
|
|
152
|
+
this.requestUpdate("x", oldValue);
|
|
153
|
+
}
|
|
154
|
+
get y() {
|
|
155
|
+
return this._y;
|
|
156
|
+
}
|
|
157
|
+
set y(y) {
|
|
158
|
+
if (y === this.y) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const oldValue = this.y;
|
|
162
|
+
if (this.inputY) {
|
|
163
|
+
this.inputY.value = y.toString();
|
|
164
|
+
this._y = this.inputY.valueAsNumber;
|
|
165
|
+
} else {
|
|
166
|
+
this._y = y;
|
|
167
|
+
}
|
|
168
|
+
this.requestUpdate("y", oldValue);
|
|
169
|
+
}
|
|
170
|
+
focus(focusOptions = {}) {
|
|
171
|
+
super.focus(focusOptions);
|
|
172
|
+
this.forwardFocus();
|
|
173
|
+
}
|
|
174
|
+
forwardFocus() {
|
|
175
|
+
this.focused = this.hasVisibleFocusInTree();
|
|
176
|
+
if (this.activeAxis === "x") {
|
|
177
|
+
this.inputX.focus();
|
|
178
|
+
} else {
|
|
179
|
+
this.inputY.focus();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
handleFocusin() {
|
|
183
|
+
this.focused = true;
|
|
184
|
+
}
|
|
185
|
+
handleFocusout() {
|
|
186
|
+
if (this._pointerDown) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this.focused = false;
|
|
190
|
+
}
|
|
191
|
+
handleKeydown(event) {
|
|
192
|
+
const { code } = event;
|
|
193
|
+
this.focused = true;
|
|
194
|
+
this.altered = [event.shiftKey, event.ctrlKey, event.altKey].filter((key) => !!key).length;
|
|
195
|
+
const isArrowKey = code.search("Arrow") === 0;
|
|
196
|
+
if (isArrowKey) {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
this.activeKeys.add(code);
|
|
199
|
+
this.handleKeypress();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
handleKeypress() {
|
|
203
|
+
let deltaX = 0;
|
|
204
|
+
let deltaY = 0;
|
|
205
|
+
const step = Math.max(this.step, this.altered * 5 * this.step);
|
|
206
|
+
this.activeKeys.forEach((code) => {
|
|
207
|
+
switch (code) {
|
|
208
|
+
case "ArrowUp":
|
|
209
|
+
deltaY = step * -1;
|
|
210
|
+
break;
|
|
211
|
+
case "ArrowDown":
|
|
212
|
+
deltaY = step * 1;
|
|
213
|
+
break;
|
|
214
|
+
case "ArrowLeft":
|
|
215
|
+
deltaX = step * -1;
|
|
216
|
+
break;
|
|
217
|
+
case "ArrowRight":
|
|
218
|
+
deltaX = step * 1;
|
|
219
|
+
break;
|
|
220
|
+
default:
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
if (deltaX != 0) {
|
|
225
|
+
this.activeAxis = "x";
|
|
226
|
+
this.inputX.focus();
|
|
227
|
+
} else if (deltaY != 0) {
|
|
228
|
+
this.activeAxis = "y";
|
|
229
|
+
this.inputY.focus();
|
|
230
|
+
}
|
|
231
|
+
this.x = Math.min(1, Math.max(this.x + deltaX, 0));
|
|
232
|
+
this.y = Math.min(1, Math.max(this.y + deltaY, 0));
|
|
233
|
+
this._previousColor = this._color.clone();
|
|
234
|
+
this._color = new TinyColor({ h: this.hue, s: this.x, v: 1 - this.y });
|
|
235
|
+
if (deltaX != 0 || deltaY != 0) {
|
|
236
|
+
this.dispatchEvent(new Event("input", {
|
|
237
|
+
bubbles: true,
|
|
238
|
+
composed: true
|
|
239
|
+
}));
|
|
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;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
handleKeyup(event) {
|
|
251
|
+
event.preventDefault();
|
|
252
|
+
const { code } = event;
|
|
253
|
+
this.activeKeys.delete(code);
|
|
254
|
+
}
|
|
255
|
+
handleInput(event) {
|
|
256
|
+
const { valueAsNumber, name } = event.target;
|
|
257
|
+
this[name] = valueAsNumber;
|
|
258
|
+
this._color = new TinyColor({ h: this.hue, s: this.x, v: 1 - this.y });
|
|
259
|
+
}
|
|
260
|
+
handleChange(event) {
|
|
261
|
+
this.handleInput(event);
|
|
262
|
+
this.dispatchEvent(new Event("change", {
|
|
263
|
+
bubbles: true,
|
|
264
|
+
composed: true,
|
|
265
|
+
cancelable: true
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
handlePointerdown(event) {
|
|
269
|
+
if (event.button !== 0) {
|
|
270
|
+
event.preventDefault();
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
this._pointerDown = true;
|
|
274
|
+
this._previousColor = this._color.clone();
|
|
275
|
+
this.boundingClientRect = this.getBoundingClientRect();
|
|
276
|
+
event.target.setPointerCapture(event.pointerId);
|
|
277
|
+
if (event.pointerType === "mouse") {
|
|
278
|
+
this.focused = true;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
handlePointermove(event) {
|
|
282
|
+
const [x, y] = this.calculateHandlePosition(event);
|
|
283
|
+
this._color = new TinyColor({ h: this.hue, s: x, v: 1 - y });
|
|
284
|
+
this.x = x;
|
|
285
|
+
this.y = y;
|
|
286
|
+
this.dispatchEvent(new Event("input", {
|
|
287
|
+
bubbles: true,
|
|
288
|
+
composed: true,
|
|
289
|
+
cancelable: true
|
|
290
|
+
}));
|
|
291
|
+
}
|
|
292
|
+
handlePointerup(event) {
|
|
293
|
+
event.preventDefault();
|
|
294
|
+
this._pointerDown = false;
|
|
295
|
+
event.target.releasePointerCapture(event.pointerId);
|
|
296
|
+
const applyDefault = this.dispatchEvent(new Event("change", {
|
|
297
|
+
bubbles: true,
|
|
298
|
+
composed: true,
|
|
299
|
+
cancelable: true
|
|
300
|
+
}));
|
|
301
|
+
this.inputX.focus();
|
|
302
|
+
if (event.pointerType === "mouse") {
|
|
303
|
+
this.focused = false;
|
|
304
|
+
}
|
|
305
|
+
if (!applyDefault) {
|
|
306
|
+
this._color = this._previousColor;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
calculateHandlePosition(event) {
|
|
310
|
+
if (!this.boundingClientRect) {
|
|
311
|
+
return [this.x, this.y];
|
|
312
|
+
}
|
|
313
|
+
const rect = this.boundingClientRect;
|
|
314
|
+
const minOffsetX = rect.left;
|
|
315
|
+
const minOffsetY = rect.top;
|
|
316
|
+
const offsetX = event.clientX;
|
|
317
|
+
const offsetY = event.clientY;
|
|
318
|
+
const width = rect.width;
|
|
319
|
+
const height = rect.height;
|
|
320
|
+
const percentX = Math.max(0, Math.min(1, (offsetX - minOffsetX) / width));
|
|
321
|
+
const percentY = Math.max(0, Math.min(1, (offsetY - minOffsetY) / height));
|
|
322
|
+
return [percentX, percentY];
|
|
323
|
+
}
|
|
324
|
+
handleAreaPointerdown(event) {
|
|
325
|
+
if (event.button !== 0) {
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
event.stopPropagation();
|
|
329
|
+
event.preventDefault();
|
|
330
|
+
this.handle.dispatchEvent(new PointerEvent("pointerdown", event));
|
|
331
|
+
this.handlePointermove(event);
|
|
332
|
+
}
|
|
333
|
+
render() {
|
|
334
|
+
var _a, _b;
|
|
335
|
+
const { width = 0, height = 0 } = this.boundingClientRect || {};
|
|
336
|
+
return html`
|
|
337
|
+
<div
|
|
338
|
+
@pointerdown=${this.handleAreaPointerdown}
|
|
339
|
+
class="gradient"
|
|
340
|
+
style="background:
|
|
341
|
+
linear-gradient(to top, black 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%),
|
|
342
|
+
linear-gradient(to right, white 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%), hsl(${this.hue}, 100%, 50%);"
|
|
343
|
+
>
|
|
344
|
+
<slot name="gradient"></slot>
|
|
345
|
+
</div>
|
|
346
|
+
|
|
347
|
+
<sp-color-handle
|
|
348
|
+
tabindex=${ifDefined(this.focused ? void 0 : "0")}
|
|
349
|
+
@focus=${this.forwardFocus}
|
|
350
|
+
?focused=${this.focused}
|
|
351
|
+
class="handle"
|
|
352
|
+
color=${this._color.toHslString()}
|
|
353
|
+
?disabled=${this.disabled}
|
|
354
|
+
style="transform: translate(${this.x * width}px, ${this.y * height}px);"
|
|
355
|
+
${streamingListener({
|
|
356
|
+
start: ["pointerdown", this.handlePointerdown],
|
|
357
|
+
streamInside: ["pointermove", this.handlePointermove],
|
|
358
|
+
end: [["pointerup", "pointercancel"], this.handlePointerup]
|
|
359
|
+
})}
|
|
360
|
+
></sp-color-handle>
|
|
361
|
+
|
|
362
|
+
<div>
|
|
363
|
+
<input
|
|
364
|
+
type="range"
|
|
365
|
+
class="slider"
|
|
366
|
+
name="x"
|
|
367
|
+
aria-label=${(_a = this.label) != null ? _a : this.labelX}
|
|
368
|
+
min="0"
|
|
369
|
+
max="1"
|
|
370
|
+
step=${this.step}
|
|
371
|
+
tabindex="-1"
|
|
372
|
+
.value=${String(this.x)}
|
|
373
|
+
@input=${this.handleInput}
|
|
374
|
+
@change=${this.handleChange}
|
|
375
|
+
/>
|
|
376
|
+
</div>
|
|
377
|
+
<div>
|
|
378
|
+
<input
|
|
379
|
+
type="range"
|
|
380
|
+
class="slider"
|
|
381
|
+
name="y"
|
|
382
|
+
aria-label=${(_b = this.label) != null ? _b : this.labelY}
|
|
383
|
+
min="0"
|
|
384
|
+
max="1"
|
|
385
|
+
step=${this.step}
|
|
386
|
+
tabindex="-1"
|
|
387
|
+
.value=${String(this.y)}
|
|
388
|
+
@input=${this.handleInput}
|
|
389
|
+
@change=${this.handleChange}
|
|
390
|
+
/>
|
|
391
|
+
</div>
|
|
392
|
+
`;
|
|
393
|
+
}
|
|
394
|
+
firstUpdated(changed) {
|
|
395
|
+
super.firstUpdated(changed);
|
|
396
|
+
this.boundingClientRect = this.getBoundingClientRect();
|
|
397
|
+
this.addEventListener("focusin", this.handleFocusin);
|
|
398
|
+
this.addEventListener("focusout", this.handleFocusout);
|
|
399
|
+
this.addEventListener("keyup", this.handleKeyup);
|
|
400
|
+
this.addEventListener("keydown", this.handleKeydown);
|
|
401
|
+
}
|
|
402
|
+
updated(changed) {
|
|
403
|
+
super.updated(changed);
|
|
404
|
+
if (this.x !== this.inputX.valueAsNumber) {
|
|
405
|
+
this._x = this.inputX.valueAsNumber;
|
|
406
|
+
}
|
|
407
|
+
if (this.y !== this.inputY.valueAsNumber) {
|
|
408
|
+
this._y = this.inputY.valueAsNumber;
|
|
409
|
+
}
|
|
410
|
+
if (changed.has("focused") && this.focused) {
|
|
411
|
+
const parentX = this.inputX.parentElement;
|
|
412
|
+
const parentY = this.inputY.parentElement;
|
|
413
|
+
if (!parentX.shadowRoot && !parentY.shadowRoot) {
|
|
414
|
+
parentX.attachShadow({ mode: "open" });
|
|
415
|
+
parentY.attachShadow({ mode: "open" });
|
|
416
|
+
const slot = '<div tabindex="-1"><slot></slot></div>';
|
|
417
|
+
parentX.shadowRoot.innerHTML = slot;
|
|
418
|
+
parentY.shadowRoot.innerHTML = slot;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
connectedCallback() {
|
|
423
|
+
var _a;
|
|
424
|
+
super.connectedCallback();
|
|
425
|
+
if (!this.observer && window.ResizeObserver) {
|
|
426
|
+
this.observer = new window.ResizeObserver((entries) => {
|
|
427
|
+
for (const entry of entries) {
|
|
428
|
+
this.boundingClientRect = entry.contentRect;
|
|
429
|
+
}
|
|
430
|
+
this.requestUpdate();
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
(_a = this.observer) == null ? void 0 : _a.observe(this);
|
|
434
|
+
}
|
|
435
|
+
disconnectedCallback() {
|
|
436
|
+
var _a;
|
|
437
|
+
(_a = this.observer) == null ? void 0 : _a.unobserve(this);
|
|
438
|
+
super.disconnectedCallback();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
__decorateClass([
|
|
442
|
+
property({ type: Boolean, reflect: true })
|
|
443
|
+
], ColorArea.prototype, "disabled", 2);
|
|
444
|
+
__decorateClass([
|
|
445
|
+
property({ type: Boolean, reflect: true })
|
|
446
|
+
], ColorArea.prototype, "focused", 2);
|
|
447
|
+
__decorateClass([
|
|
448
|
+
property({ type: String })
|
|
449
|
+
], ColorArea.prototype, "label", 2);
|
|
450
|
+
__decorateClass([
|
|
451
|
+
property({ type: String, attribute: "label-x" })
|
|
452
|
+
], ColorArea.prototype, "labelX", 2);
|
|
453
|
+
__decorateClass([
|
|
454
|
+
property({ type: String, attribute: "label-y" })
|
|
455
|
+
], ColorArea.prototype, "labelY", 2);
|
|
456
|
+
__decorateClass([
|
|
457
|
+
query(".handle")
|
|
458
|
+
], ColorArea.prototype, "handle", 2);
|
|
459
|
+
__decorateClass([
|
|
460
|
+
property({ type: Number })
|
|
461
|
+
], ColorArea.prototype, "hue", 1);
|
|
462
|
+
__decorateClass([
|
|
463
|
+
property({ type: String })
|
|
464
|
+
], ColorArea.prototype, "value", 1);
|
|
465
|
+
__decorateClass([
|
|
466
|
+
property({ type: String })
|
|
467
|
+
], ColorArea.prototype, "color", 1);
|
|
468
|
+
__decorateClass([
|
|
469
|
+
property({ attribute: false })
|
|
470
|
+
], ColorArea.prototype, "activeAxis", 2);
|
|
471
|
+
__decorateClass([
|
|
472
|
+
property({ type: Number })
|
|
473
|
+
], ColorArea.prototype, "x", 1);
|
|
474
|
+
__decorateClass([
|
|
475
|
+
property({ type: Number })
|
|
476
|
+
], ColorArea.prototype, "y", 1);
|
|
477
|
+
__decorateClass([
|
|
478
|
+
property({ type: Number })
|
|
479
|
+
], ColorArea.prototype, "step", 2);
|
|
480
|
+
__decorateClass([
|
|
481
|
+
query('[name="x"]')
|
|
482
|
+
], ColorArea.prototype, "inputX", 2);
|
|
483
|
+
__decorateClass([
|
|
484
|
+
query('[name="y"]')
|
|
485
|
+
], ColorArea.prototype, "inputY", 2);
|
|
486
|
+
//# sourceMappingURL=ColorArea.dev.js.map
|