@spectrum-web-components/color-area 0.4.9 → 0.4.11-devmode.7
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 +26 -9
- 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 +477 -490
- package/test/color-area.test.js.map +7 -1
package/test/color-area.test.js
CHANGED
|
@@ -1,554 +1,541 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import { spy } from 'sinon';
|
|
17
|
-
describe('ColorArea', () => {
|
|
18
|
-
it('loads default color-area accessibly', async () => {
|
|
19
|
-
const el = await fixture(html `
|
|
1
|
+
import {
|
|
2
|
+
elementUpdated,
|
|
3
|
+
expect,
|
|
4
|
+
fixture,
|
|
5
|
+
html,
|
|
6
|
+
nextFrame,
|
|
7
|
+
oneEvent
|
|
8
|
+
} from "@open-wc/testing";
|
|
9
|
+
import { TinyColor } from "@ctrl/tinycolor";
|
|
10
|
+
import "@spectrum-web-components/color-area/sp-color-area.js";
|
|
11
|
+
import { sendKeys } from "@web/test-runner-commands";
|
|
12
|
+
import { spy } from "sinon";
|
|
13
|
+
describe("ColorArea", () => {
|
|
14
|
+
it("loads default color-area accessibly", async () => {
|
|
15
|
+
const el = await fixture(html`
|
|
20
16
|
<sp-color-area></sp-color-area>
|
|
21
17
|
`);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
await elementUpdated(el);
|
|
19
|
+
await expect(el).to.be.accessible();
|
|
20
|
+
});
|
|
21
|
+
it("manages a single tab stop", async () => {
|
|
22
|
+
const test = await fixture(html`
|
|
27
23
|
<div>
|
|
28
24
|
<input type="text" />
|
|
29
25
|
<sp-color-area color="hsl(100, 50%, 50%)"></sp-color-area>
|
|
30
26
|
<input type="text" />
|
|
31
27
|
</div>
|
|
32
28
|
`);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
expect(el.value).to.not.equal(value);
|
|
65
|
-
await sendKeys({
|
|
66
|
-
press: 'Shift+Tab',
|
|
67
|
-
});
|
|
68
|
-
expect(document.activeElement, 'before input again').to.equal(input1);
|
|
29
|
+
const el = test.querySelector("sp-color-area");
|
|
30
|
+
const input1 = test.querySelector("input:nth-of-type(1)");
|
|
31
|
+
const input2 = test.querySelector("input:nth-of-type(2)");
|
|
32
|
+
await elementUpdated(el);
|
|
33
|
+
input1.focus();
|
|
34
|
+
expect(document.activeElement, "before input").to.equal(input1);
|
|
35
|
+
await sendKeys({
|
|
36
|
+
press: "Tab"
|
|
37
|
+
});
|
|
38
|
+
await elementUpdated(el);
|
|
39
|
+
expect(document.activeElement, "element").to.equal(el);
|
|
40
|
+
let value = el.value;
|
|
41
|
+
await sendKeys({
|
|
42
|
+
press: "ArrowRight"
|
|
43
|
+
});
|
|
44
|
+
await elementUpdated(el);
|
|
45
|
+
expect(el.value).to.not.equal(value);
|
|
46
|
+
await sendKeys({
|
|
47
|
+
press: "Tab"
|
|
48
|
+
});
|
|
49
|
+
await elementUpdated(el);
|
|
50
|
+
expect(document.activeElement, "after input").to.equal(input2);
|
|
51
|
+
await sendKeys({
|
|
52
|
+
press: "Shift+Tab"
|
|
53
|
+
});
|
|
54
|
+
await elementUpdated(el);
|
|
55
|
+
expect(document.activeElement, "element again").to.equal(el);
|
|
56
|
+
value = el.value;
|
|
57
|
+
await sendKeys({
|
|
58
|
+
press: "ArrowDown"
|
|
69
59
|
});
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
expect(el.value).to.not.equal(value);
|
|
61
|
+
await sendKeys({
|
|
62
|
+
press: "Shift+Tab"
|
|
63
|
+
});
|
|
64
|
+
expect(document.activeElement, "before input again").to.equal(input1);
|
|
65
|
+
});
|
|
66
|
+
it("provides separate aria-labels for X and Y inputs", async () => {
|
|
67
|
+
const el = await fixture(html`
|
|
72
68
|
<sp-color-area color="hsl(100, 50%, 50%)"></sp-color-area>
|
|
73
69
|
`);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
const inputX = el.shadowRoot.querySelector('input[name="x"]');
|
|
71
|
+
const inputY = el.shadowRoot.querySelector('input[name="y"]');
|
|
72
|
+
expect(inputX == null ? void 0 : inputX.getAttribute("aria-label")).to.equal("saturation");
|
|
73
|
+
expect(inputY == null ? void 0 : inputY.getAttribute("aria-label")).to.equal("luminosity");
|
|
74
|
+
});
|
|
75
|
+
it('overrides both X and Y labels with a provided "label" attribute', async () => {
|
|
76
|
+
const el = await fixture(html`
|
|
81
77
|
<sp-color-area
|
|
82
78
|
color="hsl(100, 50%, 50%)"
|
|
83
79
|
label="something custom"
|
|
84
80
|
></sp-color-area>
|
|
85
81
|
`);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
const inputX = el.shadowRoot.querySelector('input[name="x"]');
|
|
83
|
+
const inputY = el.shadowRoot.querySelector('input[name="y"]');
|
|
84
|
+
expect(inputX == null ? void 0 : inputX.getAttribute("aria-label")).to.equal("something custom");
|
|
85
|
+
expect(inputY == null ? void 0 : inputY.getAttribute("aria-label")).to.equal("something custom");
|
|
86
|
+
});
|
|
87
|
+
it('accepts "color" values as hsl', async () => {
|
|
88
|
+
const el = await fixture(html`
|
|
93
89
|
<sp-color-area color="hsl(100, 50%, 50%)"></sp-color-area>
|
|
94
90
|
`);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
91
|
+
await elementUpdated(el);
|
|
92
|
+
expect(el.hue, "hue").to.equal(100);
|
|
93
|
+
expect(el.x, "x").to.equal(0.67);
|
|
94
|
+
expect(el.y, "y").to.equal(0.25);
|
|
95
|
+
});
|
|
96
|
+
it('accepts "color" values as hsla', async () => {
|
|
97
|
+
const el = await fixture(html`
|
|
102
98
|
<sp-color-area color="hsla(100, 50%, 50%, 1)"></sp-color-area>
|
|
103
99
|
`);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
100
|
+
await elementUpdated(el);
|
|
101
|
+
expect(el.hue, "hugh").to.equal(100);
|
|
102
|
+
expect(el.x, "ex").to.equal(0.67);
|
|
103
|
+
expect(el.y, "why").to.equal(0.25);
|
|
104
|
+
el.color = "hsla(120, 100%, 0, 1)";
|
|
105
|
+
await elementUpdated(el);
|
|
106
|
+
expect(el.hue, "hue 2").to.equal(120);
|
|
107
|
+
expect(el.x, "x 2").to.equal(0);
|
|
108
|
+
expect(el.y, "y 2").to.equal(1);
|
|
109
|
+
});
|
|
110
|
+
it('accepts "color" values as rgb', async () => {
|
|
111
|
+
const el = await fixture(html`
|
|
116
112
|
<sp-color-area color="rgb(0,255,0)"></sp-color-area>
|
|
117
113
|
`);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
114
|
+
await elementUpdated(el);
|
|
115
|
+
expect(el.hue).to.equal(120);
|
|
116
|
+
expect(el.x).to.equal(1);
|
|
117
|
+
expect(el.y).to.equal(0);
|
|
118
|
+
});
|
|
119
|
+
it('accepts "color" values as hex', async () => {
|
|
120
|
+
const el = await fixture(html`
|
|
125
121
|
<sp-color-area color="#00ff00"></sp-color-area>
|
|
126
122
|
`);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
123
|
+
await elementUpdated(el);
|
|
124
|
+
expect(el.hue).to.equal(120);
|
|
125
|
+
expect(el.x).to.equal(1);
|
|
126
|
+
expect(el.y).to.equal(0);
|
|
127
|
+
});
|
|
128
|
+
it('accepts "Arrow*" keypresses', async () => {
|
|
129
|
+
const el = await fixture(html`
|
|
134
130
|
<sp-color-area color="hsla(100, 50%, 50%, 1)"></sp-color-area>
|
|
135
131
|
`);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
});
|
|
186
|
-
await changeEvent;
|
|
187
|
-
expect(el.x).to.equal(0.67);
|
|
188
|
-
expect(el.y).to.equal(0.25);
|
|
132
|
+
expect(el.hue, "hue").to.equal(100);
|
|
133
|
+
expect(el.x, "x").to.equal(0.67);
|
|
134
|
+
expect(el.y, "y").to.equal(0.25);
|
|
135
|
+
el.inputX.focus();
|
|
136
|
+
await nextFrame();
|
|
137
|
+
let changeEvent = oneEvent(el, "change");
|
|
138
|
+
await sendKeys({
|
|
139
|
+
press: "ArrowUp"
|
|
140
|
+
});
|
|
141
|
+
await changeEvent;
|
|
142
|
+
changeEvent = oneEvent(el, "change");
|
|
143
|
+
await sendKeys({
|
|
144
|
+
press: "ArrowUp"
|
|
145
|
+
});
|
|
146
|
+
await changeEvent;
|
|
147
|
+
expect(el.x).to.equal(0.67);
|
|
148
|
+
expect(el.y).to.equal(0.23);
|
|
149
|
+
changeEvent = oneEvent(el, "change");
|
|
150
|
+
await sendKeys({
|
|
151
|
+
press: "ArrowRight"
|
|
152
|
+
});
|
|
153
|
+
await changeEvent;
|
|
154
|
+
changeEvent = oneEvent(el, "change");
|
|
155
|
+
await sendKeys({
|
|
156
|
+
press: "ArrowRight"
|
|
157
|
+
});
|
|
158
|
+
await changeEvent;
|
|
159
|
+
expect(el.x).to.equal(0.69);
|
|
160
|
+
expect(el.y).to.equal(0.23);
|
|
161
|
+
changeEvent = oneEvent(el, "change");
|
|
162
|
+
await sendKeys({
|
|
163
|
+
press: "ArrowDown"
|
|
164
|
+
});
|
|
165
|
+
await changeEvent;
|
|
166
|
+
changeEvent = oneEvent(el, "change");
|
|
167
|
+
await sendKeys({
|
|
168
|
+
press: "ArrowDown"
|
|
169
|
+
});
|
|
170
|
+
await changeEvent;
|
|
171
|
+
expect(el.x).to.equal(0.69);
|
|
172
|
+
expect(el.y).to.equal(0.25);
|
|
173
|
+
changeEvent = oneEvent(el, "change");
|
|
174
|
+
await sendKeys({
|
|
175
|
+
press: "ArrowLeft"
|
|
176
|
+
});
|
|
177
|
+
await changeEvent;
|
|
178
|
+
changeEvent = oneEvent(el, "change");
|
|
179
|
+
await sendKeys({
|
|
180
|
+
press: "ArrowLeft"
|
|
189
181
|
});
|
|
190
|
-
|
|
191
|
-
|
|
182
|
+
await changeEvent;
|
|
183
|
+
expect(el.x).to.equal(0.67);
|
|
184
|
+
expect(el.y).to.equal(0.25);
|
|
185
|
+
});
|
|
186
|
+
it('accepts "Arrow*" keypresses with alteration', async () => {
|
|
187
|
+
const el = await fixture(html`
|
|
192
188
|
<sp-color-area color="hsla(100, 50%, 50%, 1)"></sp-color-area>
|
|
193
189
|
`);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
});
|
|
202
|
-
await elementUpdated(el);
|
|
203
|
-
await sendKeys({
|
|
204
|
-
press: 'ArrowUp',
|
|
205
|
-
});
|
|
206
|
-
// This ensures that all the keystrokes are processed seperately
|
|
207
|
-
await elementUpdated(el);
|
|
208
|
-
await sendKeys({
|
|
209
|
-
press: 'ArrowUp',
|
|
210
|
-
});
|
|
211
|
-
await elementUpdated(el);
|
|
212
|
-
expect(el.color).to.equal('hsl(100, 65%, 57%)');
|
|
213
|
-
expect(el.x, 'first').to.equal(0.67);
|
|
214
|
-
expect(el.y).to.equal(0.15);
|
|
215
|
-
await sendKeys({
|
|
216
|
-
press: 'ArrowRight',
|
|
217
|
-
});
|
|
218
|
-
await elementUpdated(el);
|
|
219
|
-
await sendKeys({
|
|
220
|
-
press: 'ArrowRight',
|
|
221
|
-
});
|
|
222
|
-
await elementUpdated(el);
|
|
223
|
-
expect(el.color).to.equal('hsl(100, 69%, 52%)');
|
|
224
|
-
expect(el.x).to.equal(0.77);
|
|
225
|
-
expect(el.y).to.equal(0.15);
|
|
226
|
-
await sendKeys({
|
|
227
|
-
press: 'ArrowDown',
|
|
228
|
-
});
|
|
229
|
-
await elementUpdated(el);
|
|
230
|
-
await sendKeys({
|
|
231
|
-
press: 'ArrowDown',
|
|
232
|
-
});
|
|
233
|
-
await elementUpdated(el);
|
|
234
|
-
expect(el.color).to.equal('hsl(100, 63%, 46%)');
|
|
235
|
-
expect(el.x).to.equal(0.77);
|
|
236
|
-
expect(el.y).to.equal(0.25);
|
|
237
|
-
await sendKeys({
|
|
238
|
-
press: 'ArrowLeft',
|
|
239
|
-
});
|
|
240
|
-
await elementUpdated(el);
|
|
241
|
-
await sendKeys({
|
|
242
|
-
press: 'ArrowLeft',
|
|
243
|
-
});
|
|
244
|
-
await elementUpdated(el);
|
|
245
|
-
await sendKeys({
|
|
246
|
-
up: 'Shift',
|
|
247
|
-
});
|
|
248
|
-
await elementUpdated(el);
|
|
249
|
-
expect(el.color).to.equal('hsl(100, 50%, 50%)');
|
|
250
|
-
expect(el.x, 'last').to.equal(0.67);
|
|
251
|
-
expect(el.y).to.equal(0.25);
|
|
190
|
+
await elementUpdated(el);
|
|
191
|
+
el.focus();
|
|
192
|
+
expect(el.hue, "hue").to.equal(100);
|
|
193
|
+
expect(el.x, "x").to.equal(0.67);
|
|
194
|
+
expect(el.y, "y").to.equal(0.25);
|
|
195
|
+
await sendKeys({
|
|
196
|
+
down: "Shift"
|
|
252
197
|
});
|
|
253
|
-
|
|
254
|
-
|
|
198
|
+
await elementUpdated(el);
|
|
199
|
+
await sendKeys({
|
|
200
|
+
press: "ArrowUp"
|
|
201
|
+
});
|
|
202
|
+
await elementUpdated(el);
|
|
203
|
+
await sendKeys({
|
|
204
|
+
press: "ArrowUp"
|
|
205
|
+
});
|
|
206
|
+
await elementUpdated(el);
|
|
207
|
+
expect(el.color).to.equal("hsl(100, 65%, 57%)");
|
|
208
|
+
expect(el.x, "first").to.equal(0.67);
|
|
209
|
+
expect(el.y).to.equal(0.15);
|
|
210
|
+
await sendKeys({
|
|
211
|
+
press: "ArrowRight"
|
|
212
|
+
});
|
|
213
|
+
await elementUpdated(el);
|
|
214
|
+
await sendKeys({
|
|
215
|
+
press: "ArrowRight"
|
|
216
|
+
});
|
|
217
|
+
await elementUpdated(el);
|
|
218
|
+
expect(el.color).to.equal("hsl(100, 69%, 52%)");
|
|
219
|
+
expect(el.x).to.equal(0.77);
|
|
220
|
+
expect(el.y).to.equal(0.15);
|
|
221
|
+
await sendKeys({
|
|
222
|
+
press: "ArrowDown"
|
|
223
|
+
});
|
|
224
|
+
await elementUpdated(el);
|
|
225
|
+
await sendKeys({
|
|
226
|
+
press: "ArrowDown"
|
|
227
|
+
});
|
|
228
|
+
await elementUpdated(el);
|
|
229
|
+
expect(el.color).to.equal("hsl(100, 63%, 46%)");
|
|
230
|
+
expect(el.x).to.equal(0.77);
|
|
231
|
+
expect(el.y).to.equal(0.25);
|
|
232
|
+
await sendKeys({
|
|
233
|
+
press: "ArrowLeft"
|
|
234
|
+
});
|
|
235
|
+
await elementUpdated(el);
|
|
236
|
+
await sendKeys({
|
|
237
|
+
press: "ArrowLeft"
|
|
238
|
+
});
|
|
239
|
+
await elementUpdated(el);
|
|
240
|
+
await sendKeys({
|
|
241
|
+
up: "Shift"
|
|
242
|
+
});
|
|
243
|
+
await elementUpdated(el);
|
|
244
|
+
expect(el.color).to.equal("hsl(100, 50%, 50%)");
|
|
245
|
+
expect(el.x, "last").to.equal(0.67);
|
|
246
|
+
expect(el.y).to.equal(0.25);
|
|
247
|
+
});
|
|
248
|
+
it("accepts pointer events", async () => {
|
|
249
|
+
const el = await fixture(html`
|
|
255
250
|
<sp-color-area
|
|
256
251
|
style="--spectrum-colorarea-default-width: 192px; --spectrum-colorarea-default-height: 192px;"
|
|
257
252
|
></sp-color-area>
|
|
258
253
|
`);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
254
|
+
await elementUpdated(el);
|
|
255
|
+
await elementUpdated(el);
|
|
256
|
+
const { handle } = el;
|
|
257
|
+
handle.setPointerCapture = () => {
|
|
258
|
+
return;
|
|
259
|
+
};
|
|
260
|
+
handle.releasePointerCapture = () => {
|
|
261
|
+
return;
|
|
262
|
+
};
|
|
263
|
+
expect(el.hue).to.equal(0);
|
|
264
|
+
expect(el.x).to.equal(1);
|
|
265
|
+
expect(el.y).to.equal(0);
|
|
266
|
+
handle.dispatchEvent(new PointerEvent("pointerdown", {
|
|
267
|
+
button: 1,
|
|
268
|
+
pointerId: 1,
|
|
269
|
+
clientX: 100,
|
|
270
|
+
clientY: 100,
|
|
271
|
+
bubbles: true,
|
|
272
|
+
composed: true,
|
|
273
|
+
cancelable: true
|
|
274
|
+
}));
|
|
275
|
+
await elementUpdated(el);
|
|
276
|
+
expect(el.hue).to.equal(0);
|
|
277
|
+
expect(el.x).to.equal(1);
|
|
278
|
+
expect(el.y).to.equal(0);
|
|
279
|
+
const root = el.shadowRoot ? el.shadowRoot : el;
|
|
280
|
+
const gradient = root.querySelector(".gradient");
|
|
281
|
+
gradient.dispatchEvent(new PointerEvent("pointerdown", {
|
|
282
|
+
button: 1,
|
|
283
|
+
pointerId: 1,
|
|
284
|
+
clientX: 100,
|
|
285
|
+
clientY: 100,
|
|
286
|
+
bubbles: true,
|
|
287
|
+
composed: true,
|
|
288
|
+
cancelable: true
|
|
289
|
+
}));
|
|
290
|
+
await elementUpdated(el);
|
|
291
|
+
expect(el.hue).to.equal(0);
|
|
292
|
+
expect(el.x).to.equal(1);
|
|
293
|
+
expect(el.y).to.equal(0);
|
|
294
|
+
gradient.dispatchEvent(new PointerEvent("pointerdown", {
|
|
295
|
+
pointerId: 1,
|
|
296
|
+
clientX: 100,
|
|
297
|
+
clientY: 100,
|
|
298
|
+
bubbles: true,
|
|
299
|
+
composed: true,
|
|
300
|
+
cancelable: true
|
|
301
|
+
}));
|
|
302
|
+
await elementUpdated(el);
|
|
303
|
+
expect(el.hue).to.equal(0);
|
|
304
|
+
expect(el.x, "pointerdown x").to.equal(0.48);
|
|
305
|
+
expect(el.y, "pointerdown y").to.equal(0.48);
|
|
306
|
+
handle.dispatchEvent(new PointerEvent("pointermove", {
|
|
307
|
+
pointerId: 1,
|
|
308
|
+
clientX: 110,
|
|
309
|
+
clientY: 110,
|
|
310
|
+
bubbles: true,
|
|
311
|
+
composed: true,
|
|
312
|
+
cancelable: true
|
|
313
|
+
}));
|
|
314
|
+
handle.dispatchEvent(new PointerEvent("pointerup", {
|
|
315
|
+
pointerId: 1,
|
|
316
|
+
clientX: 110,
|
|
317
|
+
clientY: 110,
|
|
318
|
+
bubbles: true,
|
|
319
|
+
composed: true,
|
|
320
|
+
cancelable: true
|
|
321
|
+
}));
|
|
322
|
+
await elementUpdated(el);
|
|
323
|
+
expect(el.hue).to.equal(0);
|
|
324
|
+
expect(el.x).to.equal(0.53);
|
|
325
|
+
expect(el.y).to.equal(0.53);
|
|
326
|
+
});
|
|
327
|
+
it("responds to events on the internal input element", async () => {
|
|
328
|
+
const inputSpy = spy();
|
|
329
|
+
const changeSpy = spy();
|
|
330
|
+
const el = await fixture(html`
|
|
336
331
|
<sp-color-area
|
|
337
332
|
color="hsla(100, 50%, 50%, 1)"
|
|
338
333
|
@change=${() => changeSpy()}
|
|
339
334
|
@input=${() => inputSpy()}
|
|
340
335
|
></sp-color-area>
|
|
341
336
|
`);
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
337
|
+
await elementUpdated(el);
|
|
338
|
+
el.inputX.focus();
|
|
339
|
+
el.inputX.dispatchEvent(new Event("input", {
|
|
340
|
+
bubbles: true,
|
|
341
|
+
composed: true
|
|
342
|
+
}));
|
|
343
|
+
el.inputX.dispatchEvent(new Event("change", {
|
|
344
|
+
bubbles: true,
|
|
345
|
+
composed: false
|
|
346
|
+
}));
|
|
347
|
+
expect(inputSpy.callCount).to.equal(1);
|
|
348
|
+
expect(changeSpy.callCount).to.equal(1);
|
|
349
|
+
el.inputY.focus();
|
|
350
|
+
el.inputY.dispatchEvent(new Event("input", {
|
|
351
|
+
bubbles: true,
|
|
352
|
+
composed: true
|
|
353
|
+
}));
|
|
354
|
+
el.inputY.dispatchEvent(new Event("change", {
|
|
355
|
+
bubbles: true,
|
|
356
|
+
composed: false
|
|
357
|
+
}));
|
|
358
|
+
expect(inputSpy.callCount).to.equal(2);
|
|
359
|
+
expect(changeSpy.callCount).to.equal(2);
|
|
360
|
+
});
|
|
361
|
+
it('dispatches input and change events in response to "Arrow*" keypresses', async () => {
|
|
362
|
+
const inputSpy = spy();
|
|
363
|
+
const changeSpy = spy();
|
|
364
|
+
const el = await fixture(html`
|
|
370
365
|
<sp-color-area
|
|
371
366
|
color="hsla(100, 50%, 50%, 1)"
|
|
372
367
|
@change=${() => changeSpy()}
|
|
373
368
|
@input=${() => inputSpy()}
|
|
374
369
|
></sp-color-area>
|
|
375
370
|
`);
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
371
|
+
await elementUpdated(el);
|
|
372
|
+
el.inputX.focus();
|
|
373
|
+
inputSpy.resetHistory();
|
|
374
|
+
changeSpy.resetHistory();
|
|
375
|
+
await sendKeys({ press: "ArrowRight" });
|
|
376
|
+
await sendKeys({ press: "ArrowRight" });
|
|
377
|
+
await elementUpdated(el);
|
|
378
|
+
expect(inputSpy.callCount).to.equal(2);
|
|
379
|
+
expect(changeSpy.callCount).to.equal(2);
|
|
380
|
+
el.inputY.focus();
|
|
381
|
+
inputSpy.resetHistory();
|
|
382
|
+
changeSpy.resetHistory();
|
|
383
|
+
await sendKeys({ press: "ArrowUp" });
|
|
384
|
+
await sendKeys({ press: "ArrowUp" });
|
|
385
|
+
await elementUpdated(el);
|
|
386
|
+
expect(inputSpy.callCount).to.equal(2);
|
|
387
|
+
expect(changeSpy.callCount).to.equal(2);
|
|
388
|
+
el.inputY.focus();
|
|
389
|
+
inputSpy.resetHistory();
|
|
390
|
+
changeSpy.resetHistory();
|
|
391
|
+
await sendKeys({ press: "ArrowDown" });
|
|
392
|
+
await sendKeys({ press: "ArrowDown" });
|
|
393
|
+
await elementUpdated(el);
|
|
394
|
+
expect(inputSpy.callCount).to.equal(2);
|
|
395
|
+
expect(changeSpy.callCount).to.equal(2);
|
|
396
|
+
el.inputX.focus();
|
|
397
|
+
inputSpy.resetHistory();
|
|
398
|
+
changeSpy.resetHistory();
|
|
399
|
+
await sendKeys({ press: "ArrowLeft" });
|
|
400
|
+
await sendKeys({ press: "ArrowLeft" });
|
|
401
|
+
await elementUpdated(el);
|
|
402
|
+
expect(inputSpy.callCount).to.equal(2);
|
|
403
|
+
expect(changeSpy.callCount).to.equal(2);
|
|
404
|
+
});
|
|
405
|
+
it("retains `hue` value when s = 0 in HSL string format", async () => {
|
|
406
|
+
const el = await fixture(html`
|
|
412
407
|
<sp-color-area color="hsl(100, 50%, 50%)"></sp-color-area>
|
|
413
408
|
`);
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
409
|
+
await elementUpdated(el);
|
|
410
|
+
expect(el.hue, "hue").to.equal(100);
|
|
411
|
+
expect(el.x, "x").to.equal(0.67);
|
|
412
|
+
expect(el.y, "y").to.equal(0.25);
|
|
413
|
+
expect(el.color).to.equal("hsl(100, 50%, 50%)");
|
|
414
|
+
el.color = "hsl(100, 0%, 50%)";
|
|
415
|
+
await elementUpdated(el);
|
|
416
|
+
expect(el.hue, "new hue").to.equal(100);
|
|
417
|
+
expect(el.x, "new x").to.equal(0);
|
|
418
|
+
expect(el.y, "new y").to.equal(0.5);
|
|
419
|
+
expect(el.color).to.equal("hsl(100, 0%, 50%)");
|
|
420
|
+
});
|
|
421
|
+
it("retains `hue` value when s = 0 in HSL object format", async () => {
|
|
422
|
+
let inputColor = { h: 100, s: 0.5, l: 0.5 };
|
|
423
|
+
const el = await fixture(html`
|
|
429
424
|
<sp-color-area .color=${inputColor}></sp-color-area>
|
|
430
425
|
`);
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
426
|
+
await elementUpdated(el);
|
|
427
|
+
let outputColor = el.color;
|
|
428
|
+
const variance = 5e-5;
|
|
429
|
+
expect(el.hue).to.equal(100);
|
|
430
|
+
expect(el.x, "x").to.equal(0.67);
|
|
431
|
+
expect(el.y, "y").to.equal(0.25);
|
|
432
|
+
expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
|
|
433
|
+
expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
|
|
434
|
+
expect(Math.abs(outputColor.l - inputColor.l)).to.be.lessThan(variance);
|
|
435
|
+
inputColor = { h: 100, s: 0, l: 0.5 };
|
|
436
|
+
el.color = inputColor;
|
|
437
|
+
await elementUpdated(el);
|
|
438
|
+
outputColor = el.color;
|
|
439
|
+
expect(el.hue).to.equal(100);
|
|
440
|
+
expect(el.x, "x").to.equal(0);
|
|
441
|
+
expect(el.y, "y").to.equal(0.5);
|
|
442
|
+
expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
|
|
443
|
+
expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
|
|
444
|
+
expect(Math.abs(outputColor.l - inputColor.l)).to.be.lessThan(variance);
|
|
445
|
+
});
|
|
446
|
+
it("retains `hue` value when s = 0 in HSV string format", async () => {
|
|
447
|
+
const el = await fixture(html`
|
|
453
448
|
<sp-color-area color="hsv(100, 50%, 50%)"></sp-color-area>
|
|
454
449
|
`);
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
450
|
+
await elementUpdated(el);
|
|
451
|
+
expect(el.hue, "hue").to.equal(100);
|
|
452
|
+
expect(el.x, "x").to.equal(0.5);
|
|
453
|
+
expect(el.y, "y").to.equal(0.5);
|
|
454
|
+
expect(el.color).to.equal("hsv(100, 50%, 50%)");
|
|
455
|
+
el.color = "hsv(100, 0%, 50%)";
|
|
456
|
+
await elementUpdated(el);
|
|
457
|
+
expect(el.hue, "new hue").to.equal(100);
|
|
458
|
+
expect(el.x, "new x").to.equal(0);
|
|
459
|
+
expect(el.y, "new y").to.equal(0.5);
|
|
460
|
+
expect(el.color).to.equal("hsv(100, 0%, 50%)");
|
|
461
|
+
});
|
|
462
|
+
it("retains `hue` value when s = 0 in HSV object format", async () => {
|
|
463
|
+
let inputColor = { h: 100, s: 0.5, v: 0.5 };
|
|
464
|
+
const el = await fixture(html`
|
|
470
465
|
<sp-color-area .color=${inputColor}></sp-color-area>
|
|
471
466
|
`);
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
// hsv
|
|
511
|
-
{ name: 'HSV String', color: 'hsv(300, 75%, 100%)' },
|
|
512
|
-
{ name: 'HSV', color: { h: 300, s: 0.75, v: 1, a: 1 } },
|
|
513
|
-
];
|
|
514
|
-
colorFormats.map((format) => {
|
|
515
|
-
it(`maintains \`color\` format as ${format.name}`, async () => {
|
|
516
|
-
const el = await fixture(html `
|
|
467
|
+
await elementUpdated(el);
|
|
468
|
+
let outputColor = el.color;
|
|
469
|
+
const variance = 5e-5;
|
|
470
|
+
expect(el.hue).to.equal(100);
|
|
471
|
+
expect(el.x, "x").to.equal(0.5);
|
|
472
|
+
expect(el.y, "y").to.equal(0.5);
|
|
473
|
+
expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
|
|
474
|
+
expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
|
|
475
|
+
expect(Math.abs(outputColor.v - inputColor.v)).to.be.lessThan(variance);
|
|
476
|
+
inputColor = { h: 100, s: 0, v: 0.5 };
|
|
477
|
+
el.color = inputColor;
|
|
478
|
+
await elementUpdated(el);
|
|
479
|
+
outputColor = el.color;
|
|
480
|
+
expect(el.hue).to.equal(100);
|
|
481
|
+
expect(el.x, "x").to.equal(0);
|
|
482
|
+
expect(el.y, "y").to.equal(0.5);
|
|
483
|
+
expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
|
|
484
|
+
expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
|
|
485
|
+
expect(Math.abs(outputColor.v - inputColor.v)).to.be.lessThan(variance);
|
|
486
|
+
});
|
|
487
|
+
const colorFormats = [
|
|
488
|
+
{ name: "RGB String", color: "rgb(204, 51, 204)" },
|
|
489
|
+
{ name: "RGB", color: { r: 204, g: 51, b: 204, a: 1 } },
|
|
490
|
+
{ name: "PRGB String", color: "rgb(80%, 20%, 80%)" },
|
|
491
|
+
{ name: "PRGB", color: { r: "80%", g: "20%", b: "80%", a: 1 } },
|
|
492
|
+
{ name: "Hex", color: "cc33cc" },
|
|
493
|
+
{ name: "Hex String", color: "#cc33cc" },
|
|
494
|
+
{ name: "Hex8", color: "cc33ccff" },
|
|
495
|
+
{ name: "Hex8 String", color: "#cc33ccff" },
|
|
496
|
+
{ name: "string", color: "red" },
|
|
497
|
+
{ name: "HSL String", color: "hsl(300, 60%, 50%)" },
|
|
498
|
+
{ name: "HSL", color: { h: 300, s: 0.6000000000000001, l: 0.5, a: 1 } },
|
|
499
|
+
{ name: "HSV String", color: "hsv(300, 75%, 100%)" },
|
|
500
|
+
{ name: "HSV", color: { h: 300, s: 0.75, v: 1, a: 1 } }
|
|
501
|
+
];
|
|
502
|
+
colorFormats.map((format) => {
|
|
503
|
+
it(`maintains \`color\` format as ${format.name}`, async () => {
|
|
504
|
+
const el = await fixture(html`
|
|
517
505
|
<sp-color-area></sp-color-area>
|
|
518
506
|
`);
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
expect(el.color).to.deep.equal(format.color);
|
|
525
|
-
});
|
|
507
|
+
el.color = format.color;
|
|
508
|
+
if (format.name.startsWith("Hex")) {
|
|
509
|
+
expect(el.color).to.equal(format.color);
|
|
510
|
+
} else
|
|
511
|
+
expect(el.color).to.deep.equal(format.color);
|
|
526
512
|
});
|
|
527
|
-
|
|
528
|
-
|
|
513
|
+
});
|
|
514
|
+
it(`maintains \`color\` format as TinyColor`, async () => {
|
|
515
|
+
const el = await fixture(html`
|
|
529
516
|
<sp-color-area></sp-color-area>
|
|
530
517
|
`);
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
518
|
+
const color = new TinyColor("rgb(204, 51, 204)");
|
|
519
|
+
el.color = color;
|
|
520
|
+
expect(color.equals(el.color));
|
|
521
|
+
});
|
|
522
|
+
it(`resolves Hex3 format to Hex6 format`, async () => {
|
|
523
|
+
const el = await fixture(html`
|
|
537
524
|
<sp-color-area></sp-color-area>
|
|
538
525
|
`);
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
526
|
+
el.color = "0f0";
|
|
527
|
+
expect(el.color).to.equal("00ff00");
|
|
528
|
+
el.color = "#1e0";
|
|
529
|
+
expect(el.color).to.equal("#11ee00");
|
|
530
|
+
});
|
|
531
|
+
it(`resolves Hex4 format to Hex8 format`, async () => {
|
|
532
|
+
const el = await fixture(html`
|
|
546
533
|
<sp-color-area></sp-color-area>
|
|
547
534
|
`);
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
535
|
+
el.color = "f3af";
|
|
536
|
+
expect(el.color).to.equal("ff33aaff");
|
|
537
|
+
el.color = "#f3af";
|
|
538
|
+
expect(el.color).to.equal("#ff33aaff");
|
|
539
|
+
});
|
|
553
540
|
});
|
|
554
|
-
//# sourceMappingURL=color-area.test.js.map
|
|
541
|
+
//# sourceMappingURL=color-area.test.js.map
|