@getflip/swirl-components 0.98.1 → 0.100.0

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 (45) hide show
  1. package/components.json +113 -7
  2. package/dist/cjs/index-506fe4ea.js +10 -6
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/swirl-accordion-item.cjs.entry.js +4 -4
  5. package/dist/cjs/swirl-accordion.cjs.entry.js +22 -0
  6. package/dist/cjs/{swirl-app-layout_7.cjs.entry.js → swirl-app-layout_6.cjs.entry.js} +0 -51
  7. package/dist/cjs/swirl-box.cjs.entry.js +58 -0
  8. package/dist/cjs/swirl-color-input.cjs.entry.js +397 -3
  9. package/dist/cjs/swirl-components.cjs.js +1 -1
  10. package/dist/collection/assets/pdfjs/pdf.worker.min.js +0 -22
  11. package/dist/collection/components/swirl-accordion/swirl-accordion.js +82 -1
  12. package/dist/collection/components/swirl-accordion/swirl-accordion.stories.js +4 -4
  13. package/dist/collection/components/swirl-accordion-item/swirl-accordion-item.js +23 -5
  14. package/dist/collection/components/swirl-accordion-item/swirl-accordion-item.spec.js +5 -5
  15. package/dist/collection/components/swirl-color-input/swirl-color-input.css +7 -3
  16. package/dist/collection/components/swirl-color-input/swirl-color-input.js +50 -2
  17. package/dist/collection/components/swirl-color-input/swirl-color-input.spec.js +11 -3
  18. package/dist/components/assets/pdfjs/pdf.worker.min.js +0 -22
  19. package/dist/components/swirl-accordion-item.js +5 -4
  20. package/dist/components/swirl-accordion.js +27 -2
  21. package/dist/components/swirl-color-input.js +420 -6
  22. package/dist/esm/index-99d0060d.js +10 -6
  23. package/dist/esm/loader.js +1 -1
  24. package/dist/esm/swirl-accordion-item.entry.js +4 -4
  25. package/dist/esm/swirl-accordion.entry.js +23 -1
  26. package/dist/esm/{swirl-app-layout_7.entry.js → swirl-app-layout_6.entry.js} +1 -51
  27. package/dist/esm/swirl-box.entry.js +54 -0
  28. package/dist/esm/swirl-color-input.entry.js +397 -3
  29. package/dist/esm/swirl-components.js +1 -1
  30. package/dist/swirl-components/p-11d08dde.entry.js +1 -0
  31. package/dist/swirl-components/p-1a815fd4.entry.js +1 -0
  32. package/dist/swirl-components/p-c6b74656.entry.js +1 -0
  33. package/dist/swirl-components/p-ea056b49.entry.js +1 -0
  34. package/dist/swirl-components/p-f4144d4c.entry.js +1 -0
  35. package/dist/swirl-components/swirl-components.esm.js +1 -1
  36. package/dist/types/components/swirl-accordion/swirl-accordion.d.ts +10 -0
  37. package/dist/types/components/swirl-accordion-item/swirl-accordion-item.d.ts +2 -2
  38. package/dist/types/components/swirl-color-input/swirl-color-input.d.ts +7 -0
  39. package/dist/types/components.d.ts +20 -1
  40. package/package.json +2 -1
  41. package/vscode-data.json +12 -0
  42. package/dist/swirl-components/p-230745da.entry.js +0 -1
  43. package/dist/swirl-components/p-244a747a.entry.js +0 -1
  44. package/dist/swirl-components/p-b1648433.entry.js +0 -1
  45. package/dist/swirl-components/p-e8231bad.entry.js +0 -1
@@ -1,7 +1,391 @@
1
1
  import { r as registerInstance, c as createEvent, h, H as Host } from './index-99d0060d.js';
2
2
  import { c as classnames } from './index-d280dafb.js';
3
+ import { v as v4 } from './v4-fa4bb814.js';
3
4
 
