@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.
@@ -1,554 +1,541 @@
1
- /*
2
- Copyright 2020 Adobe. All rights reserved.
3
- This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License. You may obtain a copy
5
- of the License at http://www.apache.org/licenses/LICENSE-2.0
6
-
7
- Unless required by applicable law or agreed to in writing, software distributed under
8
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- OF ANY KIND, either express or implied. See the License for the specific language
10
- governing permissions and limitations under the License.
11
- */
12
- import { elementUpdated, expect, fixture, html, nextFrame, oneEvent, } from '@open-wc/testing';
13
- import { TinyColor } from '@ctrl/tinycolor';
14
- import '../sp-color-area.js';
15
- import { sendKeys } from '@web/test-runner-commands';
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
- await elementUpdated(el);
23
- await expect(el).to.be.accessible();
24
- });
25
- it('manages a single tab stop', async () => {
26
- const test = await fixture(html `
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
- const el = test.querySelector('sp-color-area');
34
- const input1 = test.querySelector('input:nth-of-type(1)');
35
- const input2 = test.querySelector('input:nth-of-type(2)');
36
- await elementUpdated(el);
37
- input1.focus();
38
- expect(document.activeElement, 'before input').to.equal(input1);
39
- await sendKeys({
40
- press: 'Tab',
41
- });
42
- await elementUpdated(el);
43
- expect(document.activeElement, 'element').to.equal(el);
44
- let value = el.value;
45
- await sendKeys({
46
- press: 'ArrowRight',
47
- });
48
- await elementUpdated(el);
49
- expect(el.value).to.not.equal(value);
50
- await sendKeys({
51
- press: 'Tab',
52
- });
53
- await elementUpdated(el);
54
- expect(document.activeElement, 'after input').to.equal(input2);
55
- await sendKeys({
56
- press: 'Shift+Tab',
57
- });
58
- await elementUpdated(el);
59
- expect(document.activeElement, 'element again').to.equal(el);
60
- value = el.value;
61
- await sendKeys({
62
- press: 'ArrowDown',
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
- it('provides separate aria-labels for X and Y inputs', async () => {
71
- const el = await fixture(html `
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
- const inputX = el.shadowRoot.querySelector('input[name="x"]');
75
- const inputY = el.shadowRoot.querySelector('input[name="y"]');
76
- expect(inputX === null || inputX === void 0 ? void 0 : inputX.getAttribute('aria-label')).to.equal('saturation');
77
- expect(inputY === null || inputY === void 0 ? void 0 : inputY.getAttribute('aria-label')).to.equal('luminosity');
78
- });
79
- it('overrides both X and Y labels with a provided "label" attribute', async () => {
80
- const el = await fixture(html `
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
- const inputX = el.shadowRoot.querySelector('input[name="x"]');
87
- const inputY = el.shadowRoot.querySelector('input[name="y"]');
88
- expect(inputX === null || inputX === void 0 ? void 0 : inputX.getAttribute('aria-label')).to.equal('something custom');
89
- expect(inputY === null || inputY === void 0 ? void 0 : inputY.getAttribute('aria-label')).to.equal('something custom');
90
- });
91
- it('accepts "color" values as hsl', async () => {
92
- const el = await fixture(html `
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
- await elementUpdated(el);
96
- expect(el.hue, 'hue').to.equal(100);
97
- expect(el.x, 'x').to.equal(0.67);
98
- expect(el.y, 'y').to.equal(0.25);
99
- });
100
- it('accepts "color" values as hsla', async () => {
101
- const el = await fixture(html `
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
- await elementUpdated(el);
105
- expect(el.hue, 'hugh').to.equal(100);
106
- expect(el.x, 'ex').to.equal(0.67);
107
- expect(el.y, 'why').to.equal(0.25);
108
- el.color = 'hsla(120, 100%, 0, 1)';
109
- await elementUpdated(el);
110
- expect(el.hue, 'hue 2').to.equal(120);
111
- expect(el.x, 'x 2').to.equal(0);
112
- expect(el.y, 'y 2').to.equal(1);
113
- });
114
- it('accepts "color" values as rgb', async () => {
115
- const el = await fixture(html `
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
- await elementUpdated(el);
119
- expect(el.hue).to.equal(120);
120
- expect(el.x).to.equal(1);
121
- expect(el.y).to.equal(0);
122
- });
123
- it('accepts "color" values as hex', async () => {
124
- const el = await fixture(html `
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
- await elementUpdated(el);
128
- expect(el.hue).to.equal(120);
129
- expect(el.x).to.equal(1);
130
- expect(el.y).to.equal(0);
131
- });
132
- it('accepts "Arrow*" keypresses', async () => {
133
- const el = await fixture(html `
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
- expect(el.hue, 'hue').to.equal(100);
137
- expect(el.x, 'x').to.equal(0.67);
138
- expect(el.y, 'y').to.equal(0.25);
139
- el.inputX.focus();
140
- await nextFrame();
141
- let changeEvent = oneEvent(el, 'change');
142
- await sendKeys({
143
- press: 'ArrowUp',
144
- });
145
- await changeEvent;
146
- changeEvent = oneEvent(el, 'change');
147
- await sendKeys({
148
- press: 'ArrowUp',
149
- });
150
- await changeEvent;
151
- expect(el.x).to.equal(0.67);
152
- expect(el.y).to.equal(0.23);
153
- changeEvent = oneEvent(el, 'change');
154
- await sendKeys({
155
- press: 'ArrowRight',
156
- });
157
- await changeEvent;
158
- changeEvent = oneEvent(el, 'change');
159
- await sendKeys({
160
- press: 'ArrowRight',
161
- });
162
- await changeEvent;
163
- expect(el.x).to.equal(0.69);
164
- expect(el.y).to.equal(0.23);
165
- changeEvent = oneEvent(el, 'change');
166
- await sendKeys({
167
- press: 'ArrowDown',
168
- });
169
- await changeEvent;
170
- changeEvent = oneEvent(el, 'change');
171
- await sendKeys({
172
- press: 'ArrowDown',
173
- });
174
- await changeEvent;
175
- expect(el.x).to.equal(0.69);
176
- expect(el.y).to.equal(0.25);
177
- changeEvent = oneEvent(el, 'change');
178
- await sendKeys({
179
- press: 'ArrowLeft',
180
- });
181
- await changeEvent;
182
- changeEvent = oneEvent(el, 'change');
183
- await sendKeys({
184
- press: 'ArrowLeft',
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
- it('accepts "Arrow*" keypresses with alteration', async () => {
191
- const el = await fixture(html `
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
- await elementUpdated(el);
195
- el.focus();
196
- expect(el.hue, 'hue').to.equal(100);
197
- expect(el.x, 'x').to.equal(0.67);
198
- expect(el.y, 'y').to.equal(0.25);
199
- await sendKeys({
200
- down: 'Shift',
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
- it('accepts pointer events', async () => {
254
- const el = await fixture(html `
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
- await elementUpdated(el);
260
- await elementUpdated(el);
261
- const { handle } = el;
262
- handle.setPointerCapture = () => {
263
- return;
264
- };
265
- handle.releasePointerCapture = () => {
266
- return;
267
- };
268
- expect(el.hue).to.equal(0);
269
- expect(el.x).to.equal(1);
270
- expect(el.y).to.equal(0);
271
- handle.dispatchEvent(new PointerEvent('pointerdown', {
272
- button: 1,
273
- pointerId: 1,
274
- clientX: 100,
275
- clientY: 100,
276
- bubbles: true,
277
- composed: true,
278
- cancelable: true,
279
- }));
280
- await elementUpdated(el);
281
- expect(el.hue).to.equal(0);
282
- expect(el.x).to.equal(1);
283
- expect(el.y).to.equal(0);
284
- const root = el.shadowRoot ? el.shadowRoot : el;
285
- const gradient = root.querySelector('.gradient');
286
- gradient.dispatchEvent(new PointerEvent('pointerdown', {
287
- button: 1,
288
- pointerId: 1,
289
- clientX: 100,
290
- clientY: 100,
291
- bubbles: true,
292
- composed: true,
293
- cancelable: true,
294
- }));
295
- await elementUpdated(el);
296
- expect(el.hue).to.equal(0);
297
- expect(el.x).to.equal(1);
298
- expect(el.y).to.equal(0);
299
- gradient.dispatchEvent(new PointerEvent('pointerdown', {
300
- pointerId: 1,
301
- clientX: 100,
302
- clientY: 100,
303
- bubbles: true,
304
- composed: true,
305
- cancelable: true,
306
- }));
307
- await elementUpdated(el);
308
- expect(el.hue).to.equal(0);
309
- expect(el.x, 'pointerdown x').to.equal(0.48);
310
- expect(el.y, 'pointerdown y').to.equal(0.48);
311
- handle.dispatchEvent(new PointerEvent('pointermove', {
312
- pointerId: 1,
313
- clientX: 110,
314
- clientY: 110,
315
- bubbles: true,
316
- composed: true,
317
- cancelable: true,
318
- }));
319
- handle.dispatchEvent(new PointerEvent('pointerup', {
320
- pointerId: 1,
321
- clientX: 110,
322
- clientY: 110,
323
- bubbles: true,
324
- composed: true,
325
- cancelable: true,
326
- }));
327
- await elementUpdated(el);
328
- expect(el.hue).to.equal(0);
329
- expect(el.x).to.equal(0.53);
330
- expect(el.y).to.equal(0.53);
331
- });
332
- it('responds to events on the internal input element', async () => {
333
- const inputSpy = spy();
334
- const changeSpy = spy();
335
- const el = await fixture(html `
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
- await elementUpdated(el);
343
- el.inputX.focus();
344
- el.inputX.dispatchEvent(new Event('input', {
345
- bubbles: true,
346
- composed: true,
347
- }));
348
- el.inputX.dispatchEvent(new Event('change', {
349
- bubbles: true,
350
- composed: false, // native change events do not compose themselves by default
351
- }));
352
- expect(inputSpy.callCount).to.equal(1);
353
- expect(changeSpy.callCount).to.equal(1);
354
- el.inputY.focus();
355
- el.inputY.dispatchEvent(new Event('input', {
356
- bubbles: true,
357
- composed: true,
358
- }));
359
- el.inputY.dispatchEvent(new Event('change', {
360
- bubbles: true,
361
- composed: false, // native change events do not compose themselves by default
362
- }));
363
- expect(inputSpy.callCount).to.equal(2);
364
- expect(changeSpy.callCount).to.equal(2);
365
- });
366
- it('dispatches input and change events in response to "Arrow*" keypresses', async () => {
367
- const inputSpy = spy();
368
- const changeSpy = spy();
369
- const el = await fixture(html `
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
- await elementUpdated(el);
377
- el.inputX.focus();
378
- inputSpy.resetHistory();
379
- changeSpy.resetHistory();
380
- await sendKeys({ press: 'ArrowRight' });
381
- await sendKeys({ press: 'ArrowRight' });
382
- await elementUpdated(el);
383
- expect(inputSpy.callCount).to.equal(2);
384
- expect(changeSpy.callCount).to.equal(2);
385
- el.inputY.focus();
386
- inputSpy.resetHistory();
387
- changeSpy.resetHistory();
388
- await sendKeys({ press: 'ArrowUp' });
389
- await sendKeys({ press: 'ArrowUp' });
390
- await elementUpdated(el);
391
- expect(inputSpy.callCount).to.equal(2);
392
- expect(changeSpy.callCount).to.equal(2);
393
- el.inputY.focus();
394
- inputSpy.resetHistory();
395
- changeSpy.resetHistory();
396
- await sendKeys({ press: 'ArrowDown' });
397
- await sendKeys({ press: 'ArrowDown' });
398
- await elementUpdated(el);
399
- expect(inputSpy.callCount).to.equal(2);
400
- expect(changeSpy.callCount).to.equal(2);
401
- el.inputX.focus();
402
- inputSpy.resetHistory();
403
- changeSpy.resetHistory();
404
- await sendKeys({ press: 'ArrowLeft' });
405
- await sendKeys({ press: 'ArrowLeft' });
406
- await elementUpdated(el);
407
- expect(inputSpy.callCount).to.equal(2);
408
- expect(changeSpy.callCount).to.equal(2);
409
- });
410
- it('retains `hue` value when s = 0 in HSL string format', async () => {
411
- const el = await fixture(html `
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
- await elementUpdated(el);
415
- expect(el.hue, 'hue').to.equal(100);
416
- expect(el.x, 'x').to.equal(0.67);
417
- expect(el.y, 'y').to.equal(0.25);
418
- expect(el.color).to.equal('hsl(100, 50%, 50%)');
419
- el.color = 'hsl(100, 0%, 50%)';
420
- await elementUpdated(el);
421
- expect(el.hue, 'new hue').to.equal(100);
422
- expect(el.x, 'new x').to.equal(0);
423
- expect(el.y, 'new y').to.equal(0.5);
424
- expect(el.color).to.equal('hsl(100, 0%, 50%)');
425
- });
426
- it('retains `hue` value when s = 0 in HSL object format', async () => {
427
- let inputColor = { h: 100, s: 0.5, l: 0.5 };
428
- const el = await fixture(html `
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
- await elementUpdated(el);
432
- let outputColor = el.color;
433
- const variance = 0.00005;
434
- expect(el.hue).to.equal(100);
435
- expect(el.x, 'x').to.equal(0.67);
436
- expect(el.y, 'y').to.equal(0.25);
437
- expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
438
- expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
439
- expect(Math.abs(outputColor.l - inputColor.l)).to.be.lessThan(variance);
440
- inputColor = { h: 100, s: 0, l: 0.5 };
441
- el.color = inputColor;
442
- await elementUpdated(el);
443
- outputColor = el.color;
444
- expect(el.hue).to.equal(100);
445
- expect(el.x, 'x').to.equal(0);
446
- expect(el.y, 'y').to.equal(0.5);
447
- expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
448
- expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
449
- expect(Math.abs(outputColor.l - inputColor.l)).to.be.lessThan(variance);
450
- });
451
- it('retains `hue` value when s = 0 in HSV string format', async () => {
452
- const el = await fixture(html `
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
- await elementUpdated(el);
456
- expect(el.hue, 'hue').to.equal(100);
457
- expect(el.x, 'x').to.equal(0.5);
458
- expect(el.y, 'y').to.equal(0.5);
459
- expect(el.color).to.equal('hsv(100, 50%, 50%)');
460
- el.color = 'hsv(100, 0%, 50%)';
461
- await elementUpdated(el);
462
- expect(el.hue, 'new hue').to.equal(100);
463
- expect(el.x, 'new x').to.equal(0);
464
- expect(el.y, 'new y').to.equal(0.5);
465
- expect(el.color).to.equal('hsv(100, 0%, 50%)');
466
- });
467
- it('retains `hue` value when s = 0 in HSV object format', async () => {
468
- let inputColor = { h: 100, s: 0.5, v: 0.5 };
469
- const el = await fixture(html `
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
- await elementUpdated(el);
473
- let outputColor = el.color;
474
- const variance = 0.00005;
475
- expect(el.hue).to.equal(100);
476
- expect(el.x, 'x').to.equal(0.5);
477
- expect(el.y, 'y').to.equal(0.5);
478
- expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
479
- expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
480
- expect(Math.abs(outputColor.v - inputColor.v)).to.be.lessThan(variance);
481
- inputColor = { h: 100, s: 0, v: 0.5 };
482
- el.color = inputColor;
483
- await elementUpdated(el);
484
- outputColor = el.color;
485
- expect(el.hue).to.equal(100);
486
- expect(el.x, 'x').to.equal(0);
487
- expect(el.y, 'y').to.equal(0.5);
488
- expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
489
- expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
490
- expect(Math.abs(outputColor.v - inputColor.v)).to.be.lessThan(variance);
491
- });
492
- const colorFormats = [
493
- //rgb
494
- { name: 'RGB String', color: 'rgb(204, 51, 204)' },
495
- { name: 'RGB', color: { r: 204, g: 51, b: 204, a: 1 } },
496
- //prgb
497
- { name: 'PRGB String', color: 'rgb(80%, 20%, 80%)' },
498
- { name: 'PRGB', color: { r: '80%', g: '20%', b: '80%', a: 1 } },
499
- // hex
500
- { name: 'Hex', color: 'cc33cc' },
501
- { name: 'Hex String', color: '#cc33cc' },
502
- // hex8
503
- { name: 'Hex8', color: 'cc33ccff' },
504
- { name: 'Hex8 String', color: '#cc33ccff' },
505
- // name
506
- { name: 'string', color: 'red' },
507
- // hsl
508
- { name: 'HSL String', color: 'hsl(300, 60%, 50%)' },
509
- { name: 'HSL', color: { h: 300, s: 0.6000000000000001, l: 0.5, a: 1 } },
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
- el.color = format.color;
520
- if (format.name.startsWith('Hex')) {
521
- expect(el.color).to.equal(format.color);
522
- }
523
- else
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
- it(`maintains \`color\` format as TinyColor`, async () => {
528
- const el = await fixture(html `
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
- const color = new TinyColor('rgb(204, 51, 204)');
532
- el.color = color;
533
- expect(color.equals(el.color));
534
- });
535
- it(`resolves Hex3 format to Hex6 format`, async () => {
536
- const el = await fixture(html `
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
- el.color = '0f0';
540
- expect(el.color).to.equal('00ff00');
541
- el.color = '#1e0';
542
- expect(el.color).to.equal('#11ee00');
543
- });
544
- it(`resolves Hex4 format to Hex8 format`, async () => {
545
- const el = await fixture(html `
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
- el.color = 'f3af';
549
- expect(el.color).to.equal('ff33aaff');
550
- el.color = '#f3af';
551
- expect(el.color).to.equal('#ff33aaff');
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