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