@spectrum-web-components/color-wheel 0.3.11 → 0.3.13-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,399 +1,388 @@
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 } from '@open-wc/testing';
13
- import { arrowDownEvent, arrowDownKeyupEvent, arrowLeftEvent, arrowLeftKeyupEvent, arrowRightEvent, arrowRightKeyupEvent, arrowUpEvent, arrowUpKeyupEvent, } from '../../../test/testing-helpers.js';
14
- import '../sp-color-wheel.js';
15
- import { TinyColor } from '@ctrl/tinycolor';
16
- import { sendKeys } from '@web/test-runner-commands';
17
- import { spy } from 'sinon';
18
- describe('ColorWheel', () => {
19
- it('loads default color-wheel accessibly', async () => {
20
- const el = await fixture(html `
1
+ import { elementUpdated, expect, fixture, html } from "@open-wc/testing";
2
+ import {
3
+ arrowDownEvent,
4
+ arrowDownKeyupEvent,
5
+ arrowLeftEvent,
6
+ arrowLeftKeyupEvent,
7
+ arrowRightEvent,
8
+ arrowRightKeyupEvent,
9
+ arrowUpEvent,
10
+ arrowUpKeyupEvent
11
+ } from "../../../test/testing-helpers.js";
12
+ import "@spectrum-web-components/color-wheel/sp-color-wheel.js";
13
+ import { TinyColor } from "@ctrl/tinycolor";
14
+ import { sendKeys } from "@web/test-runner-commands";
15
+ import { spy } from "sinon";
16
+ describe("ColorWheel", () => {
17
+ it("loads default color-wheel accessibly", async () => {
18
+ const el = await fixture(html`
21
19
  <sp-color-wheel></sp-color-wheel>
22
20
  `);
23
- await elementUpdated(el);
24
- await expect(el).to.be.accessible();
25
- });
26
- it('manages a single tab stop', async () => {
27
- const test = await fixture(html `
21
+ await elementUpdated(el);
22
+ await expect(el).to.be.accessible();
23
+ });
24
+ it("manages a single tab stop", async () => {
25
+ const test = await fixture(html`
28
26
  <div>
29
27
  <input type="text" id="test-input-1" />
30
28
  <sp-color-wheel></sp-color-wheel>
31
29
  <input type="text" id="test-input-2" />
32
30
  </div>
33
31
  `);
34
- const el = test.querySelector('sp-color-wheel');
35
- const input1 = test.querySelector('input:nth-of-type(1)');
36
- const input2 = test.querySelector('input:nth-of-type(2)');
37
- await elementUpdated(el);
38
- input1.focus();
39
- expect(document.activeElement).to.equal(input1);
40
- await sendKeys({
41
- press: 'Tab',
42
- });
43
- expect(document.activeElement).to.equal(el);
44
- let value = el.value;
45
- await sendKeys({
46
- press: 'ArrowRight',
47
- });
48
- expect(el.value).to.not.equal(value);
49
- await sendKeys({
50
- press: 'Tab',
51
- });
52
- expect(document.activeElement).to.equal(input2);
53
- await sendKeys({
54
- press: 'Shift+Tab',
55
- });
56
- expect(document.activeElement).to.equal(el);
57
- value = el.value;
58
- await sendKeys({
59
- press: 'ArrowDown',
60
- });
61
- expect(el.value).to.not.equal(value);
62
- await sendKeys({
63
- press: 'Shift+Tab',
64
- });
65
- expect(document.activeElement).to.equal(input1);
32
+ const el = test.querySelector("sp-color-wheel");
33
+ const input1 = test.querySelector("input:nth-of-type(1)");
34
+ const input2 = test.querySelector("input:nth-of-type(2)");
35
+ await elementUpdated(el);
36
+ input1.focus();
37
+ expect(document.activeElement).to.equal(input1);
38
+ await sendKeys({
39
+ press: "Tab"
40
+ });
41
+ expect(document.activeElement).to.equal(el);
42
+ let value = el.value;
43
+ await sendKeys({
44
+ press: "ArrowRight"
45
+ });
46
+ expect(el.value).to.not.equal(value);
47
+ await sendKeys({
48
+ press: "Tab"
49
+ });
50
+ expect(document.activeElement).to.equal(input2);
51
+ await sendKeys({
52
+ press: "Shift+Tab"
53
+ });
54
+ expect(document.activeElement).to.equal(el);
55
+ value = el.value;
56
+ await sendKeys({
57
+ press: "ArrowDown"
58
+ });
59
+ expect(el.value).to.not.equal(value);
60
+ await sendKeys({
61
+ press: "Shift+Tab"
66
62
  });
67
- it('manages [focused]', async () => {
68
- const el = await fixture(html `
63
+ expect(document.activeElement).to.equal(input1);
64
+ });
65
+ it("manages [focused]", async () => {
66
+ const el = await fixture(html`
69
67
  <sp-color-wheel></sp-color-wheel>
70
68
  `);
71
- await elementUpdated(el);
72
- el.dispatchEvent(new FocusEvent('focusin'));
73
- await elementUpdated(el);
74
- expect(el.focused).to.be.true;
75
- el.dispatchEvent(new FocusEvent('focusout'));
76
- await elementUpdated(el);
77
- expect(el.focused).to.be.false;
78
- });
79
- it('dispatches input and change events in response to "Arrow*" keypresses', async () => {
80
- const inputSpy = spy();
81
- const changeSpy = spy();
82
- const el = await fixture(html `
69
+ await elementUpdated(el);
70
+ el.dispatchEvent(new FocusEvent("focusin"));
71
+ await elementUpdated(el);
72
+ expect(el.focused).to.be.true;
73
+ el.dispatchEvent(new FocusEvent("focusout"));
74
+ await elementUpdated(el);
75
+ expect(el.focused).to.be.false;
76
+ });
77
+ it('dispatches input and change events in response to "Arrow*" keypresses', async () => {
78
+ const inputSpy = spy();
79
+ const changeSpy = spy();
80
+ const el = await fixture(html`
83
81
  <sp-color-wheel
84
82
  @change=${() => changeSpy()}
85
83
  @input=${() => inputSpy()}
86
84
  ></sp-color-wheel>
87
85
  `);
88
- await elementUpdated(el);
89
- el.focus();
90
- await sendKeys({ press: 'ArrowRight' });
91
- expect(inputSpy.callCount).to.equal(1);
92
- expect(changeSpy.callCount).to.equal(1);
93
- await sendKeys({ press: 'ArrowLeft' });
94
- expect(inputSpy.callCount).to.equal(2);
95
- expect(changeSpy.callCount).to.equal(2);
96
- await sendKeys({ press: 'ArrowUp' });
97
- expect(inputSpy.callCount).to.equal(3);
98
- expect(changeSpy.callCount).to.equal(3);
99
- await sendKeys({ press: 'ArrowDown' });
100
- expect(inputSpy.callCount).to.equal(4);
101
- expect(changeSpy.callCount).to.equal(4);
102
- });
103
- it('responds to events on the internal input element', async () => {
104
- // screen reader interactions dispatch events as found in the following test
105
- const inputSpy = spy();
106
- const changeSpy = spy();
107
- const el = await fixture(html `
86
+ await elementUpdated(el);
87
+ el.focus();
88
+ await sendKeys({ press: "ArrowRight" });
89
+ expect(inputSpy.callCount).to.equal(1);
90
+ expect(changeSpy.callCount).to.equal(1);
91
+ await sendKeys({ press: "ArrowLeft" });
92
+ expect(inputSpy.callCount).to.equal(2);
93
+ expect(changeSpy.callCount).to.equal(2);
94
+ await sendKeys({ press: "ArrowUp" });
95
+ expect(inputSpy.callCount).to.equal(3);
96
+ expect(changeSpy.callCount).to.equal(3);
97
+ await sendKeys({ press: "ArrowDown" });
98
+ expect(inputSpy.callCount).to.equal(4);
99
+ expect(changeSpy.callCount).to.equal(4);
100
+ });
101
+ it("responds to events on the internal input element", async () => {
102
+ const inputSpy = spy();
103
+ const changeSpy = spy();
104
+ const el = await fixture(html`
108
105
  <sp-color-wheel
109
106
  @change=${() => changeSpy()}
110
107
  @input=${() => inputSpy()}
111
108
  ></sp-color-wheel>
112
109
  `);
113
- await elementUpdated(el);
114
- const input = el.focusElement;
115
- el.focus();
116
- input.dispatchEvent(new Event('input', {
117
- bubbles: true,
118
- composed: true,
119
- }));
120
- input.dispatchEvent(new Event('change', {
121
- bubbles: true,
122
- composed: false, // native change events do not compose themselves by default
123
- }));
124
- expect(inputSpy.callCount).to.equal(1);
125
- expect(changeSpy.callCount).to.equal(1);
126
- });
127
- it('accepts "Arrow*" keypresses', async () => {
128
- const el = await fixture(html `
110
+ await elementUpdated(el);
111
+ const input = el.focusElement;
112
+ el.focus();
113
+ input.dispatchEvent(new Event("input", {
114
+ bubbles: true,
115
+ composed: true
116
+ }));
117
+ input.dispatchEvent(new Event("change", {
118
+ bubbles: true,
119
+ composed: false
120
+ }));
121
+ expect(inputSpy.callCount).to.equal(1);
122
+ expect(changeSpy.callCount).to.equal(1);
123
+ });
124
+ it('accepts "Arrow*" keypresses', async () => {
125
+ const el = await fixture(html`
129
126
  <sp-color-wheel></sp-color-wheel>
130
127
  `);
131
- await elementUpdated(el);
132
- expect(el.value).to.equal(0);
133
- const input = el.focusElement;
134
- input.dispatchEvent(arrowUpEvent());
135
- input.dispatchEvent(arrowUpKeyupEvent());
136
- input.dispatchEvent(arrowUpEvent());
137
- input.dispatchEvent(arrowUpKeyupEvent());
138
- await elementUpdated(el);
139
- expect(el.value).to.equal(2);
140
- input.dispatchEvent(arrowRightEvent());
141
- input.dispatchEvent(arrowRightKeyupEvent());
142
- input.dispatchEvent(arrowRightEvent());
143
- input.dispatchEvent(arrowRightKeyupEvent());
144
- await elementUpdated(el);
145
- expect(el.value).to.equal(4);
146
- input.dispatchEvent(arrowDownEvent());
147
- input.dispatchEvent(arrowDownKeyupEvent());
148
- input.dispatchEvent(arrowDownEvent());
149
- input.dispatchEvent(arrowDownKeyupEvent());
150
- await elementUpdated(el);
151
- expect(el.value).to.equal(2);
152
- input.dispatchEvent(arrowLeftEvent());
153
- input.dispatchEvent(arrowLeftKeyupEvent());
154
- input.dispatchEvent(arrowLeftEvent());
155
- input.dispatchEvent(arrowLeftKeyupEvent());
156
- await elementUpdated(el);
157
- expect(el.value).to.equal(0);
158
- });
159
- it('accepts "Arrow*" keypresses in dir="rtl"', async () => {
160
- const el = await fixture(html `
128
+ await elementUpdated(el);
129
+ expect(el.value).to.equal(0);
130
+ const input = el.focusElement;
131
+ input.dispatchEvent(arrowUpEvent());
132
+ input.dispatchEvent(arrowUpKeyupEvent());
133
+ input.dispatchEvent(arrowUpEvent());
134
+ input.dispatchEvent(arrowUpKeyupEvent());
135
+ await elementUpdated(el);
136
+ expect(el.value).to.equal(2);
137
+ input.dispatchEvent(arrowRightEvent());
138
+ input.dispatchEvent(arrowRightKeyupEvent());
139
+ input.dispatchEvent(arrowRightEvent());
140
+ input.dispatchEvent(arrowRightKeyupEvent());
141
+ await elementUpdated(el);
142
+ expect(el.value).to.equal(4);
143
+ input.dispatchEvent(arrowDownEvent());
144
+ input.dispatchEvent(arrowDownKeyupEvent());
145
+ input.dispatchEvent(arrowDownEvent());
146
+ input.dispatchEvent(arrowDownKeyupEvent());
147
+ await elementUpdated(el);
148
+ expect(el.value).to.equal(2);
149
+ input.dispatchEvent(arrowLeftEvent());
150
+ input.dispatchEvent(arrowLeftKeyupEvent());
151
+ input.dispatchEvent(arrowLeftEvent());
152
+ input.dispatchEvent(arrowLeftKeyupEvent());
153
+ await elementUpdated(el);
154
+ expect(el.value).to.equal(0);
155
+ });
156
+ it('accepts "Arrow*" keypresses in dir="rtl"', async () => {
157
+ const el = await fixture(html`
161
158
  <sp-color-wheel dir="rtl"></sp-color-wheel>
162
159
  `);
163
- await elementUpdated(el);
164
- expect(el.value).to.equal(0);
165
- const input = el.focusElement;
166
- input.dispatchEvent(arrowUpEvent());
167
- input.dispatchEvent(arrowUpKeyupEvent());
168
- input.dispatchEvent(arrowUpEvent());
169
- input.dispatchEvent(arrowUpKeyupEvent());
170
- await elementUpdated(el);
171
- expect(el.value).to.equal(2);
172
- input.dispatchEvent(arrowRightEvent());
173
- input.dispatchEvent(arrowRightKeyupEvent());
174
- input.dispatchEvent(arrowRightEvent());
175
- input.dispatchEvent(arrowRightKeyupEvent());
176
- await elementUpdated(el);
177
- expect(el.value).to.equal(0);
178
- input.dispatchEvent(arrowLeftEvent());
179
- input.dispatchEvent(arrowLeftKeyupEvent());
180
- input.dispatchEvent(arrowLeftEvent());
181
- input.dispatchEvent(arrowLeftKeyupEvent());
182
- await elementUpdated(el);
183
- expect(el.value).to.equal(2);
184
- input.dispatchEvent(arrowDownEvent());
185
- input.dispatchEvent(arrowDownKeyupEvent());
186
- input.dispatchEvent(arrowDownEvent());
187
- input.dispatchEvent(arrowDownKeyupEvent());
188
- await elementUpdated(el);
189
- expect(el.value).to.equal(0);
190
- });
191
- it('accepts "Arrow*" keypresses with alteration', async () => {
192
- const el = await fixture(html `
160
+ await elementUpdated(el);
161
+ expect(el.value).to.equal(0);
162
+ const input = el.focusElement;
163
+ input.dispatchEvent(arrowUpEvent());
164
+ input.dispatchEvent(arrowUpKeyupEvent());
165
+ input.dispatchEvent(arrowUpEvent());
166
+ input.dispatchEvent(arrowUpKeyupEvent());
167
+ await elementUpdated(el);
168
+ expect(el.value).to.equal(2);
169
+ input.dispatchEvent(arrowRightEvent());
170
+ input.dispatchEvent(arrowRightKeyupEvent());
171
+ input.dispatchEvent(arrowRightEvent());
172
+ input.dispatchEvent(arrowRightKeyupEvent());
173
+ await elementUpdated(el);
174
+ expect(el.value).to.equal(0);
175
+ input.dispatchEvent(arrowLeftEvent());
176
+ input.dispatchEvent(arrowLeftKeyupEvent());
177
+ input.dispatchEvent(arrowLeftEvent());
178
+ input.dispatchEvent(arrowLeftKeyupEvent());
179
+ await elementUpdated(el);
180
+ expect(el.value).to.equal(2);
181
+ input.dispatchEvent(arrowDownEvent());
182
+ input.dispatchEvent(arrowDownKeyupEvent());
183
+ input.dispatchEvent(arrowDownEvent());
184
+ input.dispatchEvent(arrowDownKeyupEvent());
185
+ await elementUpdated(el);
186
+ expect(el.value).to.equal(0);
187
+ });
188
+ it('accepts "Arrow*" keypresses with alteration', async () => {
189
+ const el = await fixture(html`
193
190
  <sp-color-wheel></sp-color-wheel>
194
191
  `);
195
- await elementUpdated(el);
196
- el.focus();
197
- expect(el.value).to.equal(0);
198
- await sendKeys({
199
- down: 'Shift',
200
- });
201
- await sendKeys({
202
- press: 'ArrowUp',
203
- });
204
- await sendKeys({
205
- press: 'ArrowUp',
206
- });
207
- await elementUpdated(el);
208
- expect(el.value).to.equal(20);
209
- await sendKeys({
210
- press: 'ArrowRight',
211
- });
212
- await sendKeys({
213
- press: 'ArrowRight',
214
- });
215
- await elementUpdated(el);
216
- expect(el.value).to.equal(40);
217
- await sendKeys({
218
- press: 'ArrowDown',
219
- });
220
- await sendKeys({
221
- press: 'ArrowDown',
222
- });
223
- await elementUpdated(el);
224
- expect(el.value).to.equal(20);
225
- await sendKeys({
226
- press: 'ArrowLeft',
227
- });
228
- await sendKeys({
229
- press: 'ArrowLeft',
230
- });
231
- await sendKeys({
232
- up: 'Shift',
233
- });
234
- await elementUpdated(el);
235
- expect(el.value).to.equal(0);
192
+ await elementUpdated(el);
193
+ el.focus();
194
+ expect(el.value).to.equal(0);
195
+ await sendKeys({
196
+ down: "Shift"
197
+ });
198
+ await sendKeys({
199
+ press: "ArrowUp"
236
200
  });
237
- it('accepts pointer events', async () => {
238
- const color = new TinyColor({ h: '0', s: '20%', l: '70%' });
239
- const el = await fixture(html `
201
+ await sendKeys({
202
+ press: "ArrowUp"
203
+ });
204
+ await elementUpdated(el);
205
+ expect(el.value).to.equal(20);
206
+ await sendKeys({
207
+ press: "ArrowRight"
208
+ });
209
+ await sendKeys({
210
+ press: "ArrowRight"
211
+ });
212
+ await elementUpdated(el);
213
+ expect(el.value).to.equal(40);
214
+ await sendKeys({
215
+ press: "ArrowDown"
216
+ });
217
+ await sendKeys({
218
+ press: "ArrowDown"
219
+ });
220
+ await elementUpdated(el);
221
+ expect(el.value).to.equal(20);
222
+ await sendKeys({
223
+ press: "ArrowLeft"
224
+ });
225
+ await sendKeys({
226
+ press: "ArrowLeft"
227
+ });
228
+ await sendKeys({
229
+ up: "Shift"
230
+ });
231
+ await elementUpdated(el);
232
+ expect(el.value).to.equal(0);
233
+ });
234
+ it("accepts pointer events", async () => {
235
+ const color = new TinyColor({ h: "0", s: "20%", l: "70%" });
236
+ const el = await fixture(html`
240
237
  <sp-color-wheel
241
238
  .color=${color}
242
239
  style="--spectrum-global-dimension-size-125: 10px;"
243
240
  ></sp-color-wheel>
244
241
  `);
245
- await elementUpdated(el);
246
- const { handle } = el;
247
- handle.setPointerCapture = () => {
248
- return;
249
- };
250
- handle.releasePointerCapture = () => {
251
- return;
252
- };
253
- expect(el.value).to.equal(0);
254
- expect(el.color.s).to.be.within(0.19, 0.21);
255
- expect(el.color.l).to.be.within(0.69, 0.71);
256
- handle.dispatchEvent(new PointerEvent('pointerdown', {
257
- button: 1,
258
- pointerId: 1,
259
- clientX: 80,
260
- clientY: 15,
261
- bubbles: true,
262
- composed: true,
263
- cancelable: true,
264
- }));
265
- await elementUpdated(el);
266
- expect(el.value).to.equal(0);
267
- expect(el.color.s).to.be.within(0.19, 0.21);
268
- expect(el.color.l).to.be.within(0.69, 0.71);
269
- const root = el.shadowRoot ? el.shadowRoot : el;
270
- const gradient = root.querySelector('[name="gradient"]');
271
- gradient.dispatchEvent(new PointerEvent('pointerdown', {
272
- button: 1,
273
- pointerId: 1,
274
- clientX: 80,
275
- clientY: 15,
276
- bubbles: true,
277
- composed: true,
278
- cancelable: true,
279
- }));
280
- await elementUpdated(el);
281
- expect(el.value).to.equal(0);
282
- expect(el.color.s).to.be.within(0.19, 0.21);
283
- expect(el.color.l).to.be.within(0.69, 0.71);
284
- gradient.dispatchEvent(new PointerEvent('pointerdown', {
285
- pointerId: 1,
286
- clientX: 80,
287
- clientY: 15,
288
- bubbles: true,
289
- composed: true,
290
- cancelable: true,
291
- }));
292
- await elementUpdated(el);
293
- expect(el.value).to.equal(263.74596725608353);
294
- expect(el.color.s).to.be.within(0.19, 0.21);
295
- expect(el.color.l).to.be.within(0.69, 0.71);
296
- handle.dispatchEvent(new PointerEvent('pointermove', {
297
- pointerId: 1,
298
- clientX: 80,
299
- clientY: 160,
300
- bubbles: true,
301
- composed: true,
302
- cancelable: true,
303
- }));
304
- handle.dispatchEvent(new PointerEvent('pointerup', {
305
- pointerId: 1,
306
- clientX: 80,
307
- clientY: 160,
308
- bubbles: true,
309
- composed: true,
310
- cancelable: true,
311
- }));
312
- await elementUpdated(el);
313
- expect(el.value).to.equal(96.34019174590992);
314
- expect(el.color.s).to.be.within(0.19, 0.21);
315
- expect(el.color.l).to.be.within(0.69, 0.71);
316
- });
317
- const colorFormats = [
318
- //rgb
319
- { name: 'RGB String', color: 'rgb(204, 51, 204)' },
320
- { name: 'RGB', color: { r: 204, g: 51, b: 204, a: 1 } },
321
- //prgb
322
- { name: 'PRGB String', color: 'rgb(80%, 20%, 80%)' },
323
- { name: 'PRGB', color: { r: '80%', g: '20%', b: '80%', a: 1 } },
324
- // hex
325
- { name: 'Hex', color: 'cc33cc' },
326
- { name: 'Hex String', color: '#cc33cc' },
327
- // hex8
328
- { name: 'Hex8', color: 'cc33ccff' },
329
- { name: 'Hex8 String', color: '#cc33ccff' },
330
- // name
331
- { name: 'string', color: 'red' },
332
- // hsl
333
- { name: 'HSL String', color: 'hsl(300, 60%, 50%)' },
334
- { name: 'HSL', color: { h: 300, s: 0.6000000000000001, l: 0.5, a: 1 } },
335
- // hsv
336
- { name: 'HSV String', color: 'hsv(300, 75%, 100%)' },
337
- { name: 'HSV', color: { h: 300, s: 0.75, v: 1, a: 1 } },
338
- ];
339
- colorFormats.map((format) => {
340
- it(`maintains \`color\` format as ${format.name}`, async () => {
341
- const el = await fixture(html `
242
+ await elementUpdated(el);
243
+ const { handle } = el;
244
+ handle.setPointerCapture = () => {
245
+ return;
246
+ };
247
+ handle.releasePointerCapture = () => {
248
+ return;
249
+ };
250
+ expect(el.value).to.equal(0);
251
+ expect(el.color.s).to.be.within(0.19, 0.21);
252
+ expect(el.color.l).to.be.within(0.69, 0.71);
253
+ handle.dispatchEvent(new PointerEvent("pointerdown", {
254
+ button: 1,
255
+ pointerId: 1,
256
+ clientX: 80,
257
+ clientY: 15,
258
+ bubbles: true,
259
+ composed: true,
260
+ cancelable: true
261
+ }));
262
+ await elementUpdated(el);
263
+ expect(el.value).to.equal(0);
264
+ expect(el.color.s).to.be.within(0.19, 0.21);
265
+ expect(el.color.l).to.be.within(0.69, 0.71);
266
+ const root = el.shadowRoot ? el.shadowRoot : el;
267
+ const gradient = root.querySelector('[name="gradient"]');
268
+ gradient.dispatchEvent(new PointerEvent("pointerdown", {
269
+ button: 1,
270
+ pointerId: 1,
271
+ clientX: 80,
272
+ clientY: 15,
273
+ bubbles: true,
274
+ composed: true,
275
+ cancelable: true
276
+ }));
277
+ await elementUpdated(el);
278
+ expect(el.value).to.equal(0);
279
+ expect(el.color.s).to.be.within(0.19, 0.21);
280
+ expect(el.color.l).to.be.within(0.69, 0.71);
281
+ gradient.dispatchEvent(new PointerEvent("pointerdown", {
282
+ pointerId: 1,
283
+ clientX: 80,
284
+ clientY: 15,
285
+ bubbles: true,
286
+ composed: true,
287
+ cancelable: true
288
+ }));
289
+ await elementUpdated(el);
290
+ expect(el.value).to.equal(263.74596725608353);
291
+ expect(el.color.s).to.be.within(0.19, 0.21);
292
+ expect(el.color.l).to.be.within(0.69, 0.71);
293
+ handle.dispatchEvent(new PointerEvent("pointermove", {
294
+ pointerId: 1,
295
+ clientX: 80,
296
+ clientY: 160,
297
+ bubbles: true,
298
+ composed: true,
299
+ cancelable: true
300
+ }));
301
+ handle.dispatchEvent(new PointerEvent("pointerup", {
302
+ pointerId: 1,
303
+ clientX: 80,
304
+ clientY: 160,
305
+ bubbles: true,
306
+ composed: true,
307
+ cancelable: true
308
+ }));
309
+ await elementUpdated(el);
310
+ expect(el.value).to.equal(96.34019174590992);
311
+ expect(el.color.s).to.be.within(0.19, 0.21);
312
+ expect(el.color.l).to.be.within(0.69, 0.71);
313
+ });
314
+ const colorFormats = [
315
+ { name: "RGB String", color: "rgb(204, 51, 204)" },
316
+ { name: "RGB", color: { r: 204, g: 51, b: 204, a: 1 } },
317
+ { name: "PRGB String", color: "rgb(80%, 20%, 80%)" },
318
+ { name: "PRGB", color: { r: "80%", g: "20%", b: "80%", a: 1 } },
319
+ { name: "Hex", color: "cc33cc" },
320
+ { name: "Hex String", color: "#cc33cc" },
321
+ { name: "Hex8", color: "cc33ccff" },
322
+ { name: "Hex8 String", color: "#cc33ccff" },
323
+ { name: "string", color: "red" },
324
+ { name: "HSL String", color: "hsl(300, 60%, 50%)" },
325
+ { name: "HSL", color: { h: 300, s: 0.6000000000000001, l: 0.5, a: 1 } },
326
+ { name: "HSV String", color: "hsv(300, 75%, 100%)" },
327
+ { name: "HSV", color: { h: 300, s: 0.75, v: 1, a: 1 } }
328
+ ];
329
+ colorFormats.map((format) => {
330
+ it(`maintains \`color\` format as ${format.name}`, async () => {
331
+ const el = await fixture(html`
342
332
  <sp-color-wheel></sp-color-wheel>
343
333
  `);
344
- el.color = format.color;
345
- if (format.name.startsWith('Hex')) {
346
- expect(el.color).to.equal(format.color);
347
- }
348
- else
349
- expect(el.color).to.deep.equal(format.color);
350
- });
334
+ el.color = format.color;
335
+ if (format.name.startsWith("Hex")) {
336
+ expect(el.color).to.equal(format.color);
337
+ } else
338
+ expect(el.color).to.deep.equal(format.color);
351
339
  });
352
- it(`maintains \`color\` format as TinyColor`, async () => {
353
- const el = await fixture(html `
340
+ });
341
+ it(`maintains \`color\` format as TinyColor`, async () => {
342
+ const el = await fixture(html`
354
343
  <sp-color-wheel></sp-color-wheel>
355
344
  `);
356
- const color = new TinyColor('rgb(204, 51, 204)');
357
- el.color = color;
358
- expect(color.equals(el.color));
359
- });
360
- it(`maintains hue value`, async () => {
361
- const el = await fixture(html `
345
+ const color = new TinyColor("rgb(204, 51, 204)");
346
+ el.color = color;
347
+ expect(color.equals(el.color));
348
+ });
349
+ it(`maintains hue value`, async () => {
350
+ const el = await fixture(html`
362
351
  <sp-color-wheel></sp-color-wheel>
363
352
  `);
364
- const hue = 300;
365
- const hsl = `hsl(${hue}, 60%, 100%)`;
366
- el.color = hsl;
367
- expect(el.value).to.equal(hue);
368
- expect(el.color).to.equal(hsl);
369
- const hsla = `hsla(${hue}, 60%, 100%, 0.9)`;
370
- el.color = hsla;
371
- expect(el.value).to.equal(hue);
372
- expect(el.color).to.equal(hsla);
373
- const hsv = `hsv(${hue}, 60%, 100%)`;
374
- el.color = hsv;
375
- expect(el.value).to.equal(hue);
376
- expect(el.color).to.equal(hsv);
377
- const hsva = `hsva(${hue}, 60%, 100%, 0.9)`;
378
- el.color = hsva;
379
- expect(el.value).to.equal(hue);
380
- expect(el.color).to.equal(hsva);
381
- const tinyHSV = new TinyColor({ h: hue, s: 60, v: 100 });
382
- el.color = tinyHSV;
383
- expect(el.value).to.equal(hue);
384
- expect(tinyHSV.equals(el.color)).to.be.true;
385
- const tinyHSVA = new TinyColor({ h: hue, s: 60, v: 100, a: 1 });
386
- el.color = tinyHSVA;
387
- expect(el.value).to.equal(hue);
388
- expect(tinyHSVA.equals(el.color)).to.be.true;
389
- const tinyHSL = new TinyColor({ h: hue, s: 60, l: 100 });
390
- el.color = tinyHSL;
391
- expect(el.value).to.equal(hue);
392
- expect(tinyHSL.equals(el.color)).to.be.true;
393
- const tinyHSLA = new TinyColor({ h: hue, s: 60, l: 100, a: 1 });
394
- el.color = tinyHSLA;
395
- expect(el.value).to.equal(hue);
396
- expect(tinyHSLA.equals(el.color)).to.be.true;
397
- });
353
+ const hue = 300;
354
+ const hsl = `hsl(${hue}, 60%, 100%)`;
355
+ el.color = hsl;
356
+ expect(el.value).to.equal(hue);
357
+ expect(el.color).to.equal(hsl);
358
+ const hsla = `hsla(${hue}, 60%, 100%, 0.9)`;
359
+ el.color = hsla;
360
+ expect(el.value).to.equal(hue);
361
+ expect(el.color).to.equal(hsla);
362
+ const hsv = `hsv(${hue}, 60%, 100%)`;
363
+ el.color = hsv;
364
+ expect(el.value).to.equal(hue);
365
+ expect(el.color).to.equal(hsv);
366
+ const hsva = `hsva(${hue}, 60%, 100%, 0.9)`;
367
+ el.color = hsva;
368
+ expect(el.value).to.equal(hue);
369
+ expect(el.color).to.equal(hsva);
370
+ const tinyHSV = new TinyColor({ h: hue, s: 60, v: 100 });
371
+ el.color = tinyHSV;
372
+ expect(el.value).to.equal(hue);
373
+ expect(tinyHSV.equals(el.color)).to.be.true;
374
+ const tinyHSVA = new TinyColor({ h: hue, s: 60, v: 100, a: 1 });
375
+ el.color = tinyHSVA;
376
+ expect(el.value).to.equal(hue);
377
+ expect(tinyHSVA.equals(el.color)).to.be.true;
378
+ const tinyHSL = new TinyColor({ h: hue, s: 60, l: 100 });
379
+ el.color = tinyHSL;
380
+ expect(el.value).to.equal(hue);
381
+ expect(tinyHSL.equals(el.color)).to.be.true;
382
+ const tinyHSLA = new TinyColor({ h: hue, s: 60, l: 100, a: 1 });
383
+ el.color = tinyHSLA;
384
+ expect(el.value).to.equal(hue);
385
+ expect(tinyHSLA.equals(el.color)).to.be.true;
386
+ });
398
387
  });
399
- //# sourceMappingURL=color-wheel.test.js.map
388
+ //# sourceMappingURL=color-wheel.test.js.map