@spectrum-web-components/color-area 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/package.json +7 -7
  2. package/sp-color-area.d.ts +6 -0
  3. package/sp-color-area.dev.js +5 -0
  4. package/sp-color-area.dev.js.map +7 -0
  5. package/sp-color-area.js +2 -0
  6. package/sp-color-area.js.map +7 -0
  7. package/src/ColorArea.d.ts +65 -0
  8. package/src/ColorArea.dev.js +507 -0
  9. package/src/ColorArea.dev.js.map +7 -0
  10. package/src/ColorArea.js +64 -0
  11. package/src/ColorArea.js.map +7 -0
  12. package/src/color-area-overrides.css.d.ts +2 -0
  13. package/src/color-area-overrides.css.dev.js +7 -0
  14. package/src/color-area-overrides.css.dev.js.map +7 -0
  15. package/src/color-area-overrides.css.js +4 -0
  16. package/src/color-area-overrides.css.js.map +7 -0
  17. package/src/color-area.css.d.ts +2 -0
  18. package/src/color-area.css.dev.js +7 -0
  19. package/src/color-area.css.dev.js.map +7 -0
  20. package/src/color-area.css.js +4 -0
  21. package/src/color-area.css.js.map +7 -0
  22. package/src/index.d.ts +1 -0
  23. package/src/index.dev.js +3 -0
  24. package/src/index.dev.js.map +7 -0
  25. package/src/index.js +2 -0
  26. package/src/index.js.map +7 -0
  27. package/src/spectrum-color-area.css.d.ts +2 -0
  28. package/src/spectrum-color-area.css.dev.js +7 -0
  29. package/src/spectrum-color-area.css.dev.js.map +7 -0
  30. package/src/spectrum-color-area.css.js +4 -0
  31. package/src/spectrum-color-area.css.js.map +7 -0
  32. package/src/types.d.ts +13 -0
  33. package/src/types.dev.js +2 -0
  34. package/src/types.dev.js.map +7 -0
  35. package/src/types.js +2 -0
  36. package/src/types.js.map +7 -0
  37. package/stories/color-area.stories.js +149 -0
  38. package/stories/color-area.stories.js.map +7 -0
  39. package/test/benchmark/basic-test.js +8 -0
  40. package/test/benchmark/basic-test.js.map +7 -0
  41. package/test/color-area-memory.test.js +8 -0
  42. package/test/color-area-memory.test.js.map +7 -0
  43. package/test/color-area.test-vrt.js +5 -0
  44. package/test/color-area.test-vrt.js.map +7 -0
  45. package/test/color-area.test.js +776 -0
  46. package/test/color-area.test.js.map +7 -0
