@getflip/swirl-components 0.99.0 → 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.
- package/components.json +71 -5
- package/dist/cjs/index-506fe4ea.js +10 -6
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/swirl-accordion.cjs.entry.js +2 -0
- package/dist/cjs/{swirl-app-layout_7.cjs.entry.js → swirl-app-layout_6.cjs.entry.js} +0 -51
- package/dist/cjs/swirl-box.cjs.entry.js +58 -0
- package/dist/cjs/swirl-color-input.cjs.entry.js +397 -3
- package/dist/cjs/swirl-components.cjs.js +1 -1
- package/dist/collection/assets/pdfjs/pdf.worker.min.js +0 -22
- package/dist/collection/components/swirl-accordion/swirl-accordion.js +20 -1
- package/dist/collection/components/swirl-color-input/swirl-color-input.css +7 -3
- package/dist/collection/components/swirl-color-input/swirl-color-input.js +50 -2
- package/dist/collection/components/swirl-color-input/swirl-color-input.spec.js +11 -3
- package/dist/components/assets/pdfjs/pdf.worker.min.js +0 -22
- package/dist/components/swirl-accordion.js +3 -1
- package/dist/components/swirl-color-input.js +420 -6
- package/dist/esm/index-99d0060d.js +10 -6
- package/dist/esm/loader.js +1 -1
- package/dist/esm/swirl-accordion.entry.js +3 -1
- package/dist/esm/{swirl-app-layout_7.entry.js → swirl-app-layout_6.entry.js} +1 -51
- package/dist/esm/swirl-box.entry.js +54 -0
- package/dist/esm/swirl-color-input.entry.js +397 -3
- package/dist/esm/swirl-components.js +1 -1
- package/dist/swirl-components/p-1a815fd4.entry.js +1 -0
- package/dist/swirl-components/p-c6b74656.entry.js +1 -0
- package/dist/swirl-components/p-ea056b49.entry.js +1 -0
- package/dist/swirl-components/p-f4144d4c.entry.js +1 -0
- package/dist/swirl-components/swirl-components.esm.js +1 -1
- package/dist/types/components/swirl-accordion/swirl-accordion.d.ts +2 -0
- package/dist/types/components/swirl-color-input/swirl-color-input.d.ts +7 -0
- package/dist/types/components.d.ts +9 -0
- package/package.json +2 -1
- package/vscode-data.json +8 -0
- package/dist/swirl-components/p-244a747a.entry.js +0 -1
- package/dist/swirl-components/p-84a9e6a2.entry.js +0 -1
- package/dist/swirl-components/p-e8231bad.entry.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
|
|
1
|
+
import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
|
|
2
2
|
|
|
3
3
|
const swirlAccordionCss = ":host{display:block}:host *{box-sizing:border-box}";
|
|
4
4
|
|
|
@@ -7,10 +7,12 @@ const SwirlAccordion$1 = /*@__PURE__*/ proxyCustomElement(class SwirlAccordion e
|
|
|
7
7
|
super();
|
|
8
8
|
this.__registerHost();
|
|
9
9
|
this.__attachShadow();
|
|
10
|
+
this.expandedItemChange = createEvent(this, "expandedItemChange", 7);
|
|
10
11
|
}
|
|
11
12
|
componentDidLoad() {
|
|
12
13
|
this.el.addEventListener("expansionChange", (event) => {
|
|
13
14
|
if (event.detail) {
|
|
15
|
+
this.expandedItemChange.emit(event.target.itemId);
|
|
14
16
|
this.collapseInactiveItems(event.target);
|
|
15
17
|
}
|
|
16
18
|
});
|
|
@@ -1,15 +1,406 @@
|
|
|
1
|
-
import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
|
|
1
|
+
import { proxyCustomElement, HTMLElement as HTMLElement$1, createEvent, h, Host } from '@stencil/core/internal/client';
|
|
2
2
|
import { c as classnames } from './index2.js';
|
|
3
|
+
import { d as defineCustomElement$4 } from './swirl-box2.js';
|
|
4
|
+
import { d as defineCustomElement$3 } from './swirl-popover2.js';
|
|
5
|
+
import { d as defineCustomElement$2 } from './swirl-popover-trigger2.js';
|
|
6
|
+
import { v as v4 } from './v4.js';
|
|
3
7
|
|
|
4
|
-
|
|
8
|
+
// Clamps a value between an upper and lower bound.
|
|
9
|
+
// We use ternary operators because it makes the minified code
|
|
10
|
+
// 2 times shorter then `Math.min(Math.max(a,b),c)`
|
|
11
|
+
const clamp = (number, min = 0, max = 1) => {
|
|
12
|
+
return number > max ? max : number < min ? min : number;
|
|
13
|
+
};
|
|
14
|
+
const round = (number, digits = 0, base = Math.pow(10, digits)) => {
|
|
15
|
+
return Math.round(base * number) / base;
|
|
16
|
+
};
|
|
5
17
|
|
|
6
|
-
const
|
|
18
|
+
const hexToHsva = (hex) => rgbaToHsva(hexToRgba(hex));
|
|
19
|
+
const hexToRgba = (hex) => {
|
|
20
|
+
if (hex[0] === '#')
|
|
21
|
+
hex = hex.substring(1);
|
|
22
|
+
if (hex.length < 6) {
|
|
23
|
+
return {
|
|
24
|
+
r: parseInt(hex[0] + hex[0], 16),
|
|
25
|
+
g: parseInt(hex[1] + hex[1], 16),
|
|
26
|
+
b: parseInt(hex[2] + hex[2], 16),
|
|
27
|
+
a: hex.length === 4 ? round(parseInt(hex[3] + hex[3], 16) / 255, 2) : 1
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
r: parseInt(hex.substring(0, 2), 16),
|
|
32
|
+
g: parseInt(hex.substring(2, 4), 16),
|
|
33
|
+
b: parseInt(hex.substring(4, 6), 16),
|
|
34
|
+
a: hex.length === 8 ? round(parseInt(hex.substring(6, 8), 16) / 255, 2) : 1
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const hsvaToHex = (hsva) => rgbaToHex(hsvaToRgba(hsva));
|
|
38
|
+
const hsvaToHsla = ({ h, s, v, a }) => {
|
|
39
|
+
const hh = ((200 - s) * v) / 100;
|
|
40
|
+
return {
|
|
41
|
+
h: round(h),
|
|
42
|
+
s: round(hh > 0 && hh < 200 ? ((s * v) / 100 / (hh <= 100 ? hh : 200 - hh)) * 100 : 0),
|
|
43
|
+
l: round(hh / 2),
|
|
44
|
+
a: round(a, 2)
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
const hsvaToHslString = (hsva) => {
|
|
48
|
+
const { h, s, l } = hsvaToHsla(hsva);
|
|
49
|
+
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
50
|
+
};
|
|
51
|
+
const hsvaToRgba = ({ h, s, v, a }) => {
|
|
52
|
+
h = (h / 360) * 6;
|
|
53
|
+
s = s / 100;
|
|
54
|
+
v = v / 100;
|
|
55
|
+
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;
|
|
56
|
+
return {
|
|
57
|
+
r: round([v, c, b, b, d, v][module] * 255),
|
|
58
|
+
g: round([d, v, v, c, b, b][module] * 255),
|
|
59
|
+
b: round([b, b, d, v, v, c][module] * 255),
|
|
60
|
+
a: round(a, 2)
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
const format = (number) => {
|
|
64
|
+
const hex = number.toString(16);
|
|
65
|
+
return hex.length < 2 ? '0' + hex : hex;
|
|
66
|
+
};
|
|
67
|
+
const rgbaToHex = ({ r, g, b, a }) => {
|
|
68
|
+
const alphaHex = a < 1 ? format(round(a * 255)) : '';
|
|
69
|
+
return '#' + format(r) + format(g) + format(b) + alphaHex;
|
|
70
|
+
};
|
|
71
|
+
const rgbaToHsva = ({ r, g, b, a }) => {
|
|
72
|
+
const max = Math.max(r, g, b);
|
|
73
|
+
const delta = max - Math.min(r, g, b);
|
|
74
|
+
// prettier-ignore
|
|
75
|
+
const hh = delta
|
|
76
|
+
? max === r
|
|
77
|
+
? (g - b) / delta
|
|
78
|
+
: max === g
|
|
79
|
+
? 2 + (b - r) / delta
|
|
80
|
+
: 4 + (r - g) / delta
|
|
81
|
+
: 0;
|
|
82
|
+
return {
|
|
83
|
+
h: round(60 * (hh < 0 ? hh + 6 : hh)),
|
|
84
|
+
s: round(max ? (delta / max) * 100 : 0),
|
|
85
|
+
v: round((max / 255) * 100),
|
|
86
|
+
a
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const equalColorObjects = (first, second) => {
|
|
91
|
+
if (first === second)
|
|
92
|
+
return true;
|
|
93
|
+
for (const prop in first) {
|
|
94
|
+
// The following allows for a type-safe calling of this function (first & second have to be HSL, HSV, or RGB)
|
|
95
|
+
// with type-unsafe iterating over object keys. TS does not allow this without an index (`[key: string]: number`)
|
|
96
|
+
// on an object to define how iteration is normally done. To ensure extra keys are not allowed on our types,
|
|
97
|
+
// we must cast our object to unknown (as RGB demands `r` be a key, while `Record<string, x>` does not care if
|
|
98
|
+
// there is or not), and then as a type TS can iterate over.
|
|
99
|
+
if (first[prop] !==
|
|
100
|
+
second[prop])
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
};
|
|
105
|
+
const equalHex = (first, second) => {
|
|
106
|
+
if (first.toLowerCase() === second.toLowerCase())
|
|
107
|
+
return true;
|
|
108
|
+
// To compare colors like `#FFF` and `ffffff` we convert them into RGB objects
|
|
109
|
+
return equalColorObjects(hexToRgba(first), hexToRgba(second));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const cache = {};
|
|
113
|
+
const tpl = (html) => {
|
|
114
|
+
let template = cache[html];
|
|
115
|
+
if (!template) {
|
|
116
|
+
template = document.createElement('template');
|
|
117
|
+
template.innerHTML = html;
|
|
118
|
+
cache[html] = template;
|
|
119
|
+
}
|
|
120
|
+
return template;
|
|
121
|
+
};
|
|
122
|
+
const fire = (target, type, detail) => {
|
|
123
|
+
target.dispatchEvent(new CustomEvent(type, {
|
|
124
|
+
bubbles: true,
|
|
125
|
+
detail
|
|
126
|
+
}));
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
let hasTouched = false;
|
|
130
|
+
// Check if an event was triggered by touch
|
|
131
|
+
const isTouch = (e) => 'touches' in e;
|
|
132
|
+
// Prevent mobile browsers from handling mouse events (conflicting with touch ones).
|
|
133
|
+
// If we detected a touch interaction before, we prefer reacting to touch events only.
|
|
134
|
+
const isValid = (event) => {
|
|
135
|
+
if (hasTouched && !isTouch(event))
|
|
136
|
+
return false;
|
|
137
|
+
if (!hasTouched)
|
|
138
|
+
hasTouched = isTouch(event);
|
|
139
|
+
return true;
|
|
140
|
+
};
|
|
141
|
+
const pointerMove = (target, event) => {
|
|
142
|
+
const pointer = isTouch(event) ? event.touches[0] : event;
|
|
143
|
+
const rect = target.el.getBoundingClientRect();
|
|
144
|
+
fire(target.el, 'move', target.getMove({
|
|
145
|
+
x: clamp((pointer.pageX - (rect.left + window.pageXOffset)) / rect.width),
|
|
146
|
+
y: clamp((pointer.pageY - (rect.top + window.pageYOffset)) / rect.height)
|
|
147
|
+
}));
|
|
148
|
+
};
|
|
149
|
+
const keyMove = (target, event) => {
|
|
150
|
+
// We use `keyCode` instead of `key` to reduce the size of the library.
|
|
151
|
+
const keyCode = event.keyCode;
|
|
152
|
+
// Ignore all keys except arrow ones, Page Up, Page Down, Home and End.
|
|
153
|
+
if (keyCode > 40 || (target.xy && keyCode < 37) || keyCode < 33)
|
|
154
|
+
return;
|
|
155
|
+
// Do not scroll page by keys when color picker element has focus.
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
// Send relative offset to the parent component.
|
|
158
|
+
fire(target.el, 'move', target.getMove({
|
|
159
|
+
x: keyCode === 39 // Arrow Right
|
|
160
|
+
? 0.01
|
|
161
|
+
: keyCode === 37 // Arrow Left
|
|
162
|
+
? -0.01
|
|
163
|
+
: keyCode === 34 // Page Down
|
|
164
|
+
? 0.05
|
|
165
|
+
: keyCode === 33 // Page Up
|
|
166
|
+
? -0.05
|
|
167
|
+
: keyCode === 35 // End
|
|
168
|
+
? 1
|
|
169
|
+
: keyCode === 36 // Home
|
|
170
|
+
? -1
|
|
171
|
+
: 0,
|
|
172
|
+
y: keyCode === 40 // Arrow down
|
|
173
|
+
? 0.01
|
|
174
|
+
: keyCode === 38 // Arrow Up
|
|
175
|
+
? -0.01
|
|
176
|
+
: 0
|
|
177
|
+
}, true));
|
|
178
|
+
};
|
|
179
|
+
class Slider {
|
|
180
|
+
constructor(root, part, aria, xy) {
|
|
181
|
+
const template = tpl(`<div role="slider" tabindex="0" part="${part}" ${aria}><div part="${part}-pointer"></div></div>`);
|
|
182
|
+
root.appendChild(template.content.cloneNode(true));
|
|
183
|
+
const el = root.querySelector(`[part=${part}]`);
|
|
184
|
+
el.addEventListener('mousedown', this);
|
|
185
|
+
el.addEventListener('touchstart', this);
|
|
186
|
+
el.addEventListener('keydown', this);
|
|
187
|
+
this.el = el;
|
|
188
|
+
this.xy = xy;
|
|
189
|
+
this.nodes = [el.firstChild, el];
|
|
190
|
+
}
|
|
191
|
+
set dragging(state) {
|
|
192
|
+
const toggleEvent = state ? document.addEventListener : document.removeEventListener;
|
|
193
|
+
toggleEvent(hasTouched ? 'touchmove' : 'mousemove', this);
|
|
194
|
+
toggleEvent(hasTouched ? 'touchend' : 'mouseup', this);
|
|
195
|
+
}
|
|
196
|
+
handleEvent(event) {
|
|
197
|
+
switch (event.type) {
|
|
198
|
+
case 'mousedown':
|
|
199
|
+
case 'touchstart':
|
|
200
|
+
event.preventDefault();
|
|
201
|
+
// event.button is 0 in mousedown for left button activation
|
|
202
|
+
if (!isValid(event) || (!hasTouched && event.button != 0))
|
|
203
|
+
return;
|
|
204
|
+
this.el.focus();
|
|
205
|
+
pointerMove(this, event);
|
|
206
|
+
this.dragging = true;
|
|
207
|
+
break;
|
|
208
|
+
case 'mousemove':
|
|
209
|
+
case 'touchmove':
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
pointerMove(this, event);
|
|
212
|
+
break;
|
|
213
|
+
case 'mouseup':
|
|
214
|
+
case 'touchend':
|
|
215
|
+
this.dragging = false;
|
|
216
|
+
break;
|
|
217
|
+
case 'keydown':
|
|
218
|
+
keyMove(this, event);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
style(styles) {
|
|
223
|
+
styles.forEach((style, i) => {
|
|
224
|
+
for (const p in style) {
|
|
225
|
+
this.nodes[i].style.setProperty(p, style[p]);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
class Hue extends Slider {
|
|
232
|
+
constructor(root) {
|
|
233
|
+
super(root, 'hue', 'aria-label="Hue" aria-valuemin="0" aria-valuemax="360"', false);
|
|
234
|
+
}
|
|
235
|
+
update({ h }) {
|
|
236
|
+
this.h = h;
|
|
237
|
+
this.style([
|
|
238
|
+
{
|
|
239
|
+
left: `${(h / 360) * 100}%`,
|
|
240
|
+
color: hsvaToHslString({ h, s: 100, v: 100, a: 1 })
|
|
241
|
+
}
|
|
242
|
+
]);
|
|
243
|
+
this.el.setAttribute('aria-valuenow', `${round(h)}`);
|
|
244
|
+
}
|
|
245
|
+
getMove(offset, key) {
|
|
246
|
+
// Hue measured in degrees of the color circle ranging from 0 to 360
|
|
247
|
+
return { h: key ? clamp(this.h + offset.x * 360, 0, 360) : 360 * offset.x };
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
class Saturation extends Slider {
|
|
252
|
+
constructor(root) {
|
|
253
|
+
super(root, 'saturation', 'aria-label="Color"', true);
|
|
254
|
+
}
|
|
255
|
+
update(hsva) {
|
|
256
|
+
this.hsva = hsva;
|
|
257
|
+
this.style([
|
|
258
|
+
{
|
|
259
|
+
top: `${100 - hsva.v}%`,
|
|
260
|
+
left: `${hsva.s}%`,
|
|
261
|
+
color: hsvaToHslString(hsva)
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
'background-color': hsvaToHslString({ h: hsva.h, s: 100, v: 100, a: 1 })
|
|
265
|
+
}
|
|
266
|
+
]);
|
|
267
|
+
this.el.setAttribute('aria-valuetext', `Saturation ${round(hsva.s)}%, Brightness ${round(hsva.v)}%`);
|
|
268
|
+
}
|
|
269
|
+
getMove(offset, key) {
|
|
270
|
+
// Saturation and brightness always fit into [0, 100] range
|
|
271
|
+
return {
|
|
272
|
+
s: key ? clamp(this.hsva.s + offset.x * 100, 0, 100) : offset.x * 100,
|
|
273
|
+
v: key ? clamp(this.hsva.v - offset.y * 100, 0, 100) : Math.round(100 - offset.y * 100)
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
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)}`;
|
|
279
|
+
|
|
280
|
+
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}`;
|
|
281
|
+
|
|
282
|
+
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}`;
|
|
283
|
+
|
|
284
|
+
const $isSame = Symbol('same');
|
|
285
|
+
const $color = Symbol('color');
|
|
286
|
+
const $hsva = Symbol('hsva');
|
|
287
|
+
const $update = Symbol('update');
|
|
288
|
+
const $parts = Symbol('parts');
|
|
289
|
+
const $css = Symbol('css');
|
|
290
|
+
const $sliders = Symbol('sliders');
|
|
291
|
+
class ColorPicker extends HTMLElement {
|
|
292
|
+
static get observedAttributes() {
|
|
293
|
+
return ['color'];
|
|
294
|
+
}
|
|
295
|
+
get [$css]() {
|
|
296
|
+
return [css, hueCss, saturationCss];
|
|
297
|
+
}
|
|
298
|
+
get [$sliders]() {
|
|
299
|
+
return [Saturation, Hue];
|
|
300
|
+
}
|
|
301
|
+
get color() {
|
|
302
|
+
return this[$color];
|
|
303
|
+
}
|
|
304
|
+
set color(newColor) {
|
|
305
|
+
if (!this[$isSame](newColor)) {
|
|
306
|
+
const newHsva = this.colorModel.toHsva(newColor);
|
|
307
|
+
this[$update](newHsva);
|
|
308
|
+
this[$color] = newColor;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
constructor() {
|
|
312
|
+
super();
|
|
313
|
+
const template = tpl(`<style>${this[$css].join('')}</style>`);
|
|
314
|
+
const root = this.attachShadow({ mode: 'open' });
|
|
315
|
+
root.appendChild(template.content.cloneNode(true));
|
|
316
|
+
root.addEventListener('move', this);
|
|
317
|
+
this[$parts] = this[$sliders].map((slider) => new slider(root));
|
|
318
|
+
}
|
|
319
|
+
connectedCallback() {
|
|
320
|
+
// A user may set a property on an _instance_ of an element,
|
|
321
|
+
// before its prototype has been connected to this class.
|
|
322
|
+
// If so, we need to run it through the proper class setter.
|
|
323
|
+
if (this.hasOwnProperty('color')) {
|
|
324
|
+
const value = this.color;
|
|
325
|
+
delete this['color'];
|
|
326
|
+
this.color = value;
|
|
327
|
+
}
|
|
328
|
+
else if (!this.color) {
|
|
329
|
+
this.color = this.colorModel.defaultColor;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
attributeChangedCallback(_attr, _oldVal, newVal) {
|
|
333
|
+
const color = this.colorModel.fromAttr(newVal);
|
|
334
|
+
if (!this[$isSame](color)) {
|
|
335
|
+
this.color = color;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
handleEvent(event) {
|
|
339
|
+
// Merge the current HSV color object with updated params.
|
|
340
|
+
const oldHsva = this[$hsva];
|
|
341
|
+
const newHsva = { ...oldHsva, ...event.detail };
|
|
342
|
+
this[$update](newHsva);
|
|
343
|
+
let newColor;
|
|
344
|
+
if (!equalColorObjects(newHsva, oldHsva) &&
|
|
345
|
+
!this[$isSame]((newColor = this.colorModel.fromHsva(newHsva)))) {
|
|
346
|
+
this[$color] = newColor;
|
|
347
|
+
fire(this, 'color-changed', { value: newColor });
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
[$isSame](color) {
|
|
351
|
+
return this.color && this.colorModel.equal(color, this.color);
|
|
352
|
+
}
|
|
353
|
+
[$update](hsva) {
|
|
354
|
+
this[$hsva] = hsva;
|
|
355
|
+
this[$parts].forEach((part) => part.update(hsva));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const colorModel = {
|
|
360
|
+
defaultColor: '#000',
|
|
361
|
+
toHsva: hexToHsva,
|
|
362
|
+
fromHsva: ({ h, s, v }) => hsvaToHex({ h, s, v, a: 1 }),
|
|
363
|
+
equal: equalHex,
|
|
364
|
+
fromAttr: (color) => color
|
|
365
|
+
};
|
|
366
|
+
class HexBase extends ColorPicker {
|
|
367
|
+
get colorModel() {
|
|
368
|
+
return colorModel;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* A color picker custom element that uses HEX format.
|
|
374
|
+
*
|
|
375
|
+
* @element hex-color-picker
|
|
376
|
+
*
|
|
377
|
+
* @prop {string} color - Selected color in HEX format.
|
|
378
|
+
* @attr {string} color - Selected color in HEX format.
|
|
379
|
+
*
|
|
380
|
+
* @fires color-changed - Event fired when color property changes.
|
|
381
|
+
*
|
|
382
|
+
* @csspart hue - A hue selector container.
|
|
383
|
+
* @csspart saturation - A saturation selector container
|
|
384
|
+
* @csspart hue-pointer - A hue pointer element.
|
|
385
|
+
* @csspart saturation-pointer - A saturation pointer element.
|
|
386
|
+
*/
|
|
387
|
+
class HexColorPicker extends HexBase {
|
|
388
|
+
}
|
|
389
|
+
customElements.define('hex-color-picker', HexColorPicker);
|
|
390
|
+
|
|
391
|
+
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}";
|
|
392
|
+
|
|
393
|
+
const SwirlColorInput$1 = /*@__PURE__*/ proxyCustomElement(class SwirlColorInput extends HTMLElement$1 {
|
|
7
394
|
constructor() {
|
|
8
395
|
super();
|
|
9
396
|
this.__registerHost();
|
|
10
397
|
this.inputBlur = createEvent(this, "inputBlur", 7);
|
|
11
398
|
this.inputFocus = createEvent(this, "inputFocus", 7);
|
|
12
399
|
this.valueChange = createEvent(this, "valueChange", 7);
|
|
400
|
+
this.pickerId = `color-picker-${v4()}`;
|
|
401
|
+
this.onPickerChange = (event) => {
|
|
402
|
+
this.value = event.detail.value;
|
|
403
|
+
};
|
|
13
404
|
this.onChange = (event) => {
|
|
14
405
|
const el = event.target;
|
|
15
406
|
this.value = el.value;
|
|
@@ -30,6 +421,8 @@ const SwirlColorInput$1 = /*@__PURE__*/ proxyCustomElement(class SwirlColorInput
|
|
|
30
421
|
this.swirlAriaDescribedby = undefined;
|
|
31
422
|
this.inline = undefined;
|
|
32
423
|
this.invalid = undefined;
|
|
424
|
+
this.pickerButtonLabel = "Open color picker";
|
|
425
|
+
this.pickerLabel = "Color picker";
|
|
33
426
|
this.placeholder = undefined;
|
|
34
427
|
this.required = undefined;
|
|
35
428
|
this.value = undefined;
|
|
@@ -41,6 +434,10 @@ const SwirlColorInput$1 = /*@__PURE__*/ proxyCustomElement(class SwirlColorInput
|
|
|
41
434
|
this.inputEl.focus();
|
|
42
435
|
});
|
|
43
436
|
}
|
|
437
|
+
this.picker.addEventListener("color-changed", this.onPickerChange);
|
|
438
|
+
}
|
|
439
|
+
disconnectedCallback() {
|
|
440
|
+
this.picker?.removeEventListener("color-changed", this.onPickerChange);
|
|
44
441
|
}
|
|
45
442
|
watchValue(newValue, oldValue) {
|
|
46
443
|
if (newValue !== oldValue) {
|
|
@@ -60,11 +457,11 @@ const SwirlColorInput$1 = /*@__PURE__*/ proxyCustomElement(class SwirlColorInput
|
|
|
60
457
|
const className = classnames("color-input", {
|
|
61
458
|
"color-input--inline": this.inline,
|
|
62
459
|
});
|
|
63
|
-
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:
|
|
460
|
+
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: {
|
|
64
461
|
backgroundColor: this.disabled
|
|
65
462
|
? "var(--s-border-subdued)"
|
|
66
463
|
: this.value,
|
|
67
|
-
} }))));
|
|
464
|
+
}, 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) }))))));
|
|
68
465
|
}
|
|
69
466
|
static get watchers() { return {
|
|
70
467
|
"value": ["watchValue"]
|
|
@@ -77,6 +474,8 @@ const SwirlColorInput$1 = /*@__PURE__*/ proxyCustomElement(class SwirlColorInput
|
|
|
77
474
|
"swirlAriaDescribedby": [1, "swirl-aria-describedby"],
|
|
78
475
|
"inline": [4],
|
|
79
476
|
"invalid": [4],
|
|
477
|
+
"pickerButtonLabel": [1, "picker-button-label"],
|
|
478
|
+
"pickerLabel": [1, "picker-label"],
|
|
80
479
|
"placeholder": [1],
|
|
81
480
|
"required": [4],
|
|
82
481
|
"value": [1537]
|
|
@@ -85,13 +484,28 @@ function defineCustomElement$1() {
|
|
|
85
484
|
if (typeof customElements === "undefined") {
|
|
86
485
|
return;
|
|
87
486
|
}
|
|
88
|
-
const components = ["swirl-color-input"];
|
|
487
|
+
const components = ["swirl-color-input", "swirl-box", "swirl-popover", "swirl-popover-trigger"];
|
|
89
488
|
components.forEach(tagName => { switch (tagName) {
|
|
90
489
|
case "swirl-color-input":
|
|
91
490
|
if (!customElements.get(tagName)) {
|
|
92
491
|
customElements.define(tagName, SwirlColorInput$1);
|
|
93
492
|
}
|
|
94
493
|
break;
|
|
494
|
+
case "swirl-box":
|
|
495
|
+
if (!customElements.get(tagName)) {
|
|
496
|
+
defineCustomElement$4();
|
|
497
|
+
}
|
|
498
|
+
break;
|
|
499
|
+
case "swirl-popover":
|
|
500
|
+
if (!customElements.get(tagName)) {
|
|
501
|
+
defineCustomElement$3();
|
|
502
|
+
}
|
|
503
|
+
break;
|
|
504
|
+
case "swirl-popover-trigger":
|
|
505
|
+
if (!customElements.get(tagName)) {
|
|
506
|
+
defineCustomElement$2();
|
|
507
|
+
}
|
|
508
|
+
break;
|
|
95
509
|
} });
|
|
96
510
|
}
|
|
97
511
|
defineCustomElement$1();
|
|
@@ -3023,10 +3023,10 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
3023
3023
|
return import(
|
|
3024
3024
|
/* webpackMode: "lazy" */
|
|
3025
3025
|
'./swirl-video-thumbnail.entry.js').then(processMod, consoleError);
|
|
3026
|
-
case 'swirl-app-
|
|
3026
|
+
case 'swirl-app-layout_6':
|
|
3027
3027
|
return import(
|
|
3028
3028
|
/* webpackMode: "lazy" */
|
|
3029
|
-
'./swirl-app-
|
|
3029
|
+
'./swirl-app-layout_6.entry.js').then(processMod, consoleError);
|
|
3030
3030
|
case 'swirl-badge':
|
|
3031
3031
|
return import(
|
|
3032
3032
|
/* webpackMode: "lazy" */
|
|
@@ -3087,6 +3087,10 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
3087
3087
|
return import(
|
|
3088
3088
|
/* webpackMode: "lazy" */
|
|
3089
3089
|
'./swirl-action-list_3.entry.js').then(processMod, consoleError);
|
|
3090
|
+
case 'swirl-box':
|
|
3091
|
+
return import(
|
|
3092
|
+
/* webpackMode: "lazy" */
|
|
3093
|
+
'./swirl-box.entry.js').then(processMod, consoleError);
|
|
3090
3094
|
case 'swirl-file-viewer_7':
|
|
3091
3095
|
return import(
|
|
3092
3096
|
/* webpackMode: "lazy" */
|
|
@@ -3119,10 +3123,6 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
3119
3123
|
return import(
|
|
3120
3124
|
/* webpackMode: "lazy" */
|
|
3121
3125
|
'./swirl-icon-expand-more.entry.js').then(processMod, consoleError);
|
|
3122
|
-
case 'swirl-popover_2':
|
|
3123
|
-
return import(
|
|
3124
|
-
/* webpackMode: "lazy" */
|
|
3125
|
-
'./swirl-popover_2.entry.js').then(processMod, consoleError);
|
|
3126
3126
|
case 'swirl-heading':
|
|
3127
3127
|
return import(
|
|
3128
3128
|
/* webpackMode: "lazy" */
|
|
@@ -3131,6 +3131,10 @@ const loadModule = (cmpMeta, hostRef, hmrVersionId) => {
|
|
|
3131
3131
|
return import(
|
|
3132
3132
|
/* webpackMode: "lazy" */
|
|
3133
3133
|
'./swirl-icon-check-strong.entry.js').then(processMod, consoleError);
|
|
3134
|
+
case 'swirl-popover_2':
|
|
3135
|
+
return import(
|
|
3136
|
+
/* webpackMode: "lazy" */
|
|
3137
|
+
'./swirl-popover_2.entry.js').then(processMod, consoleError);
|
|
3134
3138
|
case 'swirl-icon-close':
|
|
3135
3139
|
return import(
|
|
3136
3140
|
/* webpackMode: "lazy" */
|