4
- const swirlColorInputCss = ".sc-swirl-color-input-h{display:block;width:100%}.sc-swirl-color-input-h *.sc-swirl-color-input{box-sizing:border-box}.color-input.sc-swirl-color-input{position:relative;display:flex;width:100%;align-items:center;color:var(--s-text-default);font:inherit;line-height:var(--s-line-height-sm);cursor:text}.color-input--inline.sc-swirl-color-input .color-input__preview.sc-swirl-color-input{width:1.5rem;height:1.5rem;margin-top:-0.125rem;margin-bottom:-0.125rem;margin-right:-0.25rem}.color-input__input.sc-swirl-color-input{display:inline-flex;width:100%;margin:0;padding:0;flex-grow:1;border:none;color:var(--s-text-default);background-color:transparent;font:inherit;font-size:var(--s-font-size-base);line-height:var(--s-line-height-base);caret-color:var(--s-border-highlight)}.color-input__input.sc-swirl-color-input:focus{outline:none}.color-input__input.sc-swirl-color-input:disabled{color:var(--s-text-disabled);background-color:transparent}@media (min-width: 992px) and (max-width: 1439px) and (hover: hover),(min-width: 1440px){.color-input__input.sc-swirl-color-input{font-size:var(--s-font-size-sm);line-height:var(--s-line-height-sm)}}.color-input__preview.sc-swirl-color-input{width:2.75rem;height:2.75rem;margin-top:-1.25rem;flex-shrink:0;border:0.0625rem solid var(--s-border-default);border-radius:var(--s-border-radius-s)}";
5
+ // Clamps a value between an upper and lower bound.
6
+ // We use ternary operators because it makes the minified code
7
+ // 2 times shorter then `Math.min(Math.max(a,b),c)`
8
+ const clamp = (number, min = 0, max = 1) => {
9
+ return number > max ? max : number < min ? min : number;
10
+ };
11
+ const round = (number, digits = 0, base = Math.pow(10, digits)) => {
12
+ return Math.round(base * number) / base;
13
+ };
14
+
15
+ const hexToHsva = (hex) => rgbaToHsva(hexToRgba(hex));
16
+ const hexToRgba = (hex) => {
17
+ if (hex[0] === '#')
18
+ hex = hex.substring(1);
19
+ if (hex.length < 6) {
20
+ return {
21
+ r: parseInt(hex[0] + hex[0], 16),
22
+ g: parseInt(hex[1] + hex[1], 16),
23
+ b: parseInt(hex[2] + hex[2], 16),
24
+ a: hex.length === 4 ? round(parseInt(hex[3] + hex[3], 16) / 255, 2) : 1
25
+ };
26
+ }
27
+ return {
28
+ r: parseInt(hex.substring(0, 2), 16),
29
+ g: parseInt(hex.substring(2, 4), 16),
30
+ b: parseInt(hex.substring(4, 6), 16),
31
+ a: hex.length === 8 ? round(parseInt(hex.substring(6, 8), 16) / 255, 2) : 1
32
+ };
33
+ };
34
+ const hsvaToHex = (hsva) => rgbaToHex(hsvaToRgba(hsva));
35
+ const hsvaToHsla = ({ h, s, v, a }) => {
36
+ const hh = ((200 - s) * v) / 100;
37
+ return {
38
+ h: round(h),
39
+ s: round(hh > 0 && hh < 200 ? ((s * v) / 100 / (hh <= 100 ? hh : 200 - hh)) * 100 : 0),
40
+ l: round(hh / 2),
41
+ a: round(a, 2)
42
+ };
43
+ };
44
+ const hsvaToHslString = (hsva) => {
45
+ const { h, s, l } = hsvaToHsla(hsva);
46
+ return `hsl(${h}, ${s}%, ${l}%)`;
47
+ };
48
+ const hsvaToRgba = ({ h, s, v, a }) => {
49
+ h = (h / 360) * 6;
50
+ s = s / 100;
51
+ v = v / 100;
52
+ const hh = Math.floor(h), b = v * (1 - s), c = v * (1 - (h - hh) * s), d = v * (1 - (1 - h + hh) * s), module = hh % 6;
53
+ return {
54
+ r: round([v, c, b, b, d, v][module] * 255),
55
+ g: round([d, v, v, c, b, b][module] * 255),
56
+ b: round([b, b, d, v, v, c][module] * 255),
57
+ a: round(a, 2)
58
+ };
59
+ };
60
+ const format = (number) => {
61
+ const hex = number.toString(16);
62
+ return hex.length < 2 ? '0' + hex : hex;
63
+ };
64
+ const rgbaToHex = ({ r, g, b, a }) => {
65
+ const alphaHex = a < 1 ? format(round(a * 255)) : '';
66
+ return '#' + format(r) + format(g) + format(b) + alphaHex;
67
+ };
68
+ const rgbaToHsva = ({ r, g, b, a }) => {
69
+ const max = Math.max(r, g, b);
70
+ const delta = max - Math.min(r, g, b);
71
+ // prettier-ignore
72
+ const hh = delta
73
+ ? max === r
74
+ ? (g - b) / delta
75
+ : max === g
76
+ ? 2 + (b - r) / delta
77
+ : 4 + (r - g) / delta
78
+ : 0;
79
+ return {
80
+ h: round(60 * (hh < 0 ? hh + 6 : hh)),
81
+ s: round(max ? (delta / max) * 100 : 0),
82
+ v: round((max / 255) * 100),
83
+ a
84
+ };
85
+ };
86
+
87
+ const equalColorObjects = (first, second) => {
88
+ if (first === second)
89
+ return true;
90
+ for (const prop in first) {
91
+ // The following allows for a type-safe calling of this function (first & second have to be HSL, HSV, or RGB)
92
+ // with type-unsafe iterating over object keys. TS does not allow this without an index (`[key: string]: number`)
93
+ // on an object to define how iteration is normally done. To ensure extra keys are not allowed on our types,
94
+ // we must cast our object to unknown (as RGB demands `r` be a key, while `Record<string, x>` does not care if
95
+ // there is or not), and then as a type TS can iterate over.
96
+ if (first[prop] !==
97
+ second[prop])
98
+ return false;
99
+ }
100
+ return true;
101
+ };
102
+ const equalHex = (first, second) => {
103
+ if (first.toLowerCase() === second.toLowerCase())
104
+ return true;
105
+ // To compare colors like `#FFF` and `ffffff` we convert them into RGB objects
106
+ return equalColorObjects(hexToRgba(first), hexToRgba(second));
107
+ };
108
+
109
+ const cache = {};
110
+ const tpl = (html) => {
111
+ let template = cache[html];
112
+ if (!template) {
113
+ template = document.createElement('template');
114
+ template.innerHTML = html;
115
+ cache[html] = template;
116
+ }
117
+ return template;
118
+ };
119
+ const fire = (target, type, detail) => {
120
+ target.dispatchEvent(new CustomEvent(type, {
121
+ bubbles: true,
122
+ detail
123
+ }));
124
+ };
125
+
126
+ let hasTouched = false;
127
+ // Check if an event was triggered by touch
128
+ const isTouch = (e) => 'touches' in e;
129
+ // Prevent mobile browsers from handling mouse events (conflicting with touch ones).
130
+ // If we detected a touch interaction before, we prefer reacting to touch events only.
131
+ const isValid = (event) => {
132
+ if (hasTouched && !isTouch(event))
133
+ return false;
134
+ if (!hasTouched)
135
+ hasTouched = isTouch(event);
136
+ return true;
137
+ };
138
+ const pointerMove = (target, event) => {
139
+ const pointer = isTouch(event) ? event.touches[0] : event;
140
+ const rect = target.el.getBoundingClientRect();
141
+ fire(target.el, 'move', target.getMove({
142
+ x: clamp((pointer.pageX - (rect.left + window.pageXOffset)) / rect.width),
143
+ y: clamp((pointer.pageY - (rect.top + window.pageYOffset)) / rect.height)
144
+ }));
145
+ };
146
+ const keyMove = (target, event) => {
147
+ // We use `keyCode` instead of `key` to reduce the size of the library.
148
+ const keyCode = event.keyCode;
149
+ // Ignore all keys except arrow ones, Page Up, Page Down, Home and End.
150
+ if (keyCode > 40 || (target.xy && keyCode < 37) || keyCode < 33)
151
+ return;
152
+ // Do not scroll page by keys when color picker element has focus.
153
+ event.preventDefault();
154
+ // Send relative offset to the parent component.
155
+ fire(target.el, 'move', target.getMove({
156
+ x: keyCode === 39 // Arrow Right
157
+ ? 0.01
158
+ : keyCode === 37 // Arrow Left
159
+ ? -0.01
160
+ : keyCode === 34 // Page Down
161
+ ? 0.05
162
+ : keyCode === 33 // Page Up
163
+ ? -0.05
164
+ : keyCode === 35 // End
165
+ ? 1
166
+ : keyCode === 36 // Home
167
+ ? -1
168
+ : 0,
169
+ y: keyCode === 40 // Arrow down
170
+ ? 0.01
171
+ : keyCode === 38 // Arrow Up
172
+ ? -0.01
173
+ : 0
174
+ }, true));
175
+ };
176
+ class Slider {
177
+ constructor(root, part, aria, xy) {
178
+ const template = tpl(`<div role="slider" tabindex="0" part="${part}" ${aria}><div part="${part}-pointer"></div></div>`);
179
+ root.appendChild(template.content.cloneNode(true));
180
+ const el = root.querySelector(`[part=${part}]`);
181
+ el.addEventListener('mousedown', this);
182
+ el.addEventListener('touchstart', this);
183
+ el.addEventListener('keydown', this);
184
+ this.el = el;
185
+ this.xy = xy;
186
+ this.nodes = [el.firstChild, el];
187
+ }
188
+ set dragging(state) {
189
+ const toggleEvent = state ? document.addEventListener : document.removeEventListener;
190
+ toggleEvent(hasTouched ? 'touchmove' : 'mousemove', this);
191
+ toggleEvent(hasTouched ? 'touchend' : 'mouseup', this);
192
+ }
193
+ handleEvent(event) {
194
+ switch (event.type) {
195
+ case 'mousedown':
196
+ case 'touchstart':
197
+ event.preventDefault();
198
+ // event.button is 0 in mousedown for left button activation
199
+ if (!isValid(event) || (!hasTouched && event.button != 0))
200
+ return;
201
+ this.el.focus();
202
+ pointerMove(this, event);
203
+ this.dragging = true;
204
+ break;
205
+ case 'mousemove':
206
+ case 'touchmove':
207
+ event.preventDefault();
208
+ pointerMove(this, event);
209
+ break;
210
+ case 'mouseup':
211
+ case 'touchend':
212
+ this.dragging = false;
213
+ break;
214
+ case 'keydown':
215
+ keyMove(this, event);
216
+ break;
217
+ }
218
+ }
219
+ style(styles) {
220
+ styles.forEach((style, i) => {
221
+ for (const p in style) {
222
+ this.nodes[i].style.setProperty(p, style[p]);
223
+ }
224
+ });
225
+ }
226
+ }
227
+
228
+ class Hue extends Slider {
229
+ constructor(root) {
230
+ super(root, 'hue', 'aria-label="Hue" aria-valuemin="0" aria-valuemax="360"', false);
231
+ }
232
+ update({ h }) {
233
+ this.h = h;
234
+ this.style([
235
+ {
236
+ left: `${(h / 360) * 100}%`,
237
+ color: hsvaToHslString({ h, s: 100, v: 100, a: 1 })
238
+ }
239
+ ]);
240
+ this.el.setAttribute('aria-valuenow', `${round(h)}`);
241
+ }
242
+ getMove(offset, key) {
243
+ // Hue measured in degrees of the color circle ranging from 0 to 360
244
+ return { h: key ? clamp(this.h + offset.x * 360, 0, 360) : 360 * offset.x };
245
+ }
246
+ }
247
+
248
+ class Saturation extends Slider {
249
+ constructor(root) {
250
+ super(root, 'saturation', 'aria-label="Color"', true);
251
+ }
252
+ update(hsva) {
253
+ this.hsva = hsva;
254
+ this.style([
255
+ {
256
+ top: `${100 - hsva.v}%`,
257
+ left: `${hsva.s}%`,
258
+ color: hsvaToHslString(hsva)
259
+ },
260
+ {
261
+ 'background-color': hsvaToHslString({ h: hsva.h, s: 100, v: 100, a: 1 })
262
+ }
263
+ ]);
264
+ this.el.setAttribute('aria-valuetext', `Saturation ${round(hsva.s)}%, Brightness ${round(hsva.v)}%`);
265
+ }
266
+ getMove(offset, key) {
267
+ // Saturation and brightness always fit into [0, 100] range
268
+ return {
269
+ s: key ? clamp(this.hsva.s + offset.x * 100, 0, 100) : offset.x * 100,
270
+ v: key ? clamp(this.hsva.v - offset.y * 100, 0, 100) : Math.round(100 - offset.y * 100)
271
+ };
272
+ }
273
+ }
274
+
275
+ const css = `:host{display:flex;flex-direction:column;position:relative;width:200px;height:200px;user-select:none;-webkit-user-select:none;cursor:default}:host([hidden]){display:none!important}[role=slider]{position:relative;touch-action:none;user-select:none;-webkit-user-select:none;outline:0}[role=slider]:last-child{border-radius:0 0 8px 8px}[part$=pointer]{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;display:flex;place-content:center center;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}[part$=pointer]::after{content:"";width:100%;height:100%;border-radius:inherit;background-color:currentColor}[role=slider]:focus [part$=pointer]{transform:translate(-50%,-50%) scale(1.1)}`;
276
+
277
+ const hueCss = `[part=hue]{flex:0 0 24px;background:linear-gradient(to right,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red 100%)}[part=hue-pointer]{top:50%;z-index:2}`;
278
+
279
+ const saturationCss = `[part=saturation]{flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(to top,#000,transparent),linear-gradient(to right,#fff,rgba(255,255,255,0));box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}[part=saturation-pointer]{z-index:3}`;
280
+
281
+ const $isSame = Symbol('same');
282
+ const $color = Symbol('color');
283
+ const $hsva = Symbol('hsva');
284
+ const $update = Symbol('update');
285
+ const $parts = Symbol('parts');
286
+ const $css = Symbol('css');
287
+ const $sliders = Symbol('sliders');
288
+ class ColorPicker extends HTMLElement {
289
+ static get observedAttributes() {
290
+ return ['color'];
291
+ }
292
+ get [$css]() {
293
+ return [css, hueCss, saturationCss];
294
+ }
295
+ get [$sliders]() {
296
+ return [Saturation, Hue];
297
+ }
298
+ get color() {
299
+ return this[$color];
300
+ }
301
+ set color(newColor) {
302
+ if (!this[$isSame](newColor)) {
303
+ const newHsva = this.colorModel.toHsva(newColor);
304
+ this[$update](newHsva);
305
+ this[$color] = newColor;
306
+ }
307
+ }
308
+ constructor() {
309
+ super();
310
+ const template = tpl(`<style>${this[$css].join('')}</style>`);
311
+ const root = this.attachShadow({ mode: 'open' });
312
+ root.appendChild(template.content.cloneNode(true));
313
+ root.addEventListener('move', this);
314
+ this[$parts] = this[$sliders].map((slider) => new slider(root));
315
+ }
316
+ connectedCallback() {
317
+ // A user may set a property on an _instance_ of an element,
318
+ // before its prototype has been connected to this class.
319
+ // If so, we need to run it through the proper class setter.
320
+ if (this.hasOwnProperty('color')) {
321
+ const value = this.color;
322
+ delete this['color'];
323
+ this.color = value;
324
+ }
325
+ else if (!this.color) {
326
+ this.color = this.colorModel.defaultColor;
327
+ }
328
+ }
329
+ attributeChangedCallback(_attr, _oldVal, newVal) {
330
+ const color = this.colorModel.fromAttr(newVal);
331
+ if (!this[$isSame](color)) {
332
+ this.color = color;
333
+ }
334
+ }
335
+ handleEvent(event) {
336
+ // Merge the current HSV color object with updated params.
337
+ const oldHsva = this[$hsva];
338
+ const newHsva = { ...oldHsva, ...event.detail };
339
+ this[$update](newHsva);
340
+ let newColor;
341
+ if (!equalColorObjects(newHsva, oldHsva) &&
342
+ !this[$isSame]((newColor = this.colorModel.fromHsva(newHsva)))) {
343
+ this[$color] = newColor;
344
+ fire(this, 'color-changed', { value: newColor });
345
+ }
346
+ }
347
+ [$isSame](color) {
348
+ return this.color && this.colorModel.equal(color, this.color);
349
+ }
350
+ [$update](hsva) {
351
+ this[$hsva] = hsva;
352
+ this[$parts].forEach((part) => part.update(hsva));
353
+ }
354
+ }
355
+
356
+ const colorModel = {
357
+ defaultColor: '#000',
358
+ toHsva: hexToHsva,
359
+ fromHsva: ({ h, s, v }) => hsvaToHex({ h, s, v, a: 1 }),
360
+ equal: equalHex,
361
+ fromAttr: (color) => color
362
+ };
363
+ class HexBase extends ColorPicker {
364
+ get colorModel() {
365
+ return colorModel;
366
+ }
367
+ }
368
+
369
+ /**
370
+ * A color picker custom element that uses HEX format.
371
+ *
372
+ * @element hex-color-picker
373
+ *
374
+ * @prop {string} color - Selected color in HEX format.
375
+ * @attr {string} color - Selected color in HEX format.
376
+ *
377
+ * @fires color-changed - Event fired when color property changes.
378
+ *
379
+ * @csspart hue - A hue selector container.
380
+ * @csspart saturation - A saturation selector container
381
+ * @csspart hue-pointer - A hue pointer element.
382
+ * @csspart saturation-pointer - A saturation pointer element.
383
+ */
384
+ class HexColorPicker extends HexBase {
385
+ }
386
+ customElements.define('hex-color-picker', HexColorPicker);
387
+
388
+ const swirlColorInputCss = ".sc-swirl-color-input-h{display:block;width:100%}.sc-swirl-color-input-h *.sc-swirl-color-input{box-sizing:border-box}.color-input.sc-swirl-color-input{position:relative;display:flex;width:100%;align-items:center;color:var(--s-text-default);font:inherit;line-height:var(--s-line-height-sm);cursor:text}.color-input--inline.sc-swirl-color-input .color-input__preview-button.sc-swirl-color-input{width:1.5rem;height:1.5rem;margin-top:-0.125rem;margin-right:-0.25rem;margin-bottom:-0.125rem}.color-input__input.sc-swirl-color-input{display:inline-flex;width:100%;margin:0;padding:0;flex-grow:1;border:none;color:var(--s-text-default);background-color:transparent;font:inherit;font-size:var(--s-font-size-base);line-height:var(--s-line-height-base);caret-color:var(--s-border-highlight)}.color-input__input.sc-swirl-color-input:focus{outline:none}.color-input__input.sc-swirl-color-input:disabled{color:var(--s-text-disabled);background-color:transparent}@media (min-width: 992px) and (max-width: 1439px) and (hover: hover),(min-width: 1440px){.color-input__input.sc-swirl-color-input{font-size:var(--s-font-size-sm);line-height:var(--s-line-height-sm)}}.color-input__preview-button.sc-swirl-color-input{width:2.75rem;height:2.75rem;margin-top:-1.25rem;flex-shrink:0;border:0.0625rem solid var(--s-border-default);border-radius:var(--s-border-radius-s);cursor:pointer;-webkit-appearance:none;-moz-appearance:none;appearance:none}";
5
389
 