@@ -0,0 +1,776 @@
1
+ "use strict";
2
+ import {
3
+ elementUpdated,
4
+ expect,
5
+ fixture,
6
+ html,
7
+ nextFrame,
8
+ oneEvent
9
+ } from "@open-wc/testing";
10
+ import { TinyColor } from "@ctrl/tinycolor";
11
+ import "@spectrum-web-components/color-area/sp-color-area.js";
12
+ import { sendKeys } from "@web/test-runner-commands";
13
+ import { spy } from "sinon";
14
+ import { testForLitDevWarnings } from "../../../test/testing-helpers.js";
15
+ describe("ColorArea", () => {
16
+ testForLitDevWarnings(
17
+ async () => await fixture(html`
18
+ <sp-color-area></sp-color-area>
19
+ `)
20
+ );
21
+ it("loads default color-area accessibly", async () => {
22
+ const el = await fixture(html`
23
+ <sp-color-area></sp-color-area>
24
+ `);
25
+ await elementUpdated(el);
26
+ await expect(el).to.be.accessible();
27
+ });
28
+ it("handleBlur returns early if _pointerDown is true", async () => {
29
+ const el = await fixture(html`
30
+ <sp-color-area></sp-color-area>
31
+ `);
32
+ await sendKeys({ press: "Tab" });
33
+ await el.updateComplete;
34
+ el._pointerDown = true;
35
+ await el.updateComplete;
36
+ el.handleBlur();
37
+ await el.updateComplete;
38
+ expect(el.focused).to.be.true;
39
+ });
40
+ it("updates color when x value changes", async () => {
41
+ const el = await fixture(html`
42
+ <sp-color-area></sp-color-area>
43
+ `);
44
+ await el.updateComplete;
45
+ expect(el.x).to.equal(1);
46
+ el.x = 0.3;
47
+ await el.updateComplete;
48
+ expect(el.x).to.equal(0.3);
49
+ const handle = el.shadowRoot.querySelector(".handle");
50
+ expect(handle.color).to.equal("hsl(0, 100%, 85%)");
51
+ });
52
+ it("updates color when y value changes", async () => {
53
+ const el = await fixture(html`
54
+ <sp-color-area></sp-color-area>
55
+ `);
56
+ await el.updateComplete;
57
+ expect(el.y).to.equal(1);
58
+ el.y = 0.5;
59
+ await el.updateComplete;
60
+ expect(el.y).to.equal(0.5);
61
+ const handle = el.shadowRoot.querySelector(".handle");
62
+ expect(handle.color).to.equal("hsl(0, 100%, 25%)");
63
+ });
64
+ it("manages a single tab stop", async () => {
65
+ const test = await fixture(html`
66
+ <div>
67
+ <input type="text" />
68
+ <sp-color-area color="hsl(100, 50%, 50%)"></sp-color-area>
69
+ <input type="text" />
70
+ </div>
71
+ `);
72
+ const el = test.querySelector("sp-color-area");
73
+ const input1 = test.querySelector(
74
+ "input:nth-of-type(1)"
75
+ );
76
+ const input2 = test.querySelector(
77
+ "input:nth-of-type(2)"
78
+ );
79
+ await elementUpdated(el);
80
+ input1.focus();
81
+ expect(document.activeElement, "before input").to.equal(input1);
82
+ await sendKeys({
83
+ press: "Tab"
84
+ });
85
+ await elementUpdated(el);
86
+ expect(document.activeElement, "element").to.equal(el);
87
+ let value = el.value;
88
+ await sendKeys({
89
+ press: "ArrowRight"
90
+ });
91
+ await elementUpdated(el);
92
+ expect(el.value).to.not.equal(value);
93
+ await sendKeys({
94
+ press: "Tab"
95
+ });
96
+ await elementUpdated(el);
97
+ expect(document.activeElement, "after input").to.equal(input2);
98
+ await sendKeys({
99
+ press: "Shift+Tab"
100
+ });
101
+ await elementUpdated(el);
102
+ expect(document.activeElement, "element again").to.equal(el);
103
+ value = el.value;
104
+ await sendKeys({
105
+ press: "ArrowDown"
106
+ });
107
+ expect(el.value).to.not.equal(value);
108
+ await sendKeys({
109
+ press: "Shift+Tab"
110
+ });
111
+ expect(document.activeElement, "before input again").to.equal(input1);
112
+ });
113
+ it("provides separate aria-labels for X and Y inputs", async () => {
114
+ const el = await fixture(html`
115
+ <sp-color-area color="hsl(100, 50%, 50%)"></sp-color-area>
116
+ `);
117
+ const inputX = el.shadowRoot.querySelector('input[name="x"]');
118
+ const inputY = el.shadowRoot.querySelector('input[name="y"]');
119
+ expect(inputX == null ? void 0 : inputX.getAttribute("aria-label")).to.equal(
120
+ "saturation Color Picker"
121
+ );
122
+ expect(inputY == null ? void 0 : inputY.getAttribute("aria-label")).to.equal(
123
+ "luminosity Color Picker"
124
+ );
125
+ expect(inputX == null ? void 0 : inputX.getAttribute("aria-roledescription")).to.equal(
126
+ "2d slider"
127
+ );
128
+ expect(inputY == null ? void 0 : inputY.getAttribute("aria-roledescription")).to.equal(
129
+ "2d slider"
130
+ );
131
+ expect(inputX == null ? void 0 : inputX.getAttribute("aria-valuetext")).to.equal(
132
+ "67%, saturation, 75%, luminosity"
133
+ );
134
+ expect(inputY == null ? void 0 : inputY.getAttribute("aria-valuetext")).to.equal(
135
+ "75%, luminosity, 67%, saturation"
136
+ );
137
+ });
138
+ it('overrides X and Y labels with provided "labelX" and "labelY" attributes', async () => {
139
+ const el = await fixture(html`
140
+ <sp-color-area
141
+ color="hsl(100, 50%, 50%)"
142
+ label-X="custom X label"
143
+ label-Y="custom Y label"
144
+ ></sp-color-area>
145
+ `);
146
+ const inputX = el.shadowRoot.querySelector('input[name="x"]');
147
+ const inputY = el.shadowRoot.querySelector('input[name="y"]');
148
+ expect(inputX == null ? void 0 : inputX.getAttribute("aria-label")).to.equal(
149
+ "custom X label Color Picker"
150
+ );
151
+ expect(inputY == null ? void 0 : inputY.getAttribute("aria-label")).to.equal(
152
+ "custom Y label Color Picker"
153
+ );
154
+ });
155
+ it("updates color when x value changes", async () => {
156
+ const el = await fixture(html`
157
+ <sp-color-area></sp-color-area>
158
+ `);
159
+ await el.updateComplete;
160
+ const handle = el.shadowRoot.querySelector(".handle");
161
+ expect(handle.color).to.equal("hsl(0, 100%, 50%)");
162
+ el.x = 0.3;
163
+ await el.updateComplete;
164
+ expect(handle.color).to.equal("hsl(0, 100%, 85%)");
165
+ });
166
+ it("updates color when y value changes", async () => {
167
+ const el = await fixture(html`
168
+ <sp-color-area></sp-color-area>
169
+ `);
170
+ await el.updateComplete;
171
+ const handle = el.shadowRoot.querySelector(".handle");
172
+ expect(handle.color).to.equal("hsl(0, 100%, 50%)");
173
+ el.y = 0.7;
174
+ await el.updateComplete;
175
+ expect(handle.color).to.equal("hsl(0, 100%, 35%)");
176
+ });
177
+ it("accepts `hue` values", async () => {
178
+ const el = await fixture(html`
179
+ <sp-color-area></sp-color-area>
180
+ `);
181
+ await elementUpdated(el);
182
+ const { handle } = el;
183
+ expect(handle.color).to.equal("hsl(0, 100%, 50%)");
184
+ el.hue = 125;
185
+ await elementUpdated(el);
186
+ expect(handle.color).to.equal("hsl(125, 100%, 50%)");
187
+ });
188
+ it('accepts "color" values as hsl', async () => {
189
+ const el = await fixture(html`
190
+ <sp-color-area color="hsl(100, 50%, 50%)"></sp-color-area>
191
+ `);
192
+ await elementUpdated(el);
193
+ expect(el.hue, "hue").to.equal(100);
194
+ expect(el.x, "x").to.equal(0.67);
195
+ expect(el.y, "y").to.equal(0.75);
196
+ });
197
+ it('accepts "color" values as hsla', async () => {
198
+ const el = await fixture(html`
199
+ <sp-color-area color="hsla(100, 50%, 50%, 1)"></sp-color-area>
200
+ `);
201
+ await elementUpdated(el);
202
+ expect(el.hue, "hugh").to.equal(100);
203
+ expect(el.x, "ex").to.equal(0.67);
204
+ expect(el.y, "why").to.equal(0.75);
205
+ el.color = "hsla(120, 100%, 0, 1)";
206
+ await elementUpdated(el);
207
+ expect(el.hue, "hue 2").to.equal(120);
208
+ expect(el.x, "x 2").to.equal(0);
209
+ expect(el.y, "y 2").to.equal(0);
210
+ });
211
+ it('accepts "color" values as rgb', async () => {
212
+ const el = await fixture(html`
213
+ <sp-color-area color="rgb(0,255,0)"></sp-color-area>
214
+ `);
215
+ await elementUpdated(el);
216
+ expect(el.hue).to.equal(120);
217
+ expect(el.x).to.equal(1);
218
+ expect(el.y).to.equal(1);
219
+ });
220
+ it('accepts "color" values as hex', async () => {
221
+ const el = await fixture(html`
222
+ <sp-color-area color="#00ff00"></sp-color-area>
223
+ `);
224
+ await elementUpdated(el);
225
+ expect(el.hue).to.equal(120);
226
+ expect(el.x).to.equal(1);
227
+ expect(el.y).to.equal(1);
228
+ });
229
+ it('accepts "Arrow*" keypresses', async () => {
230
+ const el = await fixture(html`
231
+ <sp-color-area color="hsla(100, 50%, 50%, 1)"></sp-color-area>
232
+ `);
233
+ expect(el.hue, "hue").to.equal(100);
234
+ expect(el.x, "x").to.equal(0.67);
235
+ expect(el.y, "y").to.equal(0.75);
236
+ el.inputX.focus();
237
+ await nextFrame();
238
+ let changeEvent = oneEvent(el, "change");
239
+ await sendKeys({
240
+ press: "ArrowUp"
241
+ });
242
+ await changeEvent;
243
+ changeEvent = oneEvent(el, "change");
244
+ await sendKeys({
245
+ press: "ArrowUp"
246
+ });
247
+ await changeEvent;
248
+ expect(el.x).to.equal(0.67);
249
+ expect(el.y).to.equal(0.77);
250
+ changeEvent = oneEvent(el, "change");
251
+ await sendKeys({
252
+ press: "ArrowRight"
253
+ });
254
+ await changeEvent;
255
+ changeEvent = oneEvent(el, "change");
256
+ await sendKeys({
257
+ press: "ArrowRight"
258
+ });
259
+ await changeEvent;
260
+ expect(el.x).to.equal(0.69);
261
+ expect(el.y).to.equal(0.77);
262
+ changeEvent = oneEvent(el, "change");
263
+ await sendKeys({
264
+ press: "ArrowDown"
265
+ });
266
+ await changeEvent;
267
+ changeEvent = oneEvent(el, "change");
268
+ await sendKeys({
269
+ press: "ArrowDown"
270
+ });
271
+ await changeEvent;
272
+ expect(el.x).to.equal(0.69);
273
+ expect(el.y).to.equal(0.75);
274
+ changeEvent = oneEvent(el, "change");
275
+ await sendKeys({
276
+ press: "ArrowLeft"
277
+ });
278
+ await changeEvent;
279
+ changeEvent = oneEvent(el, "change");
280
+ await sendKeys({
281
+ press: "ArrowLeft"
282
+ });
283
+ await changeEvent;
284
+ expect(el.x).to.equal(0.67);
285
+ expect(el.y).to.equal(0.75);
286
+ el.setAttribute("dir", "rtl");
287
+ changeEvent = oneEvent(el, "change");
288
+ await sendKeys({
289
+ press: "ArrowLeft"
290
+ });
291
+ await changeEvent;
292
+ changeEvent = oneEvent(el, "change");
293
+ await sendKeys({
294
+ press: "ArrowLeft"
295
+ });
296
+ await changeEvent;
297
+ expect(el.x).to.equal(0.69);
298
+ expect(el.y).to.equal(0.75);
299
+ changeEvent = oneEvent(el, "change");
300
+ await sendKeys({
301
+ press: "ArrowRight"
302
+ });
303
+ await changeEvent;
304
+ changeEvent = oneEvent(el, "change");
305
+ await sendKeys({
306
+ press: "ArrowRight"
307
+ });
308
+ await changeEvent;
309
+ expect(el.x).to.equal(0.67);
310
+ expect(el.y).to.equal(0.75);
311
+ await sendKeys({
312
+ press: "Home"
313
+ });
314
+ await changeEvent;
315
+ expect(el.x).to.equal(0.77);
316
+ expect(el.y).to.equal(0.75);
317
+ await sendKeys({
318
+ press: "End"
319
+ });
320
+ await changeEvent;
321
+ expect(el.x).to.equal(0.67);
322
+ expect(el.y).to.equal(0.75);
323
+ el.dir = "ltr";
324
+ await sendKeys({
325
+ press: "Home"
326
+ });
327
+ await changeEvent;
328
+ expect(el.x).to.equal(0.57);
329
+ expect(el.y).to.equal(0.75);
330
+ await sendKeys({
331
+ press: "End"
332
+ });
333
+ await changeEvent;
334
+ expect(el.x).to.equal(0.67);
335
+ expect(el.y).to.equal(0.75);
336
+ });
337
+ it('accepts "Arrow*" keypresses with alteration', async () => {
338
+ const el = await fixture(html`
339
+ <sp-color-area color="hsla(100, 50%, 50%, 1)"></sp-color-area>
340
+ `);
341
+ await elementUpdated(el);
342
+ el.focus();
343
+ expect(el.hue, "hue").to.equal(100);
344
+ expect(el.x, "x").to.equal(0.67);
345
+ expect(el.y, "y").to.equal(0.75);
346
+ await sendKeys({
347
+ down: "Shift"
348
+ });
349
+ await elementUpdated(el);
350
+ await sendKeys({
351
+ press: "ArrowUp"
352
+ });
353
+ await elementUpdated(el);
354
+ await sendKeys({
355
+ press: "ArrowUp"
356
+ });
357
+ await elementUpdated(el);
358
+ expect(el.color).to.equal("hsl(100, 65%, 57%)");
359
+ expect(el.x, "first").to.equal(0.67);
360
+ expect(el.y).to.equal(0.85);
361
+ await sendKeys({
362
+ press: "ArrowRight"
363
+ });
364
+ await elementUpdated(el);
365
+ await sendKeys({
366
+ press: "ArrowRight"
367
+ });
368
+ await elementUpdated(el);
369
+ expect(el.color).to.equal("hsl(100, 66%, 56%)");
370
+ expect(el.x).to.equal(0.69);
371
+ expect(el.y).to.equal(0.85);
372
+ await sendKeys({
373
+ press: "ArrowDown"
374
+ });
375
+ await elementUpdated(el);
376
+ await sendKeys({
377
+ press: "ArrowDown"
378
+ });
379
+ await elementUpdated(el);
380
+ expect(el.color).to.equal("hsl(100, 53%, 49%)");
381
+ expect(el.x).to.equal(0.69);
382
+ expect(el.y).to.equal(0.75);
383
+ await sendKeys({
384
+ press: "ArrowLeft"
385
+ });
386
+ await elementUpdated(el);
387
+ await sendKeys({
388
+ press: "ArrowLeft"
389
+ });
390
+ await elementUpdated(el);
391
+ await sendKeys({
392
+ up: "Shift"
393
+ });
394
+ await elementUpdated(el);
395
+ expect(el.color).to.equal("hsl(100, 50%, 50%)");
396
+ expect(el.x, "last").to.equal(0.67);
397
+ expect(el.y).to.equal(0.75);
398
+ });
399
+ it("accepts pointer events", async () => {
400
+ const el = await fixture(html`
401
+ <sp-color-area
402
+ style="--mod-colorarea-height: 192px; --mod-colorarea-width: 192px;"
403
+ ></sp-color-area>
404
+ `);
405
+ await elementUpdated(el);
406
+ await elementUpdated(el);
407
+ const { handle } = el;
408
+ handle.setPointerCapture = () => {
409
+ return;
410
+ };
411
+ handle.releasePointerCapture = () => {
412
+ return;
413
+ };
414
+ expect(el.hue).to.equal(0);
415
+ expect(el.x).to.equal(1);
416
+ expect(el.y).to.equal(1);
417
+ handle.dispatchEvent(
418
+ new PointerEvent("pointerdown", {
419
+ button: 1,
420
+ pointerId: 1,
421
+ clientX: 100,
422
+ clientY: 100,
423
+ bubbles: true,
424
+ composed: true,
425
+ cancelable: true
426
+ })
427
+ );
428
+ await elementUpdated(el);
429
+ expect(el.hue).to.equal(0);
430
+ expect(el.x).to.equal(1);
431
+ expect(el.y).to.equal(1);
432
+ const root = el.shadowRoot ? el.shadowRoot : el;
433
+ const gradient = root.querySelector(".gradient");
434
+ gradient.dispatchEvent(
435
+ new PointerEvent("pointerdown", {
436
+ button: 1,
437
+ pointerId: 1,
438
+ clientX: 100,
439
+ clientY: 100,
440
+ bubbles: true,
441
+ composed: true,
442
+ cancelable: true
443
+ })
444
+ );
445
+ await elementUpdated(el);
446
+ expect(el.hue).to.equal(0);
447
+ expect(el.x).to.equal(1);
448
+ expect(el.y).to.equal(1);
449
+ gradient.dispatchEvent(
450
+ new PointerEvent("pointerdown", {
451
+ pointerId: 1,
452
+ clientX: 100,
453
+ clientY: 100,
454
+ bubbles: true,
455
+ composed: true,
456
+ cancelable: true
457
+ })
458
+ );
459
+ await elementUpdated(el);
460
+ expect(el.hue).to.equal(0);
461
+ expect(el.x, "pointerdown x").to.equal(0.48);
462
+ expect(el.y, "pointerdown y").to.equal(0.52);
463
+ handle.dispatchEvent(
464
+ new PointerEvent("pointermove", {
465
+ pointerId: 1,
466
+ clientX: 110,
467
+ clientY: 110,
468
+ bubbles: true,
469
+ composed: true,
470
+ cancelable: true
471
+ })
472
+ );
473
+ handle.dispatchEvent(
474
+ new PointerEvent("pointerup", {
475
+ pointerId: 1,
476
+ clientX: 110,
477
+ clientY: 110,
478
+ bubbles: true,
479
+ composed: true,
480
+ cancelable: true
481
+ })
482
+ );
483
+ await elementUpdated(el);
484
+ expect(el.hue).to.equal(0);
485
+ expect(el.x).to.equal(0.53);
486
+ expect(el.y).to.equal(0.47);
487
+ });
488
+ it("responds to events on the internal input element", async () => {
489
+ const inputSpy = spy();
490
+ const changeSpy = spy();
491
+ const el = await fixture(html`
492
+ <sp-color-area
493
+ color="hsla(100, 50%, 50%, 1)"
494
+ @change=${() => changeSpy()}
495
+ @input=${() => inputSpy()}
496
+ ></sp-color-area>
497
+ `);
498
+ await elementUpdated(el);
499
+ el.inputX.focus();
500
+ el.inputX.dispatchEvent(
501
+ new Event("input", {
502
+ bubbles: true,
503
+ composed: true
504
+ })
505
+ );
506
+ el.inputX.dispatchEvent(
507
+ new Event("change", {
508
+ bubbles: true,
509
+ composed: false
510
+ // native change events do not compose themselves by default
511
+ })
512
+ );
513
+ expect(inputSpy.callCount).to.equal(1);
514
+ expect(changeSpy.callCount).to.equal(1);
515
+ el.inputY.focus();
516
+ el.inputY.dispatchEvent(
517
+ new Event("input", {
518
+ bubbles: true,
519
+ composed: true
520
+ })
521
+ );
522
+ el.inputY.dispatchEvent(
523
+ new Event("change", {
524
+ bubbles: true,
525
+ composed: false
526
+ // native change events do not compose themselves by default
527
+ })
528
+ );
529
+ expect(inputSpy.callCount).to.equal(2);
530
+ expect(changeSpy.callCount).to.equal(2);
531
+ });
532
+ it('dispatches input and change events in response to "Arrow*" keypresses', async () => {
533
+ const inputSpy = spy();
534
+ const changeSpy = spy();
535
+ const el = await fixture(html`
536
+ <sp-color-area
537
+ color="hsla(100, 50%, 50%, 1)"
538
+ @change=${() => changeSpy()}
539
+ @input=${() => inputSpy()}
540
+ ></sp-color-area>
541
+ `);
542
+ await elementUpdated(el);
543
+ const Xvalue = Number(Number(el.inputX.value).toFixed(2));
544
+ const Yvalue = Number(Number(el.inputY.value).toFixed(2));
545
+ el.inputX.focus();
546
+ inputSpy.resetHistory();
547
+ changeSpy.resetHistory();
548
+ await sendKeys({ press: "ArrowRight" });
549
+ await sendKeys({ press: "ArrowRight" });
550
+ await elementUpdated(el);
551
+ expect(inputSpy.callCount).to.equal(2);
552
+ expect(changeSpy.callCount).to.equal(2);
553
+ expect(parseFloat(el.inputX.value).toFixed(2)).to.equal(
554
+ (Xvalue + 0.02).toFixed(2)
555
+ );
556
+ el.inputY.focus();
557
+ inputSpy.resetHistory();
558
+ changeSpy.resetHistory();
559
+ await sendKeys({ press: "ArrowUp" });
560
+ await sendKeys({ press: "ArrowUp" });
561
+ await elementUpdated(el);
562
+ expect(inputSpy.callCount).to.equal(2);
563
+ expect(changeSpy.callCount).to.equal(2);
564
+ expect(parseFloat(el.inputY.value).toFixed(2)).to.equal(
565
+ (Yvalue + 0.02).toFixed(2)
566
+ );
567
+ el.inputY.focus();
568
+ inputSpy.resetHistory();
569
+ changeSpy.resetHistory();
570
+ await sendKeys({ press: "ArrowDown" });
571
+ await sendKeys({ press: "ArrowDown" });
572
+ await elementUpdated(el);
573
+ expect(inputSpy.callCount).to.equal(2);
574
+ expect(changeSpy.callCount).to.equal(2);
575
+ expect(parseFloat(el.inputY.value).toFixed(2)).to.equal(
576
+ Yvalue.toFixed(2)
577
+ );
578
+ el.inputX.focus();
579
+ inputSpy.resetHistory();
580
+ changeSpy.resetHistory();
581
+ await sendKeys({ press: "ArrowLeft" });
582
+ await sendKeys({ press: "ArrowLeft" });
583
+ await elementUpdated(el);
584
+ expect(inputSpy.callCount).to.equal(2);
585
+ expect(changeSpy.callCount).to.equal(2);
586
+ expect(parseFloat(el.inputX.value).toFixed(2)).to.equal(
587
+ Xvalue.toFixed(2)
588
+ );
589
+ el.inputX.focus();
590
+ inputSpy.resetHistory();
591
+ changeSpy.resetHistory();
592
+ await sendKeys({ press: "End" });
593
+ await sendKeys({ press: "End" });
594
+ await elementUpdated(el);
595
+ expect(inputSpy.callCount).to.equal(2);
596
+ expect(changeSpy.callCount).to.equal(2);
597
+ expect(parseFloat(el.inputX.value).toFixed(2)).to.equal(
598
+ (Xvalue + 0.2).toFixed(2)
599
+ );
600
+ el.inputX.focus();
601
+ inputSpy.resetHistory();
602
+ changeSpy.resetHistory();
603
+ await sendKeys({ press: "Home" });
604
+ await sendKeys({ press: "Home" });
605
+ await elementUpdated(el);
606
+ expect(inputSpy.callCount).to.equal(2);
607
+ expect(changeSpy.callCount).to.equal(2);
608
+ expect(parseFloat(el.inputX.value).toFixed(2)).to.equal(
609
+ Xvalue.toFixed(2)
610
+ );
611
+ el.inputY.focus();
612
+ inputSpy.resetHistory();
613
+ changeSpy.resetHistory();
614
+ await sendKeys({ press: "PageUp" });
615
+ await sendKeys({ press: "PageUp" });
616
+ await elementUpdated(el);
617
+ expect(inputSpy.callCount).to.equal(2);
618
+ expect(changeSpy.callCount).to.equal(2);
619
+ expect(parseFloat(el.inputY.value).toFixed(2)).to.equal(
620
+ (Yvalue + 0.2).toFixed(2)
621
+ );
622
+ el.inputY.focus();
623
+ inputSpy.resetHistory();
624
+ changeSpy.resetHistory();
625
+ await sendKeys({ press: "PageDown" });
626
+ await sendKeys({ press: "PageDown" });
627
+ await elementUpdated(el);
628
+ expect(inputSpy.callCount).to.equal(2);
629
+ expect(changeSpy.callCount).to.equal(2);
630
+ expect(parseFloat(el.inputY.value).toFixed(2)).to.equal(
631
+ Yvalue.toFixed(2)
632
+ );
633
+ });
634
+ it("retains `hue` value when s = 0 in HSL string format", async () => {
635
+ const el = await fixture(html`
636
+ <sp-color-area color="hsl(100, 50%, 50%)"></sp-color-area>
637
+ `);
638
+ await elementUpdated(el);
639
+ expect(el.hue, "hue").to.equal(100);
640
+ expect(el.x, "x").to.equal(0.67);
641
+ expect(el.y, "y").to.equal(0.75);
642
+ expect(el.color).to.equal("hsl(100, 50%, 50%)");
643
+ el.color = "hsl(100, 0%, 50%)";
644
+ await elementUpdated(el);
645
+ expect(el.hue, "new hue").to.equal(100);
646
+ expect(el.x, "new x").to.equal(0);
647
+ expect(el.y, "new y").to.equal(0.5);
648
+ expect(el.color).to.equal("hsl(100, 0%, 50%)");
649
+ });
650
+ it("retains `hue` value when s = 0 in HSL object format", async () => {
651
+ let inputColor = { h: 100, s: 0.5, l: 0.5 };
652
+ const el = await fixture(html`
653
+ <sp-color-area .color=${inputColor}></sp-color-area>
654
+ `);
655
+ await elementUpdated(el);
656
+ let outputColor = el.color;
657
+ const variance = 5e-5;
658
+ expect(el.hue).to.equal(100);
659
+ expect(el.x, "x").to.equal(0.67);
660
+ expect(el.y, "y").to.equal(0.75);
661
+ expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
662
+ expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
663
+ expect(Math.abs(outputColor.l - inputColor.l)).to.be.lessThan(variance);
664
+ inputColor = { h: 100, s: 0, l: 0.5 };
665
+ el.color = inputColor;
666
+ await elementUpdated(el);
667
+ outputColor = el.color;
668
+ expect(el.hue).to.equal(100);
669
+ expect(el.x, "x").to.equal(0);
670
+ expect(el.y, "y").to.equal(0.5);
671
+ expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
672
+ expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
673
+ expect(Math.abs(outputColor.l - inputColor.l)).to.be.lessThan(variance);
674
+ });
675
+ it("retains `hue` value when s = 0 in HSV string format", async () => {
676
+ const el = await fixture(html`
677
+ <sp-color-area color="hsv(100, 50%, 50%)"></sp-color-area>
678
+ `);
679
+ await elementUpdated(el);
680
+ expect(el.hue, "hue").to.equal(100);
681
+ expect(el.x, "x").to.equal(0.5);
682
+ expect(el.y, "y").to.equal(0.5);
683
+ expect(el.color).to.equal("hsv(100, 50%, 50%)");
684
+ el.color = "hsv(100, 0%, 50%)";
685
+ await elementUpdated(el);
686
+ expect(el.hue, "new hue").to.equal(100);
687
+ expect(el.x, "new x").to.equal(0);
688
+ expect(el.y, "new y").to.equal(0.5);
689
+ expect(el.color).to.equal("hsv(100, 0%, 50%)");
690
+ });
691
+ it("retains `hue` value when s = 0 in HSV object format", async () => {
692
+ let inputColor = { h: 100, s: 0.5, v: 0.5 };
693
+ const el = await fixture(html`
694
+ <sp-color-area .color=${inputColor}></sp-color-area>
695
+ `);
696
+ await elementUpdated(el);
697
+ let outputColor = el.color;
698
+ const variance = 5e-5;
699
+ expect(el.hue).to.equal(100);
700
+ expect(el.x, "x").to.equal(0.5);
701
+ expect(el.y, "y").to.equal(0.5);
702
+ expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
703
+ expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
704
+ expect(Math.abs(outputColor.v - inputColor.v)).to.be.lessThan(variance);
705
+ inputColor = { h: 100, s: 0, v: 0.5 };
706
+ el.color = inputColor;
707
+ await elementUpdated(el);
708
+ outputColor = el.color;
709
+ expect(el.hue).to.equal(100);
710
+ expect(el.x, "x").to.equal(0);
711
+ expect(el.y, "y").to.equal(0.5);
712
+ expect(Math.abs(outputColor.h - inputColor.h)).to.be.lessThan(variance);
713
+ expect(Math.abs(outputColor.s - inputColor.s)).to.be.lessThan(variance);
714
+ expect(Math.abs(outputColor.v - inputColor.v)).to.be.lessThan(variance);
715
+ });
716
+ const colorFormats = [
717
+ //rgb
718
+ { name: "RGB String", color: "rgb(204, 51, 204)" },
719
+ { name: "RGB", color: { r: 204, g: 51, b: 204, a: 1 } },
720
+ //prgb
721
+ { name: "PRGB String", color: "rgb(80%, 20%, 80%)" },
722
+ { name: "PRGB", color: { r: "80%", g: "20%", b: "80%", a: 1 } },
723
+ // hex
724
+ { name: "Hex", color: "cc33cc" },
725
+ { name: "Hex String", color: "#cc33cc" },
726
+ // hex8
727
+ { name: "Hex8", color: "cc33ccff" },
728
+ { name: "Hex8 String", color: "#cc33ccff" },
729
+ // name
730
+ { name: "string", color: "red" },
731
+ // hsl
732
+ { name: "HSL String", color: "hsl(300, 60%, 50%)" },
733
+ { name: "HSL", color: { h: 300, s: 0.6000000000000001, l: 0.5, a: 1 } },
734
+ // hsv
735
+ { name: "HSV String", color: "hsv(300, 75%, 100%)" },
736
+ { name: "HSV", color: { h: 300, s: 0.75, v: 1, a: 1 } }
737
+ ];
738
+ colorFormats.map((format) => {
739
+ it(`maintains \`color\` format as ${format.name}`, async () => {
740
+ const el = await fixture(html`
741
+ <sp-color-area></sp-color-area>
742
+ `);
743
+ el.color = format.color;
744
+ if (format.name.startsWith("Hex")) {
745
+ expect(el.color).to.equal(format.color);
746
+ } else expect(el.color).to.deep.equal(format.color);
747
+ });
748
+ });
749
+ it(`maintains \`color\` format as TinyColor`, async () => {
750
+ const el = await fixture(html`
751
+ <sp-color-area></sp-color-area>
752
+ `);
753
+ const color = new TinyColor("rgb(204, 51, 204)");
754
+ el.color = color;
755
+ expect(color.equals(el.color));
756
+ });
757
+ it(`resolves Hex3 format to Hex6 format`, async () => {
758
+ const el = await fixture(html`
759
+ <sp-color-area></sp-color-area>
760
+ `);
761
+ el.color = "0f0";
762
+ expect(el.color).to.equal("00ff00");
763
+ el.color = "#1e0";
764
+ expect(el.color).to.equal("#11ee00");
765
+ });
766
+ it(`resolves Hex4 format to Hex8 format`, async () => {
767
+ const el = await fixture(html`
768
+ <sp-color-area></sp-color-area>
769
+ `);
770
+ el.color = "f3af";
771
+ expect(el.color).to.equal("ff33aaff");
772
+ el.color = "#f3af";
773
+ expect(el.color).to.equal("#ff33aaff");
774
+ });
775
+ });
776
+ //# sourceMappingURL=color-area.test.js.map