@spectrum-web-components/color-area 1.0.0 → 1.0.1-color-testing
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 -8
- package/src/ColorArea.d.ts +44 -6
- package/src/ColorArea.dev.js +66 -32
- package/src/ColorArea.dev.js.map +2 -2
- package/src/ColorArea.js +7 -7
- package/src/ColorArea.js.map +3 -3
- package/stories/color-area.stories.js +12 -2
- package/stories/color-area.stories.js.map +2 -2
- package/test/color-area.test.js +28 -25
- package/test/color-area.test.js.map +2 -2
- package/custom-elements.json +0 -603
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectrum-web-components/color-area",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-color-testing",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -62,12 +62,11 @@
|
|
|
62
62
|
"lit-html"
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@
|
|
66
|
-
"@spectrum-web-components/
|
|
67
|
-
"@spectrum-web-components/
|
|
68
|
-
"@spectrum-web-components/
|
|
69
|
-
"@spectrum-web-components/
|
|
70
|
-
"@spectrum-web-components/shared": "^1.0.0"
|
|
65
|
+
"@spectrum-web-components/base": "^1.0.1-color-testing",
|
|
66
|
+
"@spectrum-web-components/color-handle": "^1.0.1-color-testing",
|
|
67
|
+
"@spectrum-web-components/opacity-checkerboard": "^1.0.1-color-testing",
|
|
68
|
+
"@spectrum-web-components/reactive-controllers": "^1.0.1-color-testing",
|
|
69
|
+
"@spectrum-web-components/shared": "^1.0.1-color-testing"
|
|
71
70
|
},
|
|
72
71
|
"devDependencies": {
|
|
73
72
|
"@spectrum-css/colorarea": "^6.0.0-s2-foundations.15"
|
|
@@ -78,5 +77,5 @@
|
|
|
78
77
|
"./sp-*.js",
|
|
79
78
|
"./**/*.dev.js"
|
|
80
79
|
],
|
|
81
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "17e14b4a9fa2c8b15df158ea7d77ce09bf50de82"
|
|
82
81
|
}
|
package/src/ColorArea.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
|
|
2
2
|
import '@spectrum-web-components/color-handle/sp-color-handle.js';
|
|
3
|
-
import {
|
|
3
|
+
import { ColorTypes } from '@spectrum-web-components/reactive-controllers/src/ColorController.js';
|
|
4
4
|
/**
|
|
5
5
|
* @element sp-color-area
|
|
6
6
|
* @slot gradient - a custom gradient visually outlining the available color values
|
|
@@ -16,19 +16,45 @@ export declare class ColorArea extends SpectrumElement {
|
|
|
16
16
|
labelY: string;
|
|
17
17
|
private handle;
|
|
18
18
|
private languageResolver;
|
|
19
|
+
/**
|
|
20
|
+
* A controller for managing color interactions within the ColorArea component.
|
|
21
|
+
*
|
|
22
|
+
* The `ColorController` is instantiated with the `manageAs` option set to `hsv`
|
|
23
|
+
* because the ColorArea component is designed to manipulate the saturation (`s`)
|
|
24
|
+
* and value (`v`) components of the HSV color model along the x and y axes,
|
|
25
|
+
* respectively. In the HSV color model:
|
|
26
|
+
*
|
|
27
|
+
* - The `hue` (h) represents the color type and is typically controlled by a separate input.
|
|
28
|
+
* - The `saturation` (s) represents the intensity of the color, ranging from 0% (gray) to 100% (full color).
|
|
29
|
+
* - The `value` (v) represents the brightness of the color, ranging from 0% (black) to 100% (full brightness).
|
|
30
|
+
*
|
|
31
|
+
* In the ColorArea component:
|
|
32
|
+
*
|
|
33
|
+
* - The x-axis controls the saturation (`s`), allowing users to adjust the intensity of the color.
|
|
34
|
+
* - The y-axis controls the value (`v`), allowing users to adjust the brightness of the color.
|
|
35
|
+
*
|
|
36
|
+
* By managing the color as `hsv`, the ColorController can efficiently handle the changes in saturation and value
|
|
37
|
+
* as the user interacts with the ColorArea component.
|
|
38
|
+
*
|
|
39
|
+
* @private
|
|
40
|
+
* @type {ColorController}
|
|
41
|
+
* @memberof ColorArea
|
|
42
|
+
*
|
|
43
|
+
* @property {ColorArea} this - The instance of the ColorArea component.
|
|
44
|
+
* @property {Object} options - Configuration options for the ColorController.
|
|
45
|
+
* @property {string} options.manageAs - Specifies the color model to manage, in this case 'hsv'.
|
|
46
|
+
*/
|
|
19
47
|
private colorController;
|
|
20
48
|
get hue(): number;
|
|
21
49
|
set hue(value: number);
|
|
22
|
-
get value():
|
|
23
|
-
get color():
|
|
24
|
-
set color(color:
|
|
50
|
+
get value(): ColorTypes;
|
|
51
|
+
get color(): ColorTypes;
|
|
52
|
+
set color(color: ColorTypes);
|
|
25
53
|
private activeAxis;
|
|
26
54
|
get x(): number;
|
|
27
55
|
set x(x: number);
|
|
28
|
-
private _x;
|
|
29
56
|
get y(): number;
|
|
30
57
|
set y(y: number);
|
|
31
|
-
private _y;
|
|
32
58
|
step: number;
|
|
33
59
|
inputX: HTMLInputElement;
|
|
34
60
|
inputY: HTMLInputElement;
|
|
@@ -58,6 +84,18 @@ export declare class ColorArea extends SpectrumElement {
|
|
|
58
84
|
private handleAreaPointerdown;
|
|
59
85
|
protected render(): TemplateResult;
|
|
60
86
|
protected firstUpdated(changed: PropertyValues): void;
|
|
87
|
+
/**
|
|
88
|
+
* Overrides the `updated` method to handle changes in property values.
|
|
89
|
+
*
|
|
90
|
+
* @param changed - A map of changed properties with their previous values.
|
|
91
|
+
*
|
|
92
|
+
* This method performs the following actions:
|
|
93
|
+
* - Updates the saturation (`s`) of the color if `x` has changed.
|
|
94
|
+
* - Updates the value (`v`) of the color if `y` has changed.
|
|
95
|
+
* - If the `focused` property has changed and is now true, it lazily binds
|
|
96
|
+
* the `input[type="range"]` elements in shadow roots to prevent multiple
|
|
97
|
+
* tab stops within the Color Area for certain browser settings (e.g., Webkit).
|
|
98
|
+
*/
|
|
61
99
|
protected updated(changed: PropertyValues): void;
|
|
62
100
|
private observer?;
|
|
63
101
|
connectedCallback(): void;
|
package/src/ColorArea.dev.js
CHANGED
|
@@ -25,7 +25,7 @@ import { streamingListener } from "@spectrum-web-components/base/src/streaming-l
|
|
|
25
25
|
import "@spectrum-web-components/color-handle/sp-color-handle.js";
|
|
26
26
|
import {
|
|
27
27
|
ColorController
|
|
28
|
-
} from "@spectrum-web-components/reactive-controllers/src/
|
|
28
|
+
} from "@spectrum-web-components/reactive-controllers/src/ColorController.js";
|
|
29
29
|
import { LanguageResolutionController } from "@spectrum-web-components/reactive-controllers/src/LanguageResolution.js";
|
|
30
30
|
import {
|
|
31
31
|
isAndroid,
|
|
@@ -40,21 +40,36 @@ export class ColorArea extends SpectrumElement {
|
|
|
40
40
|
this.labelX = "saturation";
|
|
41
41
|
this.labelY = "luminosity";
|
|
42
42
|
this.languageResolver = new LanguageResolutionController(this);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
/**
|
|
44
|
+
* A controller for managing color interactions within the ColorArea component.
|
|
45
|
+
*
|
|
46
|
+
* The `ColorController` is instantiated with the `manageAs` option set to `hsv`
|
|
47
|
+
* because the ColorArea component is designed to manipulate the saturation (`s`)
|
|
48
|
+
* and value (`v`) components of the HSV color model along the x and y axes,
|
|
49
|
+
* respectively. In the HSV color model:
|
|
50
|
+
*
|
|
51
|
+
* - The `hue` (h) represents the color type and is typically controlled by a separate input.
|
|
52
|
+
* - The `saturation` (s) represents the intensity of the color, ranging from 0% (gray) to 100% (full color).
|
|
53
|
+
* - The `value` (v) represents the brightness of the color, ranging from 0% (black) to 100% (full brightness).
|
|
54
|
+
*
|
|
55
|
+
* In the ColorArea component:
|
|
56
|
+
*
|
|
57
|
+
* - The x-axis controls the saturation (`s`), allowing users to adjust the intensity of the color.
|
|
58
|
+
* - The y-axis controls the value (`v`), allowing users to adjust the brightness of the color.
|
|
59
|
+
*
|
|
60
|
+
* By managing the color as `hsv`, the ColorController can efficiently handle the changes in saturation and value
|
|
61
|
+
* as the user interacts with the ColorArea component.
|
|
62
|
+
*
|
|
63
|
+
* @private
|
|
64
|
+
* @type {ColorController}
|
|
65
|
+
* @memberof ColorArea
|
|
66
|
+
*
|
|
67
|
+
* @property {ColorArea} this - The instance of the ColorArea component.
|
|
68
|
+
* @property {Object} options - Configuration options for the ColorController.
|
|
69
|
+
* @property {string} options.manageAs - Specifies the color model to manage, in this case 'hsv'.
|
|
70
|
+
*/
|
|
71
|
+
this.colorController = new ColorController(this, { manageAs: "hsv" });
|
|
55
72
|
this.activeAxis = "x";
|
|
56
|
-
this._x = 1;
|
|
57
|
-
this._y = 1;
|
|
58
73
|
this.step = 0.01;
|
|
59
74
|
this.altered = 0;
|
|
60
75
|
this.activeKeys = /* @__PURE__ */ new Set();
|
|
@@ -71,45 +86,49 @@ export class ColorArea extends SpectrumElement {
|
|
|
71
86
|
this.colorController.hue = value;
|
|
72
87
|
}
|
|
73
88
|
get value() {
|
|
74
|
-
return this.colorController.
|
|
89
|
+
return this.colorController.colorValue;
|
|
75
90
|
}
|
|
76
91
|
get color() {
|
|
77
|
-
return this.colorController.
|
|
92
|
+
return this.colorController.colorValue;
|
|
78
93
|
}
|
|
79
94
|
set color(color) {
|
|
80
95
|
this.colorController.color = color;
|
|
81
96
|
}
|
|
82
97
|
get x() {
|
|
83
|
-
return this.
|
|
98
|
+
return this.colorController.color.hsv.s / 100;
|
|
84
99
|
}
|
|
85
100
|
set x(x) {
|
|
86
101
|
if (x === this.x) {
|
|
87
102
|
return;
|
|
88
103
|
}
|
|
89
104
|
const oldValue = this.x;
|
|
90
|
-
this._x = x;
|
|
91
105
|
if (this.inputX) {
|
|
92
106
|
this.inputX.value = x.toString();
|
|
93
|
-
this.
|
|
107
|
+
this.colorController.color.set(
|
|
108
|
+
"s",
|
|
109
|
+
this.inputX.valueAsNumber * 100
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
this.colorController.color.set("s", x * 100);
|
|
94
113
|
}
|
|
95
114
|
this.requestUpdate("x", oldValue);
|
|
96
|
-
this.colorController.applyColorFromState();
|
|
97
115
|
}
|
|
98
116
|
get y() {
|
|
99
|
-
return this.
|
|
117
|
+
return this.colorController.color.hsv.v / 100;
|
|
100
118
|
}
|
|
101
119
|
set y(y) {
|
|
102
120
|
if (y === this.y) {
|
|
103
121
|
return;
|
|
104
122
|
}
|
|
105
123
|
const oldValue = this.y;
|
|
106
|
-
this._y = y;
|
|
107
124
|
if (this.inputY) {
|
|
108
125
|
this.inputY.value = y.toString();
|
|
109
|
-
this.
|
|
126
|
+
this.colorController.color.set(
|
|
127
|
+
"v",
|
|
128
|
+
this.inputY.valueAsNumber * 100
|
|
129
|
+
);
|
|
110
130
|
}
|
|
111
131
|
this.requestUpdate("y", oldValue);
|
|
112
|
-
this.colorController.applyColorFromState();
|
|
113
132
|
}
|
|
114
133
|
focus(focusOptions = {}) {
|
|
115
134
|
super.focus(focusOptions);
|
|
@@ -192,7 +211,6 @@ export class ColorArea extends SpectrumElement {
|
|
|
192
211
|
this.x = Math.min(1, Math.max(this.x + deltaX, 0));
|
|
193
212
|
this.y = Math.min(1, Math.max(this.y + deltaY, 0));
|
|
194
213
|
this.colorController.savePreviousColor();
|
|
195
|
-
this.colorController.applyColorFromState();
|
|
196
214
|
if (deltaX != 0 || deltaY != 0) {
|
|
197
215
|
this._valueChanged = true;
|
|
198
216
|
this.dispatchEvent(
|
|
@@ -221,7 +239,6 @@ export class ColorArea extends SpectrumElement {
|
|
|
221
239
|
handleInput(event) {
|
|
222
240
|
const { valueAsNumber, name } = event.target;
|
|
223
241
|
this[name] = valueAsNumber;
|
|
224
|
-
this.colorController.applyColorFromState();
|
|
225
242
|
}
|
|
226
243
|
handleChange(event) {
|
|
227
244
|
this.handleInput(event);
|
|
@@ -250,8 +267,7 @@ export class ColorArea extends SpectrumElement {
|
|
|
250
267
|
const [x, y] = this.calculateHandlePosition(event);
|
|
251
268
|
this._valueChanged = false;
|
|
252
269
|
this.x = x;
|
|
253
|
-
this.y =
|
|
254
|
-
this.colorController.applyColorFromState();
|
|
270
|
+
this.y = y;
|
|
255
271
|
this.dispatchEvent(
|
|
256
272
|
new Event("input", {
|
|
257
273
|
bubbles: true,
|
|
@@ -303,7 +319,7 @@ export class ColorArea extends SpectrumElement {
|
|
|
303
319
|
0,
|
|
304
320
|
Math.min(1, (offsetY - minOffsetY) / height)
|
|
305
321
|
);
|
|
306
|
-
return [this.isLTR ? percentX : 1 - percentX, percentY];
|
|
322
|
+
return [this.isLTR ? percentX : 1 - percentX, 1 - percentY];
|
|
307
323
|
}
|
|
308
324
|
handleAreaPointerdown(event) {
|
|
309
325
|
if (event.button !== 0) {
|
|
@@ -420,13 +436,31 @@ export class ColorArea extends SpectrumElement {
|
|
|
420
436
|
this.addEventListener("keyup", this.handleKeyup);
|
|
421
437
|
this.addEventListener("keydown", this.handleKeydown);
|
|
422
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* Overrides the `updated` method to handle changes in property values.
|
|
441
|
+
*
|
|
442
|
+
* @param changed - A map of changed properties with their previous values.
|
|
443
|
+
*
|
|
444
|
+
* This method performs the following actions:
|
|
445
|
+
* - Updates the saturation (`s`) of the color if `x` has changed.
|
|
446
|
+
* - Updates the value (`v`) of the color if `y` has changed.
|
|
447
|
+
* - If the `focused` property has changed and is now true, it lazily binds
|
|
448
|
+
* the `input[type="range"]` elements in shadow roots to prevent multiple
|
|
449
|
+
* tab stops within the Color Area for certain browser settings (e.g., Webkit).
|
|
450
|
+
*/
|
|
423
451
|
updated(changed) {
|
|
424
452
|
super.updated(changed);
|
|
425
453
|
if (this.x !== this.inputX.valueAsNumber) {
|
|
426
|
-
this.
|
|
454
|
+
this.colorController.color.set(
|
|
455
|
+
"s",
|
|
456
|
+
this.inputX.valueAsNumber * 100
|
|
457
|
+
);
|
|
427
458
|
}
|
|
428
459
|
if (this.y !== this.inputY.valueAsNumber) {
|
|
429
|
-
this.
|
|
460
|
+
this.colorController.color.set(
|
|
461
|
+
"v",
|
|
462
|
+
(1 - this.inputY.valueAsNumber) * 100
|
|
463
|
+
);
|
|
430
464
|
}
|
|
431
465
|
if (changed.has("focused") && this.focused) {
|
|
432
466
|
const parentX = this.inputX.parentElement;
|
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 {\n ifDefined,\n styleMap,\n} 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';\nimport { LanguageResolutionController } from '@spectrum-web-components/reactive-controllers/src/LanguageResolution.js';\nimport {\n isAndroid,\n isIOS,\n} from '@spectrum-web-components/shared/src/platform.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: String, reflect: true })\n public override dir!: 'ltr' | 'rtl';\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, 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 languageResolver = new LanguageResolutionController(this);\n\n private colorController = new ColorController(this, {\n extractColorFromState: () => ({\n h: this.hue,\n s: this.x,\n v: this.y,\n }),\n applyColorToState: ({ s, v }) => {\n this._x = s;\n this._y = v;\n this.requestUpdate();\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 this._x = 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 }\n this.requestUpdate('x', oldValue);\n this.colorController.applyColorFromState();\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 this._y = 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 }\n this.requestUpdate('y', oldValue);\n this.colorController.applyColorFromState();\n }\n\n private _y = 1;\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 private _valueChanged = false;\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 handleFocus(): void {\n this.focused = true;\n this._valueChanged = false;\n }\n\n public handleBlur(): void {\n if (this._pointerDown) {\n return;\n }\n this.altered = 0;\n this.focused = false;\n this._valueChanged = 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 =\n code.search('Arrow') === 0 ||\n code.search('Page') === 0 ||\n code.search('Home') === 0 ||\n code.search('End') === 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;\n break;\n case 'ArrowDown':\n deltaY = step * -1;\n break;\n case 'ArrowLeft':\n deltaX = this.step * (this.isLTR ? -1 : 1);\n break;\n case 'ArrowRight':\n deltaX = this.step * (this.isLTR ? 1 : -1);\n break;\n case 'PageUp':\n deltaY = step * 10;\n break;\n case 'PageDown':\n deltaY = step * -10;\n break;\n case 'Home':\n deltaX = step * (this.isLTR ? -10 : 10);\n break;\n case 'End':\n deltaX = step * (this.isLTR ? 10 : -10);\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._valueChanged = true;\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 public _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._valueChanged = false;\n\n this.x = x;\n this.y = 1 - 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 [this.isLTR ? percentX : 1 - 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 const isMobile = isAndroid() || isIOS();\n const defaultAriaLabel = 'Color Picker';\n const ariaLabel = defaultAriaLabel;\n const ariaRoleDescription = ifDefined(\n isMobile ? undefined : '2d slider'\n );\n\n const ariaLabelX = this.labelX;\n const ariaLabelY = this.labelY;\n const ariaValueX = new Intl.NumberFormat(\n this.languageResolver.language,\n {\n style: 'percent',\n unitDisplay: 'narrow',\n }\n ).format(this.x);\n const ariaValueY = new Intl.NumberFormat(\n this.languageResolver.language,\n {\n style: 'percent',\n unitDisplay: 'narrow',\n }\n ).format(this.y);\n\n const style = {\n 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%);`,\n };\n\n return html`\n <div\n @pointerdown=${this.handleAreaPointerdown}\n class=\"gradient\"\n style=${styleMap(style)}\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(${\n (this.isLTR ? this.x : 1 - this.x) * width\n }px, ${height - this.y * height}px);`}\n ${streamingListener({\n start: ['pointerdown', this.handlePointerdown],\n streamInside: ['pointermove', this.handlePointermove],\n end: [\n ['pointerup', 'pointercancel', 'pointerleave'],\n this.handlePointerup,\n ],\n })}\n ></sp-color-handle>\n\n <fieldset\n class=\"fieldset\"\n aria-label=${ifDefined(isMobile ? ariaLabel : undefined)}\n >\n <div role=\"presentation\">\n <input\n type=\"range\"\n class=\"slider\"\n name=\"x\"\n aria-label=${isMobile\n ? ariaLabelX\n : `${ariaLabelX} ${ariaLabel}`}\n aria-roledescription=${ariaRoleDescription}\n aria-orientation=\"horizontal\"\n aria-valuetext=${isMobile\n ? ariaValueX\n : `${ariaValueX}, ${ariaLabelX}${\n this._valueChanged\n ? ''\n : `, ${ariaValueY}, ${ariaLabelY}`\n }`}\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 role=\"presentation\">\n <input\n type=\"range\"\n class=\"slider\"\n name=\"y\"\n aria-label=${isMobile\n ? ariaLabelY\n : `${ariaLabelY} ${ariaLabel}`}\n aria-roledescription=${ariaRoleDescription}\n aria-orientation=\"vertical\"\n aria-valuetext=${isMobile\n ? ariaValueY\n : `${ariaValueY}, ${ariaLabelY}${\n this._valueChanged\n ? ''\n : `, ${ariaValueX}, ${ariaLabelX}`\n }`}\n orient=\"vertical\"\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 </fieldset>\n `;\n }\n\n protected override firstUpdated(changed: PropertyValues): void {\n super.firstUpdated(changed);\n this.boundingClientRect = this.getBoundingClientRect();\n\n this.addEventListener('focus', this.handleFocus);\n this.addEventListener('blur', this.handleBlur);\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": ";;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,EAEA;AAAA,OAEG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,yBAAyB;AAGlC,OAAO;
|
|
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 {\n ifDefined,\n styleMap,\n} 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';\n\nimport {\n ColorController,\n ColorTypes,\n} from '@spectrum-web-components/reactive-controllers/src/ColorController.js';\nimport { LanguageResolutionController } from '@spectrum-web-components/reactive-controllers/src/LanguageResolution.js';\nimport {\n isAndroid,\n isIOS,\n} from '@spectrum-web-components/shared/src/platform.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: String, reflect: true })\n public override dir!: 'ltr' | 'rtl';\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, 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 languageResolver = new LanguageResolutionController(this);\n\n /**\n * A controller for managing color interactions within the ColorArea component.\n *\n * The `ColorController` is instantiated with the `manageAs` option set to `hsv`\n * because the ColorArea component is designed to manipulate the saturation (`s`)\n * and value (`v`) components of the HSV color model along the x and y axes,\n * respectively. In the HSV color model:\n *\n * - The `hue` (h) represents the color type and is typically controlled by a separate input.\n * - The `saturation` (s) represents the intensity of the color, ranging from 0% (gray) to 100% (full color).\n * - The `value` (v) represents the brightness of the color, ranging from 0% (black) to 100% (full brightness).\n *\n * In the ColorArea component:\n *\n * - The x-axis controls the saturation (`s`), allowing users to adjust the intensity of the color.\n * - The y-axis controls the value (`v`), allowing users to adjust the brightness of the color.\n *\n * By managing the color as `hsv`, the ColorController can efficiently handle the changes in saturation and value\n * as the user interacts with the ColorArea component.\n *\n * @private\n * @type {ColorController}\n * @memberof ColorArea\n *\n * @property {ColorArea} this - The instance of the ColorArea component.\n * @property {Object} options - Configuration options for the ColorController.\n * @property {string} options.manageAs - Specifies the color model to manage, in this case 'hsv'.\n */\n private colorController = new ColorController(this, { manageAs: 'hsv' });\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(): ColorTypes {\n return this.colorController.colorValue;\n }\n\n @property({ type: String })\n public get color(): ColorTypes {\n return this.colorController.colorValue;\n }\n\n public set color(color: ColorTypes) {\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.colorController.color.hsv.s / 100;\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.colorController.color.set(\n 's',\n this.inputX.valueAsNumber * 100\n );\n } else {\n this.colorController.color.set('s', x * 100);\n }\n this.requestUpdate('x', oldValue);\n }\n\n @property({ type: Number })\n public get y(): number {\n return this.colorController.color.hsv.v / 100;\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.colorController.color.set(\n 'v',\n this.inputY.valueAsNumber * 100\n );\n }\n this.requestUpdate('y', oldValue);\n }\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 private _valueChanged = false;\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 handleFocus(): void {\n this.focused = true;\n this._valueChanged = false;\n }\n\n public handleBlur(): void {\n if (this._pointerDown) {\n return;\n }\n this.altered = 0;\n this.focused = false;\n this._valueChanged = false;\n }\n\n private handleKeydown(event: KeyboardEvent): void {\n const { code } = event;\n this.focused = true;\n\n this.altered = [event.shiftKey, event.ctrlKey, event.altKey].filter(\n (key) => !!key\n ).length;\n const isArrowKey =\n code.search('Arrow') === 0 ||\n code.search('Page') === 0 ||\n code.search('Home') === 0 ||\n code.search('End') === 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;\n break;\n case 'ArrowDown':\n deltaY = step * -1;\n break;\n case 'ArrowLeft':\n deltaX = this.step * (this.isLTR ? -1 : 1);\n break;\n case 'ArrowRight':\n deltaX = this.step * (this.isLTR ? 1 : -1);\n break;\n case 'PageUp':\n deltaY = step * 10;\n break;\n case 'PageDown':\n deltaY = step * -10;\n break;\n case 'Home':\n deltaX = step * (this.isLTR ? -10 : 10);\n break;\n case 'End':\n deltaX = step * (this.isLTR ? 10 : -10);\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\n if (deltaX != 0 || deltaY != 0) {\n this._valueChanged = true;\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 }\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 public _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._valueChanged = false;\n\n this.x = x;\n this.y = y;\n\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 [this.isLTR ? percentX : 1 - percentX, 1 - 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 const isMobile = isAndroid() || isIOS();\n const defaultAriaLabel = 'Color Picker';\n const ariaLabel = defaultAriaLabel;\n const ariaRoleDescription = ifDefined(\n isMobile ? undefined : '2d slider'\n );\n\n const ariaLabelX = this.labelX;\n const ariaLabelY = this.labelY;\n const ariaValueX = new Intl.NumberFormat(\n this.languageResolver.language,\n {\n style: 'percent',\n unitDisplay: 'narrow',\n }\n ).format(this.x);\n const ariaValueY = new Intl.NumberFormat(\n this.languageResolver.language,\n {\n style: 'percent',\n unitDisplay: 'narrow',\n }\n ).format(this.y);\n\n const style = {\n 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%);`,\n };\n\n return html`\n <div\n @pointerdown=${this.handleAreaPointerdown}\n class=\"gradient\"\n style=${styleMap(style)}\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(${\n (this.isLTR ? this.x : 1 - this.x) * width\n }px, ${height - this.y * height}px);`}\n ${streamingListener({\n start: ['pointerdown', this.handlePointerdown],\n streamInside: ['pointermove', this.handlePointermove],\n end: [\n ['pointerup', 'pointercancel', 'pointerleave'],\n this.handlePointerup,\n ],\n })}\n ></sp-color-handle>\n\n <fieldset\n class=\"fieldset\"\n aria-label=${ifDefined(isMobile ? ariaLabel : undefined)}\n >\n <div role=\"presentation\">\n <input\n type=\"range\"\n class=\"slider\"\n name=\"x\"\n aria-label=${isMobile\n ? ariaLabelX\n : `${ariaLabelX} ${ariaLabel}`}\n aria-roledescription=${ariaRoleDescription}\n aria-orientation=\"horizontal\"\n aria-valuetext=${isMobile\n ? ariaValueX\n : `${ariaValueX}, ${ariaLabelX}${\n this._valueChanged\n ? ''\n : `, ${ariaValueY}, ${ariaLabelY}`\n }`}\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 role=\"presentation\">\n <input\n type=\"range\"\n class=\"slider\"\n name=\"y\"\n aria-label=${isMobile\n ? ariaLabelY\n : `${ariaLabelY} ${ariaLabel}`}\n aria-roledescription=${ariaRoleDescription}\n aria-orientation=\"vertical\"\n aria-valuetext=${isMobile\n ? ariaValueY\n : `${ariaValueY}, ${ariaLabelY}${\n this._valueChanged\n ? ''\n : `, ${ariaValueX}, ${ariaLabelX}`\n }`}\n orient=\"vertical\"\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 </fieldset>\n `;\n }\n\n protected override firstUpdated(changed: PropertyValues): void {\n super.firstUpdated(changed);\n this.boundingClientRect = this.getBoundingClientRect();\n\n this.addEventListener('focus', this.handleFocus);\n this.addEventListener('blur', this.handleBlur);\n this.addEventListener('keyup', this.handleKeyup);\n this.addEventListener('keydown', this.handleKeydown);\n }\n\n /**\n * Overrides the `updated` method to handle changes in property values.\n *\n * @param changed - A map of changed properties with their previous values.\n *\n * This method performs the following actions:\n * - Updates the saturation (`s`) of the color if `x` has changed.\n * - Updates the value (`v`) of the color if `y` has changed.\n * - If the `focused` property has changed and is now true, it lazily binds\n * the `input[type=\"range\"]` elements in shadow roots to prevent multiple\n * tab stops within the Color Area for certain browser settings (e.g., Webkit).\n */\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (this.x !== this.inputX.valueAsNumber) {\n this.colorController.color.set(\n 's',\n this.inputX.valueAsNumber * 100\n );\n }\n if (this.y !== this.inputY.valueAsNumber) {\n this.colorController.color.set(\n 'v',\n (1 - this.inputY.valueAsNumber) * 100\n );\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": ";;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,EAEA;AAAA,OAEG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AACP,SAAS,yBAAyB;AAGlC,OAAO;AAEP;AAAA,EACI;AAAA,OAEG;AACP,SAAS,oCAAoC;AAC7C;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP,OAAO,YAAY;AAQZ,aAAM,kBAAkB,gBAAgB;AAAA,EAAxC;AAAA;AASH,SAAO,WAAW;AAGlB,SAAO,UAAU;AAGjB,SAAO,SAAS;AAGhB,SAAO,SAAS;AAKhB,SAAQ,mBAAmB,IAAI,6BAA6B,IAAI;AA8BhE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAQ,kBAAkB,IAAI,gBAAgB,MAAM,EAAE,UAAU,MAAM,CAAC;AA0BvE,SAAQ,aAAa;AA+CrB,SAAO,OAAO;AAQd,SAAQ,UAAU;AAElB,SA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AE,MAAM,OAAO,CAAC;AAAA,GAhEjB,UAiEE;AAKA;AAAA,EADV,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GArEjB,UAsEE;AASH;AAAA,EADP,SAAS,EAAE,WAAW,MAAM,CAAC;AAAA,GA9ErB,UA+ED;AAGG;AAAA,EADV,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAjFjB,UAkFE;AAuBA;AAAA,EADV,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAxGjB,UAyGE;AAqBJ;AAAA,EADN,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GA7HjB,UA8HF;AAGA;AAAA,EADN,MAAM,YAAY;AAAA,GAhIV,UAiIF;AAGA;AAAA,EADN,MAAM,YAAY;AAAA,GAnIV,UAoIF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/src/ColorArea.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var s=(
|
|
1
|
+
"use strict";var m=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var s=(p,u,e,t)=>{for(var i=t>1?void 0:t?y(u,e):u,r=p.length-1,n;r>=0;r--)(n=p[r])&&(i=(t?n(u,e,i):n(i))||i);return t&&i&&m(u,e,i),i};import{html as g,SpectrumElement as w}from"@spectrum-web-components/base";import{ifDefined as v,styleMap as C}from"@spectrum-web-components/base/src/directives.js";import{property as o,query as b}from"@spectrum-web-components/base/src/decorators.js";import{streamingListener as $}from"@spectrum-web-components/base/src/streaming-listener.js";import"@spectrum-web-components/color-handle/sp-color-handle.js";import{ColorController as R}from"@spectrum-web-components/reactive-controllers/src/ColorController.js";import{LanguageResolutionController as x}from"@spectrum-web-components/reactive-controllers/src/LanguageResolution.js";import{isAndroid as E,isIOS as P}from"@spectrum-web-components/shared/src/platform.js";import L from"./color-area.css.js";export class ColorArea extends w{constructor(){super(...arguments);this.disabled=!1;this.focused=!1;this.labelX="saturation";this.labelY="luminosity";this.languageResolver=new x(this);this.colorController=new R(this,{manageAs:"hsv"});this.activeAxis="x";this.step=.01;this.altered=0;this.activeKeys=new Set;this._valueChanged=!1;this._pointerDown=!1}static get styles(){return[L]}get hue(){return this.colorController.hue}set hue(e){this.colorController.hue=e}get value(){return this.colorController.colorValue}get color(){return this.colorController.colorValue}set color(e){this.colorController.color=e}get x(){return this.colorController.color.hsv.s/100}set x(e){if(e===this.x)return;const t=this.x;this.inputX?(this.inputX.value=e.toString(),this.colorController.color.set("s",this.inputX.valueAsNumber*100)):this.colorController.color.set("s",e*100),this.requestUpdate("x",t)}get y(){return this.colorController.color.hsv.v/100}set y(e){if(e===this.y)return;const t=this.y;this.inputY&&(this.inputY.value=e.toString(),this.colorController.color.set("v",this.inputY.valueAsNumber*100)),this.requestUpdate("y",t)}focus(e={}){super.focus(e),this.forwardFocus()}forwardFocus(){this.focused=this.hasVisibleFocusInTree(),this.activeAxis==="x"?this.inputX.focus():this.inputY.focus()}handleFocus(){this.focused=!0,this._valueChanged=!1}handleBlur(){this._pointerDown||(this.altered=0,this.focused=!1,this._valueChanged=!1)}handleKeydown(e){const{code:t}=e;this.focused=!0,this.altered=[e.shiftKey,e.ctrlKey,e.altKey].filter(r=>!!r).length,(t.search("Arrow")===0||t.search("Page")===0||t.search("Home")===0||t.search("End")===0)&&(e.preventDefault(),this.activeKeys.add(t),this.handleKeypress())}handleKeypress(){let e=0,t=0;const i=Math.max(this.step,this.altered*5*this.step);this.activeKeys.forEach(r=>{switch(r){case"ArrowUp":t=i;break;case"ArrowDown":t=i*-1;break;case"ArrowLeft":e=this.step*(this.isLTR?-1:1);break;case"ArrowRight":e=this.step*(this.isLTR?1:-1);break;case"PageUp":t=i*10;break;case"PageDown":t=i*-10;break;case"Home":e=i*(this.isLTR?-10:10);break;case"End":e=i*(this.isLTR?10:-10);break;default:break}}),e!=0?(this.activeAxis="x",this.inputX.focus()):t!=0&&(this.activeAxis="y",this.inputY.focus()),this.x=Math.min(1,Math.max(this.x+e,0)),this.y=Math.min(1,Math.max(this.y+t,0)),this.colorController.savePreviousColor(),(e!=0||t!=0)&&(this._valueChanged=!0,this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0})),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0,cancelable:!0}))||this.colorController.restorePreviousColor())}handleKeyup(e){e.preventDefault();const{code:t}=e;this.activeKeys.delete(t)}handleInput(e){const{valueAsNumber:t,name:i}=e.target;this[i]=t}handleChange(e){this.handleInput(e),this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0,cancelable:!0}))}handlePointerdown(e){if(e.button!==0){e.preventDefault();return}this._pointerDown=!0,this.colorController.savePreviousColor(),this.boundingClientRect=this.getBoundingClientRect(),e.target.setPointerCapture(e.pointerId),e.pointerType==="mouse"&&(this.focused=!0)}handlePointermove(e){const[t,i]=this.calculateHandlePosition(e);this._valueChanged=!1,this.x=t,this.y=i,this.dispatchEvent(new Event("input",{bubbles:!0,composed:!0,cancelable:!0}))}handlePointerup(e){e.preventDefault(),this._pointerDown=!1,e.target.releasePointerCapture(e.pointerId);const t=this.dispatchEvent(new Event("change",{bubbles:!0,composed:!0,cancelable:!0}));this.inputX.focus(),e.pointerType==="mouse"&&(this.focused=!1),t||this.colorController.restorePreviousColor()}calculateHandlePosition(e){if(!this.boundingClientRect)return[this.x,this.y];const t=this.boundingClientRect,i=t.left,r=t.top,n=e.clientX,d=e.clientY,a=t.width,l=t.height,h=Math.max(0,Math.min(1,(n-i)/a)),c=Math.max(0,Math.min(1,(d-r)/l));return[this.isLTR?h:1-h,1-c]}handleAreaPointerdown(e){e.button===0&&(e.stopPropagation(),e.preventDefault(),this.handle.dispatchEvent(new PointerEvent("pointerdown",e)),this.handlePointermove(e))}render(){const{width:e=0,height:t=0}=this.boundingClientRect||{},i=E()||P(),n="Color Picker",d=v(i?void 0:"2d slider"),a=this.labelX,l=this.labelY,h=new Intl.NumberFormat(this.languageResolver.language,{style:"percent",unitDisplay:"narrow"}).format(this.x),c=new Intl.NumberFormat(this.languageResolver.language,{style:"percent",unitDisplay:"narrow"}).format(this.y),f={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%);`};return g`
|
|
2
2
|
<div
|
|
3
3
|
@pointerdown=${this.handleAreaPointerdown}
|
|
4
4
|
class="gradient"
|
|
@@ -8,19 +8,19 @@
|
|
|
8
8
|
</div>
|
|
9
9
|
|
|
10
10
|
<sp-color-handle
|
|
11
|
-
tabindex=${
|
|
11
|
+
tabindex=${v(this.focused?void 0:"0")}
|
|
12
12
|
@focus=${this.forwardFocus}
|
|
13
13
|
?focused=${this.focused}
|
|
14
14
|
class="handle"
|
|
15
15
|
color=${this.colorController.getHslString()}
|
|
16
16
|
?disabled=${this.disabled}
|
|
17
17
|
style=${`transform: translate(${(this.isLTR?this.x:1-this.x)*e}px, ${t-this.y*t}px);`}
|
|
18
|
-
${
|
|
18
|
+
${$({start:["pointerdown",this.handlePointerdown],streamInside:["pointermove",this.handlePointermove],end:[["pointerup","pointercancel","pointerleave"],this.handlePointerup]})}
|
|
19
19
|
></sp-color-handle>
|
|
20
20
|
|
|
21
21
|
<fieldset
|
|
22
22
|
class="fieldset"
|
|
23
|
-
aria-label=${
|
|
23
|
+
aria-label=${v(i?n:void 0)}
|
|
24
24
|
>
|
|
25
25
|
<div role="presentation">
|
|
26
26
|
<input
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
aria-label=${i?a:`${a} ${n}`}
|
|
31
31
|
aria-roledescription=${d}
|
|
32
32
|
aria-orientation="horizontal"
|
|
33
|
-
aria-valuetext=${i?h:`${h}, ${a}${this._valueChanged?"":`, ${
|
|
33
|
+
aria-valuetext=${i?h:`${h}, ${a}${this._valueChanged?"":`, ${c}, ${l}`}`}
|
|
34
34
|
min="0"
|
|
35
35
|
max="1"
|
|
36
36
|
step=${this.step}
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
aria-label=${i?l:`${l} ${n}`}
|
|
49
49
|
aria-roledescription=${d}
|
|
50
50
|
aria-orientation="vertical"
|
|
51
|
-
aria-valuetext=${i?
|
|
51
|
+
aria-valuetext=${i?c:`${c}, ${l}${this._valueChanged?"":`, ${h}, ${a}`}`}
|
|
52
52
|
orient="vertical"
|
|
53
53
|
min="0"
|
|
54
54
|
max="1"
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
/>
|
|
61
61
|
</div>
|
|
62
62
|
</fieldset>
|
|
63
|
-
`}firstUpdated(e){super.firstUpdated(e),this.boundingClientRect=this.getBoundingClientRect(),this.addEventListener("focus",this.handleFocus),this.addEventListener("blur",this.handleBlur),this.addEventListener("keyup",this.handleKeyup),this.addEventListener("keydown",this.handleKeydown)}updated(e){if(super.updated(e),this.x!==this.inputX.valueAsNumber&&
|
|
63
|
+
`}firstUpdated(e){super.firstUpdated(e),this.boundingClientRect=this.getBoundingClientRect(),this.addEventListener("focus",this.handleFocus),this.addEventListener("blur",this.handleBlur),this.addEventListener("keyup",this.handleKeyup),this.addEventListener("keydown",this.handleKeydown)}updated(e){if(super.updated(e),this.x!==this.inputX.valueAsNumber&&this.colorController.color.set("s",this.inputX.valueAsNumber*100),this.y!==this.inputY.valueAsNumber&&this.colorController.color.set("v",(1-this.inputY.valueAsNumber)*100),e.has("focused")&&this.focused){const t=this.inputX.parentElement,i=this.inputY.parentElement;if(!t.shadowRoot&&!i.shadowRoot){t.attachShadow({mode:"open"}),i.attachShadow({mode:"open"});const r='<div tabindex="-1"><slot></slot></div>';t.shadowRoot.innerHTML=r,i.shadowRoot.innerHTML=r}}}connectedCallback(){var e;super.connectedCallback(),!this.observer&&window.ResizeObserver&&(this.observer=new window.ResizeObserver(t=>{for(const i of t)this.boundingClientRect=i.contentRect;this.requestUpdate()})),(e=this.observer)==null||e.observe(this)}disconnectedCallback(){var e;(e=this.observer)==null||e.unobserve(this),super.disconnectedCallback()}}s([o({type:String,reflect:!0})],ColorArea.prototype,"dir",2),s([o({type:Boolean,reflect:!0})],ColorArea.prototype,"disabled",2),s([o({type:Boolean,reflect:!0})],ColorArea.prototype,"focused",2),s([o({type:String,attribute:"label-x"})],ColorArea.prototype,"labelX",2),s([o({type:String,attribute:"label-y"})],ColorArea.prototype,"labelY",2),s([b(".handle")],ColorArea.prototype,"handle",2),s([o({type:Number})],ColorArea.prototype,"hue",1),s([o({type:String})],ColorArea.prototype,"value",1),s([o({type:String})],ColorArea.prototype,"color",1),s([o({attribute:!1})],ColorArea.prototype,"activeAxis",2),s([o({type:Number})],ColorArea.prototype,"x",1),s([o({type:Number})],ColorArea.prototype,"y",1),s([o({type:Number})],ColorArea.prototype,"step",2),s([b('[name="x"]')],ColorArea.prototype,"inputX",2),s([b('[name="y"]')],ColorArea.prototype,"inputY",2);
|
|
64
64
|
//# sourceMappingURL=ColorArea.js.map
|