6
390
  const SwirlColorInput = class {
7
391
  constructor(hostRef) {
@@ -9,6 +393,10 @@ const SwirlColorInput = class {
9
393
  this.inputBlur = createEvent(this, "inputBlur", 7);
10
394
  this.inputFocus = createEvent(this, "inputFocus", 7);
11
395
  this.valueChange = createEvent(this, "valueChange", 7);
396
+ this.pickerId = `color-picker-${v4()}`;
397
+ this.onPickerChange = (event) => {
398
+ this.value = event.detail.value;
399
+ };
12
400
  this.onChange = (event) => {
13
401
  const el = event.target;
14
402
  this.value = el.value;
@@ -29,6 +417,8 @@ const SwirlColorInput = class {
29
417
  this.swirlAriaDescribedby = undefined;
30
418
  this.inline = undefined;
31
419
  this.invalid = undefined;
420
+ this.pickerButtonLabel = "Open color picker";
421
+ this.pickerLabel = "Color picker";
32
422
  this.placeholder = undefined;
33
423
  this.required = undefined;
34
424
  this.value = undefined;
@@ -40,6 +430,10 @@ const SwirlColorInput = class {
40
430
  this.inputEl.focus();
41
431
  });
42
432
  }
433
+ this.picker.addEventListener("color-changed", this.onPickerChange);
434
+ }
435
+ disconnectedCallback() {
436
+ this.picker?.removeEventListener("color-changed", this.onPickerChange);
43
437
  }
44
438
  watchValue(newValue, oldValue) {
45
439
  if (newValue !== oldValue) {
@@ -59,11 +453,11 @@ const SwirlColorInput = class {
59
453
  const className = classnames("color-input", {
60
454
  "color-input--inline": this.inline,
61
455
  });
62
- return (h(Host, null, h("div", { class: className }, h("input", { "aria-describedby": this.swirlAriaDescribedby, "aria-disabled": this.disabled ? "true" : undefined, "aria-invalid": ariaInvalid, autoFocus: this.autoFocus, class: "color-input__input", disabled: this.disabled, maxLength: 9, onBlur: this.onBlur, onFocus: this.onFocus, onInput: this.onInput, placeholder: this.placeholder, ref: (el) => (this.inputEl = el), required: this.required, spellcheck: "false", type: "text", value: this.value }), h("span", { class: "color-input__preview", style: {
456
+ return (h(Host, null, h("div", { class: className }, h("input", { "aria-describedby": this.swirlAriaDescribedby, "aria-disabled": this.disabled ? "true" : undefined, "aria-invalid": ariaInvalid, autoFocus: this.autoFocus, class: "color-input__input", disabled: this.disabled, maxLength: 7, onBlur: this.onBlur, onFocus: this.onFocus, onInput: this.onInput, placeholder: this.placeholder, ref: (el) => (this.inputEl = el), required: this.required, spellcheck: "false", type: "text", value: this.value }), h("swirl-popover-trigger", { popover: this.pickerId }, h("button", { "aria-label": this.pickerButtonLabel, class: "color-input__preview-button", style: {
63
457
  backgroundColor: this.disabled
64
458
  ? "var(--s-border-subdued)"
65
459
  : this.value,
66
- } }))));
460
+ }, type: "button" })), h("swirl-popover", { animation: "scale-in-y", id: this.pickerId, label: this.pickerLabel, placement: "bottom-end" }, h("swirl-box", { centerInline: true, paddingBlockEnd: "8", paddingBlockStart: "8", paddingInlineEnd: "16", paddingInlineStart: "16" }, h("hex-color-picker", { color: this.value, ref: (el) => (this.picker = el) }))))));
67
461
  }
68
462
  static get watchers() { return {
69
463
  "value": ["watchValue"]