@spectrum-web-components/color-area 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/sp-color-area.d.ts +6 -0
- package/sp-color-area.dev.js +5 -0
- package/sp-color-area.dev.js.map +7 -0
- package/sp-color-area.js +2 -0
- package/sp-color-area.js.map +7 -0
- package/src/ColorArea.d.ts +65 -0
- package/src/ColorArea.dev.js +507 -0
- package/src/ColorArea.dev.js.map +7 -0
- package/src/ColorArea.js +64 -0
- package/src/ColorArea.js.map +7 -0
- package/src/color-area-overrides.css.d.ts +2 -0
- package/src/color-area-overrides.css.dev.js +7 -0
- package/src/color-area-overrides.css.dev.js.map +7 -0
- package/src/color-area-overrides.css.js +4 -0
- package/src/color-area-overrides.css.js.map +7 -0
- package/src/color-area.css.d.ts +2 -0
- package/src/color-area.css.dev.js +7 -0
- package/src/color-area.css.dev.js.map +7 -0
- package/src/color-area.css.js +4 -0
- package/src/color-area.css.js.map +7 -0
- package/src/index.d.ts +1 -0
- package/src/index.dev.js +3 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +2 -0
- package/src/index.js.map +7 -0
- package/src/spectrum-color-area.css.d.ts +2 -0
- package/src/spectrum-color-area.css.dev.js +7 -0
- package/src/spectrum-color-area.css.dev.js.map +7 -0
- package/src/spectrum-color-area.css.js +4 -0
- package/src/spectrum-color-area.css.js.map +7 -0
- package/src/types.d.ts +13 -0
- package/src/types.dev.js +2 -0
- package/src/types.dev.js.map +7 -0
- package/src/types.js +2 -0
- package/src/types.js.map +7 -0
- package/stories/color-area.stories.js +149 -0
- package/stories/color-area.stories.js.map +7 -0
- package/test/benchmark/basic-test.js +8 -0
- package/test/benchmark/basic-test.js.map +7 -0
- package/test/color-area-memory.test.js +8 -0
- package/test/color-area-memory.test.js.map +7 -0
- package/test/color-area.test-vrt.js +5 -0
- package/test/color-area.test-vrt.js.map +7 -0
- package/test/color-area.test.js +776 -0
- package/test/color-area.test.js.map +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/color-area",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -63,11 +63,11 @@
|
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@ctrl/tinycolor": "^4.0.3",
|
|
66
|
-
"@spectrum-web-components/base": "^1.1.
|
|
67
|
-
"@spectrum-web-components/color-handle": "^1.1.
|
|
68
|
-
"@spectrum-web-components/opacity-checkerboard": "^1.1.
|
|
69
|
-
"@spectrum-web-components/reactive-controllers": "^1.1.
|
|
70
|
-
"@spectrum-web-components/shared": "^1.1.
|
|
66
|
+
"@spectrum-web-components/base": "^1.1.2",
|
|
67
|
+
"@spectrum-web-components/color-handle": "^1.1.2",
|
|
68
|
+
"@spectrum-web-components/opacity-checkerboard": "^1.1.2",
|
|
69
|
+
"@spectrum-web-components/reactive-controllers": "^1.1.2",
|
|
70
|
+
"@spectrum-web-components/shared": "^1.1.2"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@spectrum-css/colorarea": "6.0.0-s2-foundations.15"
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"./sp-*.js",
|
|
79
79
|
"./**/*.dev.js"
|
|
80
80
|
],
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "9ee45f2dfd3ac1939072726d00195c6c05d9a562"
|
|
82
82
|
}
|
|
@@ -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'\nimport { defineElement } from '@spectrum-web-components/base/src/define-element.js';\n\ndefineElement('sp-color-area', ColorArea);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-color-area': ColorArea;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAYA,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAE9B,cAAc,iBAAiB,SAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/sp-color-area.js
ADDED
|
@@ -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.js';\nimport { defineElement } from '@spectrum-web-components/base/src/define-element.js';\n\ndefineElement('sp-color-area', ColorArea);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-color-area': ColorArea;\n }\n}\n"],
|
|
5
|
+
"mappings": "aAYA,OAAS,aAAAA,MAAiB,qBAC1B,OAAS,iBAAAC,MAAqB,sDAE9BA,EAAc,gBAAiBD,CAAS",
|
|
6
|
+
"names": ["ColorArea", "defineElement"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
|
|
2
|
+
import '@spectrum-web-components/color-handle/sp-color-handle.js';
|
|
3
|
+
import { ColorValue } from '@spectrum-web-components/reactive-controllers/src/Color.js';
|
|
4
|
+
/**
|
|
5
|
+
* @element sp-color-area
|
|
6
|
+
* @slot gradient - a custom gradient visually outlining the available color values
|
|
7
|
+
* @fires input - The value of the Color Area has changed.
|
|
8
|
+
* @fires change - An alteration to the value of the Color Area has been committed by the user.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ColorArea extends SpectrumElement {
|
|
11
|
+
static get styles(): CSSResultArray;
|
|
12
|
+
dir: 'ltr' | 'rtl';
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
focused: boolean;
|
|
15
|
+
labelX: string;
|
|
16
|
+
labelY: string;
|
|
17
|
+
private handle;
|
|
18
|
+
private languageResolver;
|
|
19
|
+
private colorController;
|
|
20
|
+
get hue(): number;
|
|
21
|
+
set hue(value: number);
|
|
22
|
+
get value(): ColorValue;
|
|
23
|
+
get color(): ColorValue;
|
|
24
|
+
set color(color: ColorValue);
|
|
25
|
+
private activeAxis;
|
|
26
|
+
get x(): number;
|
|
27
|
+
set x(x: number);
|
|
28
|
+
private _x;
|
|
29
|
+
get y(): number;
|
|
30
|
+
set y(y: number);
|
|
31
|
+
private _y;
|
|
32
|
+
step: number;
|
|
33
|
+
inputX: HTMLInputElement;
|
|
34
|
+
inputY: HTMLInputElement;
|
|
35
|
+
private altered;
|
|
36
|
+
private activeKeys;
|
|
37
|
+
private _valueChanged;
|
|
38
|
+
focus(focusOptions?: FocusOptions): void;
|
|
39
|
+
private forwardFocus;
|
|
40
|
+
private handleFocus;
|
|
41
|
+
handleBlur(): void;
|
|
42
|
+
private handleKeydown;
|
|
43
|
+
private handleKeypress;
|
|
44
|
+
private handleKeyup;
|
|
45
|
+
private handleInput;
|
|
46
|
+
private handleChange;
|
|
47
|
+
private boundingClientRect;
|
|
48
|
+
_pointerDown: boolean;
|
|
49
|
+
private handlePointerdown;
|
|
50
|
+
private handlePointermove;
|
|
51
|
+
private handlePointerup;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the value under the cursor
|
|
54
|
+
* @param: PointerEvent on slider
|
|
55
|
+
* @return: Slider value that correlates to the position under the pointer
|
|
56
|
+
*/
|
|
57
|
+
private calculateHandlePosition;
|
|
58
|
+
private handleAreaPointerdown;
|
|
59
|
+
protected render(): TemplateResult;
|
|
60
|
+
protected firstUpdated(changed: PropertyValues): void;
|
|
61
|
+
protected updated(changed: PropertyValues): void;
|
|
62
|
+
private observer?;
|
|
63
|
+
connectedCallback(): void;
|
|
64
|
+
disconnectedCallback(): void;
|
|
65
|
+
}
|
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
5
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
6
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
7
|
+
if (decorator = decorators[i])
|
|
8
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
9
|
+
if (kind && result) __defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html,
|
|
14
|
+
SpectrumElement
|
|
15
|
+
} from "@spectrum-web-components/base";
|
|
16
|
+
import {
|
|
17
|
+
ifDefined,
|
|
18
|
+
styleMap
|
|
19
|
+
} from "@spectrum-web-components/base/src/directives.js";
|
|
20
|
+
import {
|
|
21
|
+
property,
|
|
22
|
+
query
|
|
23
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
24
|
+
import { streamingListener } from "@spectrum-web-components/base/src/streaming-listener.js";
|
|
25
|
+
import "@spectrum-web-components/color-handle/sp-color-handle.js";
|
|
26
|
+
import {
|
|
27
|
+
ColorController
|
|
28
|
+
} from "@spectrum-web-components/reactive-controllers/src/Color.js";
|
|
29
|
+
import { LanguageResolutionController } from "@spectrum-web-components/reactive-controllers/src/LanguageResolution.js";
|
|
30
|
+
import {
|
|
31
|
+
isAndroid,
|
|
32
|
+
isIOS
|
|
33
|
+
} from "@spectrum-web-components/shared/src/platform.js";
|
|
34
|
+
import styles from "./color-area.css.js";
|
|
35
|
+
export class ColorArea extends SpectrumElement {
|
|
36
|
+
constructor() {
|
|
37
|
+
super(...arguments);
|
|
38
|
+
this.disabled = false;
|
|
39
|
+
this.focused = false;
|
|
40
|
+
this.labelX = "saturation";
|
|
41
|
+
this.labelY = "luminosity";
|
|
42
|
+
this.languageResolver = new LanguageResolutionController(this);
|
|
43
|
+
this.colorController = new ColorController(this, {
|
|
44
|
+
extractColorFromState: () => ({
|
|
45
|
+
h: this.hue,
|
|
46
|
+
s: this.x,
|
|
47
|
+
v: this.y
|
|
48
|
+
}),
|
|
49
|
+
applyColorToState: ({ s, v }) => {
|
|
50
|
+
this._x = s;
|
|
51
|
+
this._y = v;
|
|
52
|
+
this.requestUpdate();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.activeAxis = "x";
|
|
56
|
+
this._x = 1;
|
|
57
|
+
this._y = 1;
|
|
58
|
+
this.step = 0.01;
|
|
59
|
+
this.altered = 0;
|
|
60
|
+
this.activeKeys = /* @__PURE__ */ new Set();
|
|
61
|
+
this._valueChanged = false;
|
|
62
|
+
this._pointerDown = false;
|
|
63
|
+
}
|
|
64
|
+
static get styles() {
|
|
65
|
+
return [styles];
|
|
66
|
+
}
|
|
67
|
+
get hue() {
|
|
68
|
+
return this.colorController.hue;
|
|
69
|
+
}
|
|
70
|
+
set hue(value) {
|
|
71
|
+
this.colorController.hue = value;
|
|
72
|
+
}
|
|
73
|
+
get value() {
|
|
74
|
+
return this.colorController.color;
|
|
75
|
+
}
|
|
76
|
+
get color() {
|
|
77
|
+
return this.colorController.color;
|
|
78
|
+
}
|
|
79
|
+
set color(color) {
|
|
80
|
+
this.colorController.color = color;
|
|
81
|
+
}
|
|
82
|
+
get x() {
|
|
83
|
+
return this._x;
|
|
84
|
+
}
|
|
85
|
+
set x(x) {
|
|
86
|
+
if (x === this.x) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const oldValue = this.x;
|
|
90
|
+
this._x = x;
|
|
91
|
+
if (this.inputX) {
|
|
92
|
+
this.inputX.value = x.toString();
|
|
93
|
+
this._x = this.inputX.valueAsNumber;
|
|
94
|
+
}
|
|
95
|
+
this.requestUpdate("x", oldValue);
|
|
96
|
+
this.colorController.applyColorFromState();
|
|
97
|
+
}
|
|
98
|
+
get y() {
|
|
99
|
+
return this._y;
|
|
100
|
+
}
|
|
101
|
+
set y(y) {
|
|
102
|
+
if (y === this.y) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const oldValue = this.y;
|
|
106
|
+
this._y = y;
|
|
107
|
+
if (this.inputY) {
|
|
108
|
+
this.inputY.value = y.toString();
|
|
109
|
+
this._y = this.inputY.valueAsNumber;
|
|
110
|
+
}
|
|
111
|
+
this.requestUpdate("y", oldValue);
|
|
112
|
+
this.colorController.applyColorFromState();
|
|
113
|
+
}
|
|
114
|
+
focus(focusOptions = {}) {
|
|
115
|
+
super.focus(focusOptions);
|
|
116
|
+
this.forwardFocus();
|
|
117
|
+
}
|
|
118
|
+
forwardFocus() {
|
|
119
|
+
this.focused = this.hasVisibleFocusInTree();
|
|
120
|
+
if (this.activeAxis === "x") {
|
|
121
|
+
this.inputX.focus();
|
|
122
|
+
} else {
|
|
123
|
+
this.inputY.focus();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
handleFocus() {
|
|
127
|
+
this.focused = true;
|
|
128
|
+
this._valueChanged = false;
|
|
129
|
+
}
|
|
130
|
+
handleBlur() {
|
|
131
|
+
if (this._pointerDown) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
this.altered = 0;
|
|
135
|
+
this.focused = false;
|
|
136
|
+
this._valueChanged = false;
|
|
137
|
+
}
|
|
138
|
+
handleKeydown(event) {
|
|
139
|
+
const { code } = event;
|
|
140
|
+
this.focused = true;
|
|
141
|
+
this.altered = [event.shiftKey, event.ctrlKey, event.altKey].filter(
|
|
142
|
+
(key) => !!key
|
|
143
|
+
).length;
|
|
144
|
+
const isArrowKey = code.search("Arrow") === 0 || code.search("Page") === 0 || code.search("Home") === 0 || code.search("End") === 0;
|
|
145
|
+
if (isArrowKey) {
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
this.activeKeys.add(code);
|
|
148
|
+
this.handleKeypress();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
handleKeypress() {
|
|
152
|
+
let deltaX = 0;
|
|
153
|
+
let deltaY = 0;
|
|
154
|
+
const step = Math.max(this.step, this.altered * 5 * this.step);
|
|
155
|
+
this.activeKeys.forEach((code) => {
|
|
156
|
+
switch (code) {
|
|
157
|
+
case "ArrowUp":
|
|
158
|
+
deltaY = step;
|
|
159
|
+
break;
|
|
160
|
+
case "ArrowDown":
|
|
161
|
+
deltaY = step * -1;
|
|
162
|
+
break;
|
|
163
|
+
case "ArrowLeft":
|
|
164
|
+
deltaX = this.step * (this.isLTR ? -1 : 1);
|
|
165
|
+
break;
|
|
166
|
+
case "ArrowRight":
|
|
167
|
+
deltaX = this.step * (this.isLTR ? 1 : -1);
|
|
168
|
+
break;
|
|
169
|
+
case "PageUp":
|
|
170
|
+
deltaY = step * 10;
|
|
171
|
+
break;
|
|
172
|
+
case "PageDown":
|
|
173
|
+
deltaY = step * -10;
|
|
174
|
+
break;
|
|
175
|
+
case "Home":
|
|
176
|
+
deltaX = step * (this.isLTR ? -10 : 10);
|
|
177
|
+
break;
|
|
178
|
+
case "End":
|
|
179
|
+
deltaX = step * (this.isLTR ? 10 : -10);
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
if (deltaX != 0) {
|
|
186
|
+
this.activeAxis = "x";
|
|
187
|
+
this.inputX.focus();
|
|
188
|
+
} else if (deltaY != 0) {
|
|
189
|
+
this.activeAxis = "y";
|
|
190
|
+
this.inputY.focus();
|
|
191
|
+
}
|
|
192
|
+
this.x = Math.min(1, Math.max(this.x + deltaX, 0));
|
|
193
|
+
this.y = Math.min(1, Math.max(this.y + deltaY, 0));
|
|
194
|
+
this.colorController.savePreviousColor();
|
|
195
|
+
this.colorController.applyColorFromState();
|
|
196
|
+
if (deltaX != 0 || deltaY != 0) {
|
|
197
|
+
this._valueChanged = true;
|
|
198
|
+
this.dispatchEvent(
|
|
199
|
+
new Event("input", {
|
|
200
|
+
bubbles: true,
|
|
201
|
+
composed: true
|
|
202
|
+
})
|
|
203
|
+
);
|
|
204
|
+
const applyDefault = this.dispatchEvent(
|
|
205
|
+
new Event("change", {
|
|
206
|
+
bubbles: true,
|
|
207
|
+
composed: true,
|
|
208
|
+
cancelable: true
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
if (!applyDefault) {
|
|
212
|
+
this.colorController.restorePreviousColor();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
handleKeyup(event) {
|
|
217
|
+
event.preventDefault();
|
|
218
|
+
const { code } = event;
|
|
219
|
+
this.activeKeys.delete(code);
|
|
220
|
+
}
|
|
221
|
+
handleInput(event) {
|
|
222
|
+
const { valueAsNumber, name } = event.target;
|
|
223
|
+
this[name] = valueAsNumber;
|
|
224
|
+
this.colorController.applyColorFromState();
|
|
225
|
+
}
|
|
226
|
+
handleChange(event) {
|
|
227
|
+
this.handleInput(event);
|
|
228
|
+
this.dispatchEvent(
|
|
229
|
+
new Event("change", {
|
|
230
|
+
bubbles: true,
|
|
231
|
+
composed: true,
|
|
232
|
+
cancelable: true
|
|
233
|
+
})
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
handlePointerdown(event) {
|
|
237
|
+
if (event.button !== 0) {
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
this._pointerDown = true;
|
|
242
|
+
this.colorController.savePreviousColor();
|
|
243
|
+
this.boundingClientRect = this.getBoundingClientRect();
|
|
244
|
+
event.target.setPointerCapture(event.pointerId);
|
|
245
|
+
if (event.pointerType === "mouse") {
|
|
246
|
+
this.focused = true;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
handlePointermove(event) {
|
|
250
|
+
const [x, y] = this.calculateHandlePosition(event);
|
|
251
|
+
this._valueChanged = false;
|
|
252
|
+
this.x = x;
|
|
253
|
+
this.y = 1 - y;
|
|
254
|
+
this.colorController.applyColorFromState();
|
|
255
|
+
this.dispatchEvent(
|
|
256
|
+
new Event("input", {
|
|
257
|
+
bubbles: true,
|
|
258
|
+
composed: true,
|
|
259
|
+
cancelable: true
|
|
260
|
+
})
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
handlePointerup(event) {
|
|
264
|
+
event.preventDefault();
|
|
265
|
+
this._pointerDown = false;
|
|
266
|
+
event.target.releasePointerCapture(event.pointerId);
|
|
267
|
+
const applyDefault = this.dispatchEvent(
|
|
268
|
+
new Event("change", {
|
|
269
|
+
bubbles: true,
|
|
270
|
+
composed: true,
|
|
271
|
+
cancelable: true
|
|
272
|
+
})
|
|
273
|
+
);
|
|
274
|
+
this.inputX.focus();
|
|
275
|
+
if (event.pointerType === "mouse") {
|
|
276
|
+
this.focused = false;
|
|
277
|
+
}
|
|
278
|
+
if (!applyDefault) {
|
|
279
|
+
this.colorController.restorePreviousColor();
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Returns the value under the cursor
|
|
284
|
+
* @param: PointerEvent on slider
|
|
285
|
+
* @return: Slider value that correlates to the position under the pointer
|
|
286
|
+
*/
|
|
287
|
+
calculateHandlePosition(event) {
|
|
288
|
+
if (!this.boundingClientRect) {
|
|
289
|
+
return [this.x, this.y];
|
|
290
|
+
}
|
|
291
|
+
const rect = this.boundingClientRect;
|
|
292
|
+
const minOffsetX = rect.left;
|
|
293
|
+
const minOffsetY = rect.top;
|
|
294
|
+
const offsetX = event.clientX;
|
|
295
|
+
const offsetY = event.clientY;
|
|
296
|
+
const width = rect.width;
|
|
297
|
+
const height = rect.height;
|
|
298
|
+
const percentX = Math.max(
|
|
299
|
+
0,
|
|
300
|
+
Math.min(1, (offsetX - minOffsetX) / width)
|
|
301
|
+
);
|
|
302
|
+
const percentY = Math.max(
|
|
303
|
+
0,
|
|
304
|
+
Math.min(1, (offsetY - minOffsetY) / height)
|
|
305
|
+
);
|
|
306
|
+
return [this.isLTR ? percentX : 1 - percentX, percentY];
|
|
307
|
+
}
|
|
308
|
+
handleAreaPointerdown(event) {
|
|
309
|
+
if (event.button !== 0) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
event.stopPropagation();
|
|
313
|
+
event.preventDefault();
|
|
314
|
+
this.handle.dispatchEvent(new PointerEvent("pointerdown", event));
|
|
315
|
+
this.handlePointermove(event);
|
|
316
|
+
}
|
|
317
|
+
render() {
|
|
318
|
+
const { width = 0, height = 0 } = this.boundingClientRect || {};
|
|
319
|
+
const isMobile = isAndroid() || isIOS();
|
|
320
|
+
const defaultAriaLabel = "Color Picker";
|
|
321
|
+
const ariaLabel = defaultAriaLabel;
|
|
322
|
+
const ariaRoleDescription = ifDefined(
|
|
323
|
+
isMobile ? void 0 : "2d slider"
|
|
324
|
+
);
|
|
325
|
+
const ariaLabelX = this.labelX;
|
|
326
|
+
const ariaLabelY = this.labelY;
|
|
327
|
+
const ariaValueX = new Intl.NumberFormat(
|
|
328
|
+
this.languageResolver.language,
|
|
329
|
+
{
|
|
330
|
+
style: "percent",
|
|
331
|
+
unitDisplay: "narrow"
|
|
332
|
+
}
|
|
333
|
+
).format(this.x);
|
|
334
|
+
const ariaValueY = new Intl.NumberFormat(
|
|
335
|
+
this.languageResolver.language,
|
|
336
|
+
{
|
|
337
|
+
style: "percent",
|
|
338
|
+
unitDisplay: "narrow"
|
|
339
|
+
}
|
|
340
|
+
).format(this.y);
|
|
341
|
+
const style = {
|
|
342
|
+
background: `linear-gradient(to top, black 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%),linear-gradient(to right, white 0%, hsla(${this.hue}, 100%, 0.01%, 0) 100%), hsl(${this.hue}, 100%, 50%);`
|
|
343
|
+
};
|
|
344
|
+
return html`
|
|
345
|
+
<div
|
|
346
|
+
@pointerdown=${this.handleAreaPointerdown}
|
|
347
|
+
class="gradient"
|
|
348
|
+
style=${styleMap(style)}
|
|
349
|
+
>
|
|
350
|
+
<slot name="gradient"></slot>
|
|
351
|
+
</div>
|
|
352
|
+
|
|
353
|
+
<sp-color-handle
|
|
354
|
+
tabindex=${ifDefined(this.focused ? void 0 : "0")}
|
|
355
|
+
@focus=${this.forwardFocus}
|
|
356
|
+
?focused=${this.focused}
|
|
357
|
+
class="handle"
|
|
358
|
+
color=${this.colorController.getHslString()}
|
|
359
|
+
?disabled=${this.disabled}
|
|
360
|
+
style=${`transform: translate(${(this.isLTR ? this.x : 1 - this.x) * width}px, ${height - this.y * height}px);`}
|
|
361
|
+
${streamingListener({
|
|
362
|
+
start: ["pointerdown", this.handlePointerdown],
|
|
363
|
+
streamInside: ["pointermove", this.handlePointermove],
|
|
364
|
+
end: [
|
|
365
|
+
["pointerup", "pointercancel", "pointerleave"],
|
|
366
|
+
this.handlePointerup
|
|
367
|
+
]
|
|
368
|
+
})}
|
|
369
|
+
></sp-color-handle>
|
|
370
|
+
|
|
371
|
+
<fieldset
|
|
372
|
+
class="fieldset"
|
|
373
|
+
aria-label=${ifDefined(isMobile ? ariaLabel : void 0)}
|
|
374
|
+
>
|
|
375
|
+
<div role="presentation">
|
|
376
|
+
<input
|
|
377
|
+
type="range"
|
|
378
|
+
class="slider"
|
|
379
|
+
name="x"
|
|
380
|
+
aria-label=${isMobile ? ariaLabelX : `${ariaLabelX} ${ariaLabel}`}
|
|
381
|
+
aria-roledescription=${ariaRoleDescription}
|
|
382
|
+
aria-orientation="horizontal"
|
|
383
|
+
aria-valuetext=${isMobile ? ariaValueX : `${ariaValueX}, ${ariaLabelX}${this._valueChanged ? "" : `, ${ariaValueY}, ${ariaLabelY}`}`}
|
|
384
|
+
min="0"
|
|
385
|
+
max="1"
|
|
386
|
+
step=${this.step}
|
|
387
|
+
tabindex="-1"
|
|
388
|
+
.value=${String(this.x)}
|
|
389
|
+
@input=${this.handleInput}
|
|
390
|
+
@change=${this.handleChange}
|
|
391
|
+
/>
|
|
392
|
+
</div>
|
|
393
|
+
<div role="presentation">
|
|
394
|
+
<input
|
|
395
|
+
type="range"
|
|
396
|
+
class="slider"
|
|
397
|
+
name="y"
|
|
398
|
+
aria-label=${isMobile ? ariaLabelY : `${ariaLabelY} ${ariaLabel}`}
|
|
399
|
+
aria-roledescription=${ariaRoleDescription}
|
|
400
|
+
aria-orientation="vertical"
|
|
401
|
+
aria-valuetext=${isMobile ? ariaValueY : `${ariaValueY}, ${ariaLabelY}${this._valueChanged ? "" : `, ${ariaValueX}, ${ariaLabelX}`}`}
|
|
402
|
+
orient="vertical"
|
|
403
|
+
min="0"
|
|
404
|
+
max="1"
|
|
405
|
+
step=${this.step}
|
|
406
|
+
tabindex="-1"
|
|
407
|
+
.value=${String(this.y)}
|
|
408
|
+
@input=${this.handleInput}
|
|
409
|
+
@change=${this.handleChange}
|
|
410
|
+
/>
|
|
411
|
+
</div>
|
|
412
|
+
</fieldset>
|
|
413
|
+
`;
|
|
414
|
+
}
|
|
415
|
+
firstUpdated(changed) {
|
|
416
|
+
super.firstUpdated(changed);
|
|
417
|
+
this.boundingClientRect = this.getBoundingClientRect();
|
|
418
|
+
this.addEventListener("focus", this.handleFocus);
|
|
419
|
+
this.addEventListener("blur", this.handleBlur);
|
|
420
|
+
this.addEventListener("keyup", this.handleKeyup);
|
|
421
|
+
this.addEventListener("keydown", this.handleKeydown);
|
|
422
|
+
}
|
|
423
|
+
updated(changed) {
|
|
424
|
+
super.updated(changed);
|
|
425
|
+
if (this.x !== this.inputX.valueAsNumber) {
|
|
426
|
+
this._x = this.inputX.valueAsNumber;
|
|
427
|
+
}
|
|
428
|
+
if (this.y !== this.inputY.valueAsNumber) {
|
|
429
|
+
this._y = this.inputY.valueAsNumber;
|
|
430
|
+
}
|
|
431
|
+
if (changed.has("focused") && this.focused) {
|
|
432
|
+
const parentX = this.inputX.parentElement;
|
|
433
|
+
const parentY = this.inputY.parentElement;
|
|
434
|
+
if (!parentX.shadowRoot && !parentY.shadowRoot) {
|
|
435
|
+
parentX.attachShadow({ mode: "open" });
|
|
436
|
+
parentY.attachShadow({ mode: "open" });
|
|
437
|
+
const slot = '<div tabindex="-1"><slot></slot></div>';
|
|
438
|
+
parentX.shadowRoot.innerHTML = slot;
|
|
439
|
+
parentY.shadowRoot.innerHTML = slot;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
connectedCallback() {
|
|
444
|
+
var _a;
|
|
445
|
+
super.connectedCallback();
|
|
446
|
+
if (!this.observer && window.ResizeObserver) {
|
|
447
|
+
this.observer = new window.ResizeObserver((entries) => {
|
|
448
|
+
for (const entry of entries) {
|
|
449
|
+
this.boundingClientRect = entry.contentRect;
|
|
450
|
+
}
|
|
451
|
+
this.requestUpdate();
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
(_a = this.observer) == null ? void 0 : _a.observe(this);
|
|
455
|
+
}
|
|
456
|
+
disconnectedCallback() {
|
|
457
|
+
var _a;
|
|
458
|
+
(_a = this.observer) == null ? void 0 : _a.unobserve(this);
|
|
459
|
+
super.disconnectedCallback();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
__decorateClass([
|
|
463
|
+
property({ type: String, reflect: true })
|
|
464
|
+
], ColorArea.prototype, "dir", 2);
|
|
465
|
+
__decorateClass([
|
|
466
|
+
property({ type: Boolean, reflect: true })
|
|
467
|
+
], ColorArea.prototype, "disabled", 2);
|
|
468
|
+
__decorateClass([
|
|
469
|
+
property({ type: Boolean, reflect: true })
|
|
470
|
+
], ColorArea.prototype, "focused", 2);
|
|
471
|
+
__decorateClass([
|
|
472
|
+
property({ type: String, attribute: "label-x" })
|
|
473
|
+
], ColorArea.prototype, "labelX", 2);
|
|
474
|
+
__decorateClass([
|
|
475
|
+
property({ type: String, attribute: "label-y" })
|
|
476
|
+
], ColorArea.prototype, "labelY", 2);
|
|
477
|
+
__decorateClass([
|
|
478
|
+
query(".handle")
|
|
479
|
+
], ColorArea.prototype, "handle", 2);
|
|
480
|
+
__decorateClass([
|
|
481
|
+
property({ type: Number })
|
|
482
|
+
], ColorArea.prototype, "hue", 1);
|
|
483
|
+
__decorateClass([
|
|
484
|
+
property({ type: String })
|
|
485
|
+
], ColorArea.prototype, "value", 1);
|
|
486
|
+
__decorateClass([
|
|
487
|
+
property({ type: String })
|
|
488
|
+
], ColorArea.prototype, "color", 1);
|
|
489
|
+
__decorateClass([
|
|
490
|
+
property({ attribute: false })
|
|
491
|
+
], ColorArea.prototype, "activeAxis", 2);
|
|
492
|
+
__decorateClass([
|
|
493
|
+
property({ type: Number })
|
|
494
|
+
], ColorArea.prototype, "x", 1);
|
|
495
|
+
__decorateClass([
|
|
496
|
+
property({ type: Number })
|
|
497
|
+
], ColorArea.prototype, "y", 1);
|
|
498
|
+
__decorateClass([
|
|
499
|
+
property({ type: Number })
|
|
500
|
+
], ColorArea.prototype, "step", 2);
|
|
501
|
+
__decorateClass([
|
|
502
|
+
query('[name="x"]')
|
|
503
|
+
], ColorArea.prototype, "inputX", 2);
|
|
504
|
+
__decorateClass([
|
|
505
|
+
query('[name="y"]')
|
|
506
|
+
], ColorArea.prototype, "inputY", 2);
|
|
507
|
+
//# sourceMappingURL=ColorArea.dev.js.map
|