@commmerce/ui 1.15.0 → 1.17.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.
@@ -0,0 +1,648 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _CmColorPicker_instances, _CmColorPicker_id, _CmColorPicker_written, _CmColorPicker_loaded, _CmColorPicker_local, _CmColorPicker_drag, _CmColorPicker_store, _CmColorPicker_loadSources, _CmColorPicker_readValue, _CmColorPicker_setHsvaFrom, _CmColorPicker_rgba_get, _CmColorPicker_write, _CmColorPicker_emit, _CmColorPicker_commit, _CmColorPicker_areaAt, _CmColorPicker_onAreaDown, _CmColorPicker_onAreaMove, _CmColorPicker_onUp, _CmColorPicker_onAreaKey, _CmColorPicker_onHue, _CmColorPicker_onAlpha, _CmColorPicker_onFormat, _CmColorPicker_onBox, _CmColorPicker_fromBoxes, _CmColorPicker_onEyedropper, _CmColorPicker_setMode, _CmColorPicker_setGrad, _CmColorPicker_selectStop, _CmColorPicker_posAt, _CmColorPicker_onBarDown, _CmColorPicker_onHandleDown, _CmColorPicker_onHandleMove, _CmColorPicker_moveStop, _CmColorPicker_removeStop, _CmColorPicker_onHandleKey, _CmColorPicker_pickSwatch, _CmColorPicker_swatchGroup, _CmColorPicker_boxes;
13
+ import { html, css, nothing } from 'lit';
14
+ import { live } from 'lit/directives/live.js';
15
+ import { base, define, nextId } from '../base.js';
16
+ import { CmLocalizedElement, defineStrings } from '../localize.js';
17
+ import { colorAt, formatColor, formatGradient, hsvToRgb, parseColor, parseGradient, rgbToHsl, rgbToHsv, sameColor, toHex6, hslToRgb, } from '../color.js';
18
+ import { localColorSource, pushRecent, MAX_RECENT } from '../color-source.js';
19
+ import './icon.js';
20
+ const strings = defineStrings('colorPicker', {
21
+ /** Accessible name of the whole picker when it has no `aria-label`. */
22
+ label: 'Colour picker',
23
+ solid: 'Solid',
24
+ gradient: 'Gradient',
25
+ /** Accessible name of the saturation and brightness square, and how its value is read out. */
26
+ area: 'Saturation and brightness',
27
+ areaValue: 'Saturation {s}%, brightness {v}%',
28
+ hue: 'Hue',
29
+ opacity: 'Opacity',
30
+ /** The colour format menu and its options. */
31
+ format: 'Colour format',
32
+ hex: 'Hex',
33
+ rgb: 'RGB',
34
+ hsl: 'HSL',
35
+ red: 'Red',
36
+ green: 'Green',
37
+ blue: 'Blue',
38
+ saturation: 'Saturation',
39
+ lightness: 'Lightness',
40
+ /** The browser's eyedropper button (shown only where the browser has one). */
41
+ eyedropper: 'Pick a colour from the screen',
42
+ /** Gradient controls. */
43
+ gradientType: 'Gradient type',
44
+ linear: 'Linear',
45
+ radial: 'Radial',
46
+ angle: 'Angle',
47
+ stops: 'Gradient stops',
48
+ stop: 'Stop {n}, {color} at {position}%',
49
+ addStop: 'Add stop',
50
+ removeStop: 'Remove stop',
51
+ /** Headings of the swatch groups. */
52
+ brand: 'Brand colours',
53
+ recent: 'Recent',
54
+ palette: 'Palette',
55
+ /** Accessible name of a swatch: its name and value, or the value alone. */
56
+ swatch: '{name}, {value}',
57
+ });
58
+ /** The default palette (the hues of the Commmerce light theme), shared with cm-color-field. */
59
+ export const DEFAULT_PALETTE = [
60
+ '#000000', '#707070', '#c9c9c9', '#de0000', '#ad5500', '#f1a953', '#ffc107', '#81bb47', '#3c7c00', '#5394d9', '#2e6faf', '#446beb',
61
+ ].map((value) => ({ value }));
62
+ const FORMATS = ['hex', 'rgb', 'hsl'];
63
+ const toSwatches = (list) => (list ?? []).flatMap((s) => {
64
+ const o = typeof s === 'string' ? { value: s } : s;
65
+ return o && typeof o.value === 'string' && (parseColor(o.value) || parseGradient(o.value)) ? [{ value: o.value.trim(), name: o.name }] : [];
66
+ });
67
+ /**
68
+ * Colour picker: a saturation and brightness square, hue and opacity sliders, the value as hex, RGB or HSL, the
69
+ * browser's eyedropper, gradients, and swatches for the store's brand colours, the merchant's recent colours and a
70
+ * palette. Use it inline in a panel, or let cm-color-field open it (`picker`).
71
+ *
72
+ * Brand and recent colours come from `brand-colors` / `recent-colors`, or from a `source`: `app.colors` (App
73
+ * Bridge), `httpColorSource()` (your server, Colour API) or `localColorSource()`. Each committed colour that isn't
74
+ * a brand or palette colour is added to the recents: through `source.addRecentColor`, or kept locally when
75
+ * `recent-key` is set, and announced with `cm-recent-change` either way.
76
+ * @element cm-color-picker
77
+ * @fires input - While the colour changes (dragging, typing a complete value).
78
+ * @fires change - When a colour is committed: a drag ends, a swatch is picked, a box is left or Enter pressed.
79
+ * @fires cm-recent-change - `detail.colors`: the new recent list (newest first) after a commit added to it.
80
+ * @csspart area - The saturation and brightness square.
81
+ * @csspart swatch - Each swatch button.
82
+ */
83
+ export class CmColorPicker extends CmLocalizedElement {
84
+ constructor() {
85
+ super(...arguments);
86
+ _CmColorPicker_instances.add(this);
87
+ /** The colour: hex, `rgb()`, `hsl()` or, with `gradient`, a `linear-gradient()` / `radial-gradient()`. Empty for none. */
88
+ this.value = '';
89
+ /** How the value is written: `hex` (default), `rgb` or `hsl`. Changes when the merchant picks another format. */
90
+ this.format = 'hex';
91
+ /** Formats the merchant may switch between, space separated. Default `hex rgb hsl`; one format hides the menu. */
92
+ this.formats = 'hex rgb hsl';
93
+ /** Shows the opacity slider. A see-through colour is written `#rrggbbaa`, `rgba()` or `hsla()`. */
94
+ this.alpha = false;
95
+ /** Adds Solid / Gradient tabs: linear or radial gradients with two or more stops. */
96
+ this.gradient = false;
97
+ /** Keeps recents in this browser under this key when there is no `source` (a `localColorSource`). */
98
+ this.recentKey = '';
99
+ /** How many recent colours to show. Default 16. */
100
+ this.maxRecent = MAX_RECENT;
101
+ /** Shows the eyedropper where the browser has one (Chrome and Edge on desktop). Default on. */
102
+ this.eyedropper = true;
103
+ /** Blocks interaction. */
104
+ this.disabled = false;
105
+ this._hsva = { h: 0, s: 0, v: 0, a: 1 };
106
+ this._grad = null;
107
+ this._stop = 0;
108
+ this._brand = [];
109
+ this._recent = [];
110
+ /** Text in a box while it differs from the colour, keyed by box. */
111
+ this._drafts = {};
112
+ _CmColorPicker_id.set(this, nextId('cm-cp'));
113
+ /** The value this element wrote last, so an outside change is told apart from our own. */
114
+ _CmColorPicker_written.set(this, void 0);
115
+ _CmColorPicker_loaded.set(this, void 0);
116
+ _CmColorPicker_local.set(this, void 0);
117
+ _CmColorPicker_drag.set(this, null);
118
+ }
119
+ connectedCallback() {
120
+ super.connectedCallback();
121
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_loadSources).call(this);
122
+ }
123
+ /** Formats the merchant may choose. */
124
+ get allowedFormats() {
125
+ const list = String(this.formats ?? '').split(/[\s,]+/).filter((f) => FORMATS.includes(f));
126
+ return list.length ? list : ['hex'];
127
+ }
128
+ /** The palette in use. */
129
+ get palette() { return this.swatches ? toSwatches(this.swatches) : DEFAULT_PALETTE; }
130
+ /** Brand colours in use (`brand-colors`, else from `source`). */
131
+ get brand() { return this.brandColors ? toSwatches(this.brandColors) : this._brand; }
132
+ /** Recent colours in use (`recent-colors`, else from `source` / `recent-key`), without gradients unless `gradient`. */
133
+ get recent() {
134
+ const list = (this.recentColors ?? this._recent).filter((c) => parseColor(c) || (this.gradient && parseGradient(c)));
135
+ return list.filter((c) => this.alpha || (parseColor(c)?.a ?? 1) === 1).slice(0, this.maxRecent || MAX_RECENT);
136
+ }
137
+ willUpdate(changed) {
138
+ if (changed.has('recentKey'))
139
+ __classPrivateFieldSet(this, _CmColorPicker_local, undefined, "f");
140
+ if (changed.has('source') || changed.has('recentKey'))
141
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_loadSources).call(this);
142
+ if (changed.has('format') && !this.allowedFormats.includes(this.format))
143
+ this.format = this.allowedFormats[0];
144
+ if (changed.has('value') && this.value !== __classPrivateFieldGet(this, _CmColorPicker_written, "f"))
145
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_readValue).call(this);
146
+ }
147
+ render() {
148
+ const { h, s, v, a } = this._hsva;
149
+ const rgb = __classPrivateFieldGet(this, _CmColorPicker_instances, "a", _CmColorPicker_rgba_get);
150
+ const solid = toHex6(rgb);
151
+ const formats = this.allowedFormats;
152
+ const g = this._grad;
153
+ const rtl = this.matches(':dir(rtl)');
154
+ const hasDropper = this.eyedropper && typeof window !== 'undefined' && 'EyeDropper' in window;
155
+ const gradCss = g ? formatGradient({ ...g, type: 'linear', angle: rtl ? 270 : 90 }) : '';
156
+ return html `<div class="panel" role="group" aria-label=${this.getAttribute('aria-label') || this.t('label')}>
157
+ ${this.gradient
158
+ ? html `<div class="tabs" role="radiogroup" aria-label=${this.t('label')}>
159
+ <button type="button" role="radio" aria-checked=${g ? 'false' : 'true'} tabindex=${g ? '-1' : '0'} @click=${() => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setMode).call(this, false)}
160
+ @keydown=${(e) => { if (e.key.startsWith('Arrow')) {
161
+ e.preventDefault();
162
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setMode).call(this, true);
163
+ this.updateComplete.then(() => (this.renderRoot.querySelectorAll('.tabs button')[1])?.focus());
164
+ } }}>${this.t('solid')}</button>
165
+ <button type="button" role="radio" aria-checked=${g ? 'true' : 'false'} tabindex=${g ? '0' : '-1'} @click=${() => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setMode).call(this, true)}
166
+ @keydown=${(e) => { if (e.key.startsWith('Arrow')) {
167
+ e.preventDefault();
168
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setMode).call(this, false);
169
+ this.updateComplete.then(() => (this.renderRoot.querySelectorAll('.tabs button')[0])?.focus());
170
+ } }}>${this.t('gradient')}</button>
171
+ </div>`
172
+ : nothing}
173
+ ${g
174
+ ? html `<div class="row">
175
+ <select aria-label=${this.t('gradientType')} @change=${(e) => { e.stopPropagation(); __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setGrad).call(this, { type: e.target.value }); }}>
176
+ <option value="linear" .selected=${live(g.type === 'linear')}>${this.t('linear')}</option><option value="radial" .selected=${live(g.type === 'radial')}>${this.t('radial')}</option>
177
+ </select>
178
+ ${g.type === 'linear'
179
+ ? html `<input class="box num" type="text" inputmode="numeric" aria-label=${this.t('angle')} .value=${live(this._drafts.angle ?? `${g.angle}°`)}
180
+ @input=${(e) => { e.stopPropagation(); this._drafts = { ...this._drafts, angle: e.target.value }; }}
181
+ @change=${(e) => { e.stopPropagation(); const n = parseFloat(e.target.value); this._drafts = {}; if (Number.isFinite(n))
182
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setGrad).call(this, { angle: ((Math.round(n) % 360) + 360) % 360 }); }} />`
183
+ : nothing}
184
+ <button type="button" class="icon-btn" aria-label=${this.t('removeStop')} title=${this.t('removeStop')} ?disabled=${g.stops.length <= 2}
185
+ @click=${() => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_removeStop).call(this, this._stop)}><cm-icon name="trash" size="16"></cm-icon></button>
186
+ </div>
187
+ <div class="bar checker" role="group" aria-label=${this.t('stops')} @pointerdown=${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onBarDown)}>
188
+ <span class="fill" style="background:${gradCss}"></span>
189
+ ${g.stops.map((st, i) => html `<button type="button" class="handle" role="slider" aria-orientation="horizontal"
190
+ aria-valuemin="0" aria-valuemax="100" aria-valuenow=${Math.round(st.position)}
191
+ aria-label=${this.t('stop', { n: i + 1, color: formatColor(st.color, this.format), position: Math.round(st.position) })}
192
+ aria-current=${i === this._stop ? 'true' : 'false'} style="inset-inline-start:${st.position}%;background:${formatColor(st.color)}"
193
+ @pointerdown=${(e) => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onHandleDown).call(this, e, i)} @pointermove=${(e) => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onHandleMove).call(this, e, i)}
194
+ @pointerup=${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onUp)} @pointercancel=${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onUp)} @focus=${() => { if (this._stop !== i)
195
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_selectStop).call(this, i); }}
196
+ @keydown=${(e) => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onHandleKey).call(this, e, i)}></button>`)}
197
+ </div>`
198
+ : nothing}
199
+ <div class="area" part="area" tabindex="0" role="slider" aria-label=${this.t('area')}
200
+ aria-valuetext=${this.t('areaValue', { s: Math.round(s), v: Math.round(v) })} aria-valuenow=${Math.round(s)} aria-valuemin="0" aria-valuemax="100"
201
+ style="background-color:hsl(${h} 100% 50%)"
202
+ @pointerdown=${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onAreaDown)} @pointermove=${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onAreaMove)} @pointerup=${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onUp)} @pointercancel=${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onUp)} @keydown=${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onAreaKey)}>
203
+ <span class="thumb" style="left:${rtl ? 100 - s : s}%;top:${100 - v}%;background:${solid}"></span>
204
+ </div>
205
+ <div class="sliders">
206
+ <span class="preview checker" aria-hidden="true"><span style="background:${g ? formatGradient(g) : formatColor(rgb)}"></span></span>
207
+ <div class="stack">
208
+ <input type="range" class="hue" min="0" max="360" step="1" .value=${live(String(Math.round(h)))} aria-label=${this.t('hue')}
209
+ @input=${(e) => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onHue).call(this, e, false)} @change=${(e) => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onHue).call(this, e, true)} />
210
+ ${this.alpha
211
+ ? html `<div class="alpha-wrap checker"><input type="range" min="0" max="100" step="1" .value=${live(String(Math.round(a * 100)))}
212
+ aria-label=${this.t('opacity')} aria-valuetext="${Math.round(a * 100)}%"
213
+ style="--track:linear-gradient(to ${rtl ? 'left' : 'right'}, transparent, ${solid})"
214
+ @input=${(e) => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onAlpha).call(this, e, false)} @change=${(e) => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onAlpha).call(this, e, true)} /></div>`
215
+ : nothing}
216
+ </div>
217
+ </div>
218
+ <div class="row">
219
+ ${formats.length > 1
220
+ ? html `<select aria-label=${this.t('format')} @change=${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onFormat)}>
221
+ ${formats.map((f) => html `<option value=${f} ?selected=${f === this.format} .selected=${live(f === this.format)}>${this.t(f)}</option>`)}
222
+ </select>`
223
+ : nothing}
224
+ ${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_boxes).call(this)}
225
+ ${hasDropper
226
+ ? html `<button type="button" class="icon-btn" aria-label=${this.t('eyedropper')} title=${this.t('eyedropper')} @click=${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onEyedropper)}>
227
+ <cm-icon name="eyedropper" size="16"></cm-icon></button>`
228
+ : nothing}
229
+ </div>
230
+ ${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_swatchGroup).call(this, 'brand', this.brand)}
231
+ ${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_swatchGroup).call(this, 'recent', this.recent.map((value) => ({ value })))}
232
+ ${__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_swatchGroup).call(this, 'palette', this.palette)}
233
+ </div>`;
234
+ }
235
+ }
236
+ _CmColorPicker_id = new WeakMap(), _CmColorPicker_written = new WeakMap(), _CmColorPicker_loaded = new WeakMap(), _CmColorPicker_local = new WeakMap(), _CmColorPicker_drag = new WeakMap(), _CmColorPicker_instances = new WeakSet(), _CmColorPicker_store = function _CmColorPicker_store() {
237
+ if (this.source)
238
+ return this.source;
239
+ if (!this.recentKey)
240
+ return undefined;
241
+ return (__classPrivateFieldSet(this, _CmColorPicker_local, __classPrivateFieldGet(this, _CmColorPicker_local, "f") ?? localColorSource(this.recentKey), "f"));
242
+ }, _CmColorPicker_loadSources = async function _CmColorPicker_loadSources() {
243
+ const src = __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_store).call(this);
244
+ if (!src || src === __classPrivateFieldGet(this, _CmColorPicker_loaded, "f"))
245
+ return;
246
+ __classPrivateFieldSet(this, _CmColorPicker_loaded, src, "f");
247
+ const [brand, recent] = await Promise.allSettled([src.brandColors?.() ?? Promise.resolve([]), src.recentColors?.() ?? Promise.resolve([])]);
248
+ if (__classPrivateFieldGet(this, _CmColorPicker_loaded, "f") !== src)
249
+ return;
250
+ if (brand.status === 'fulfilled' && Array.isArray(brand.value))
251
+ this._brand = toSwatches(brand.value);
252
+ if (recent.status === 'fulfilled' && Array.isArray(recent.value))
253
+ this._recent = recent.value.filter((c) => typeof c === 'string');
254
+ }, _CmColorPicker_readValue = function _CmColorPicker_readValue() {
255
+ const v = (this.value ?? '').trim();
256
+ const g = this.gradient ? parseGradient(v) : null;
257
+ if (g) {
258
+ this._grad = g;
259
+ this._stop = Math.min(this._stop, g.stops.length - 1);
260
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setHsvaFrom).call(this, g.stops[this._stop].color);
261
+ }
262
+ else {
263
+ this._grad = null;
264
+ const c = parseColor(v);
265
+ if (c)
266
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setHsvaFrom).call(this, c);
267
+ }
268
+ if (/^rgba?\(/i.test(v) && this.allowedFormats.includes('rgb'))
269
+ this.format = 'rgb';
270
+ else if (/^hsla?\(/i.test(v) && this.allowedFormats.includes('hsl'))
271
+ this.format = 'hsl';
272
+ this._drafts = {};
273
+ }, _CmColorPicker_setHsvaFrom = function _CmColorPicker_setHsvaFrom(c) {
274
+ const n = rgbToHsv(c);
275
+ if (n.s === 0 || n.v === 0)
276
+ n.h = this._hsva.h;
277
+ if (n.v === 0)
278
+ n.s = this._hsva.s;
279
+ this._hsva = { ...n, a: this.alpha ? c.a : 1 };
280
+ }, _CmColorPicker_rgba_get = function _CmColorPicker_rgba_get() { return hsvToRgb(this._hsva); }, _CmColorPicker_write = function _CmColorPicker_write(emitChange = false) {
281
+ let next;
282
+ if (this._grad) {
283
+ const stops = this._grad.stops.map((s, i) => (i === this._stop ? { ...s, color: __classPrivateFieldGet(this, _CmColorPicker_instances, "a", _CmColorPicker_rgba_get) } : s));
284
+ this._grad = { ...this._grad, stops };
285
+ next = formatGradient(this._grad, this.format);
286
+ }
287
+ else
288
+ next = formatColor(__classPrivateFieldGet(this, _CmColorPicker_instances, "a", _CmColorPicker_rgba_get), this.format);
289
+ const changed = next !== this.value;
290
+ __classPrivateFieldSet(this, _CmColorPicker_written, next, "f");
291
+ this.value = next;
292
+ if (changed)
293
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_emit).call(this, 'input');
294
+ if (emitChange)
295
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_commit).call(this);
296
+ }, _CmColorPicker_emit = function _CmColorPicker_emit(type) { this.dispatchEvent(new Event(type, { bubbles: true, composed: true })); }, _CmColorPicker_commit = function _CmColorPicker_commit() {
297
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_emit).call(this, 'change');
298
+ const v = this.value;
299
+ if (!v || [...this.brand, ...this.palette].some((s) => sameColor(s.value, v)))
300
+ return;
301
+ const before = this.recentColors ?? this._recent;
302
+ if (before[0] && sameColor(before[0], v))
303
+ return;
304
+ const next = pushRecent(before, v, Math.max(this.maxRecent || MAX_RECENT, MAX_RECENT));
305
+ this._recent = next;
306
+ this.dispatchEvent(new CustomEvent('cm-recent-change', { detail: { colors: next }, bubbles: true, composed: true }));
307
+ const add = __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_store).call(this)?.addRecentColor?.(v);
308
+ add?.then((list) => { if (Array.isArray(list))
309
+ this._recent = list; }).catch(() => { });
310
+ }, _CmColorPicker_areaAt = function _CmColorPicker_areaAt(e) {
311
+ const r = e.currentTarget.getBoundingClientRect();
312
+ const x = Math.min(1, Math.max(0, (e.clientX - r.left) / r.width));
313
+ const y = Math.min(1, Math.max(0, (e.clientY - r.top) / r.height));
314
+ const rtl = getComputedStyle(this).direction === 'rtl';
315
+ this._hsva = { ...this._hsva, s: (rtl ? 1 - x : x) * 100, v: (1 - y) * 100 };
316
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this);
317
+ }, _CmColorPicker_onAreaDown = function _CmColorPicker_onAreaDown(e) {
318
+ if (e.button !== 0)
319
+ return;
320
+ const el = e.currentTarget;
321
+ el.setPointerCapture?.(e.pointerId);
322
+ el.focus();
323
+ __classPrivateFieldSet(this, _CmColorPicker_drag, 'area', "f");
324
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_areaAt).call(this, e);
325
+ }, _CmColorPicker_onAreaMove = function _CmColorPicker_onAreaMove(e) { if (__classPrivateFieldGet(this, _CmColorPicker_drag, "f") === 'area')
326
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_areaAt).call(this, e); }, _CmColorPicker_onUp = function _CmColorPicker_onUp() {
327
+ if (__classPrivateFieldGet(this, _CmColorPicker_drag, "f") === null)
328
+ return;
329
+ __classPrivateFieldSet(this, _CmColorPicker_drag, null, "f");
330
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_commit).call(this);
331
+ }, _CmColorPicker_onAreaKey = function _CmColorPicker_onAreaKey(e) {
332
+ const step = e.shiftKey ? 10 : 1;
333
+ const rtl = getComputedStyle(this).direction === 'rtl';
334
+ let { s, v } = this._hsva;
335
+ if (e.key === 'ArrowRight')
336
+ s += rtl ? -step : step;
337
+ else if (e.key === 'ArrowLeft')
338
+ s += rtl ? step : -step;
339
+ else if (e.key === 'ArrowUp')
340
+ v += step;
341
+ else if (e.key === 'ArrowDown')
342
+ v -= step;
343
+ else if (e.key === 'Home')
344
+ s = 0;
345
+ else if (e.key === 'End')
346
+ s = 100;
347
+ else if (e.key === 'PageUp')
348
+ v = 100;
349
+ else if (e.key === 'PageDown')
350
+ v = 0;
351
+ else
352
+ return;
353
+ e.preventDefault();
354
+ this._hsva = { ...this._hsva, s: Math.min(100, Math.max(0, s)), v: Math.min(100, Math.max(0, v)) };
355
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, true);
356
+ }, _CmColorPicker_onHue = function _CmColorPicker_onHue(e, commit) {
357
+ e.stopPropagation();
358
+ this._hsva = { ...this._hsva, h: Number(e.target.value) };
359
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, commit);
360
+ }, _CmColorPicker_onAlpha = function _CmColorPicker_onAlpha(e, commit) {
361
+ e.stopPropagation();
362
+ this._hsva = { ...this._hsva, a: Number(e.target.value) / 100 };
363
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, commit);
364
+ }, _CmColorPicker_onFormat = function _CmColorPicker_onFormat(e) {
365
+ e.stopPropagation();
366
+ this.format = e.target.value;
367
+ this._drafts = {};
368
+ if (this.value)
369
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, true);
370
+ }, _CmColorPicker_onBox = function _CmColorPicker_onBox(e, key, commit) {
371
+ e.stopPropagation();
372
+ const text = e.target.value;
373
+ const c = __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_fromBoxes).call(this, key, text);
374
+ if (!c) {
375
+ this._drafts = { ...this._drafts, [key]: text };
376
+ return;
377
+ }
378
+ this._drafts = commit ? {} : { ...this._drafts, [key]: text };
379
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setHsvaFrom).call(this, c);
380
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, commit);
381
+ }, _CmColorPicker_fromBoxes = function _CmColorPicker_fromBoxes(key, text) {
382
+ const cur = __classPrivateFieldGet(this, _CmColorPicker_instances, "a", _CmColorPicker_rgba_get);
383
+ if (key === 'hex') {
384
+ const t = text.trim();
385
+ if (!/^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t))
386
+ return null;
387
+ const c = parseColor(t);
388
+ return c && (this.alpha && /^#?[0-9a-f]{8}$/i.test(t) ? c : { ...c, a: this._hsva.a });
389
+ }
390
+ const n = Number(text);
391
+ if (text.trim() === '' || !Number.isFinite(n))
392
+ return null;
393
+ if (key === 'a')
394
+ return n >= 0 && n <= 100 ? { ...cur, a: n / 100 } : null;
395
+ if (key === 'r' || key === 'g' || key === 'b')
396
+ return n >= 0 && n <= 255 ? { ...cur, [key]: Math.round(n) } : null;
397
+ const hsl = rgbToHsl(cur);
398
+ if (key === 'h')
399
+ return n >= 0 && n <= 360 ? hslToRgb({ ...hsl, h: n % 360, a: cur.a }) : null;
400
+ if (key === 's' || key === 'l')
401
+ return n >= 0 && n <= 100 ? hslToRgb({ ...hsl, [key]: n, a: cur.a }) : null;
402
+ return null;
403
+ }, _CmColorPicker_onEyedropper = async function _CmColorPicker_onEyedropper() {
404
+ const Dropper = window.EyeDropper;
405
+ if (!Dropper)
406
+ return;
407
+ try {
408
+ const { sRGBHex } = await new Dropper().open();
409
+ const c = parseColor(sRGBHex);
410
+ if (!c)
411
+ return;
412
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setHsvaFrom).call(this, { ...c, a: this._hsva.a });
413
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, true);
414
+ }
415
+ catch { /* cancelled */ }
416
+ }, _CmColorPicker_setMode = function _CmColorPicker_setMode(gradient) {
417
+ if (gradient === !!this._grad)
418
+ return;
419
+ if (gradient) {
420
+ const c = __classPrivateFieldGet(this, _CmColorPicker_instances, "a", _CmColorPicker_rgba_get);
421
+ const end = hsvToRgb({ ...this._hsva, h: (this._hsva.h + 60) % 360, s: Math.max(this._hsva.s, 40), v: Math.max(this._hsva.v, 60) });
422
+ this._grad = { type: 'linear', angle: 90, stops: [{ color: c, position: 0 }, { color: end, position: 100 }] };
423
+ this._stop = 0;
424
+ }
425
+ else {
426
+ this._grad = null;
427
+ }
428
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, true);
429
+ }, _CmColorPicker_setGrad = function _CmColorPicker_setGrad(patch, commit = true) {
430
+ if (!this._grad)
431
+ return;
432
+ this._grad = { ...this._grad, ...patch };
433
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, commit);
434
+ }, _CmColorPicker_selectStop = function _CmColorPicker_selectStop(i) {
435
+ if (!this._grad)
436
+ return;
437
+ this._stop = i;
438
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setHsvaFrom).call(this, this._grad.stops[i].color);
439
+ this._drafts = {};
440
+ }, _CmColorPicker_posAt = function _CmColorPicker_posAt(e, bar) {
441
+ const r = bar.getBoundingClientRect();
442
+ const x = Math.min(1, Math.max(0, (e.clientX - r.left) / r.width));
443
+ return Math.round((getComputedStyle(this).direction === 'rtl' ? 1 - x : x) * 100);
444
+ }, _CmColorPicker_onBarDown = function _CmColorPicker_onBarDown(e) {
445
+ if (!this._grad || e.button !== 0 || e.target.closest('.handle'))
446
+ return;
447
+ const pos = __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_posAt).call(this, e, e.currentTarget);
448
+ const color = colorAt(this._grad, pos);
449
+ const stops = [...this._grad.stops, { color, position: pos }];
450
+ this._grad = { ...this._grad, stops };
451
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_selectStop).call(this, stops.length - 1);
452
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, true);
453
+ this.updateComplete.then(() => this.renderRoot.querySelectorAll('.handle')[stops.length - 1]?.focus());
454
+ }, _CmColorPicker_onHandleDown = function _CmColorPicker_onHandleDown(e, i) {
455
+ if (e.button !== 0)
456
+ return;
457
+ e.stopPropagation();
458
+ e.currentTarget.setPointerCapture?.(e.pointerId);
459
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_selectStop).call(this, i);
460
+ __classPrivateFieldSet(this, _CmColorPicker_drag, i, "f");
461
+ }, _CmColorPicker_onHandleMove = function _CmColorPicker_onHandleMove(e, i) {
462
+ if (__classPrivateFieldGet(this, _CmColorPicker_drag, "f") !== i || !this._grad)
463
+ return;
464
+ const bar = this.renderRoot.querySelector('.bar');
465
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_moveStop).call(this, i, __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_posAt).call(this, e, bar), false);
466
+ }, _CmColorPicker_moveStop = function _CmColorPicker_moveStop(i, position, commit) {
467
+ if (!this._grad)
468
+ return;
469
+ const stops = this._grad.stops.map((s, j) => (j === i ? { ...s, position: Math.min(100, Math.max(0, position)) } : s));
470
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setGrad).call(this, { stops }, commit);
471
+ }, _CmColorPicker_removeStop = function _CmColorPicker_removeStop(i) {
472
+ if (!this._grad || this._grad.stops.length <= 2)
473
+ return;
474
+ const stops = this._grad.stops.filter((_, j) => j !== i);
475
+ this._grad = { ...this._grad, stops };
476
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_selectStop).call(this, Math.min(i, stops.length - 1));
477
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, true);
478
+ this.updateComplete.then(() => this.renderRoot.querySelectorAll('.handle')[this._stop]?.focus());
479
+ }, _CmColorPicker_onHandleKey = function _CmColorPicker_onHandleKey(e, i) {
480
+ if (!this._grad)
481
+ return;
482
+ const step = e.shiftKey ? 10 : 1;
483
+ const rtl = getComputedStyle(this).direction === 'rtl';
484
+ const p = this._grad.stops[i].position;
485
+ if (e.key === 'ArrowRight' || e.key === 'ArrowUp')
486
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_moveStop).call(this, i, p + (rtl && e.key === 'ArrowRight' ? -step : step), true);
487
+ else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown')
488
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_moveStop).call(this, i, p - (rtl && e.key === 'ArrowLeft' ? -step : step), true);
489
+ else if (e.key === 'Home')
490
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_moveStop).call(this, i, 0, true);
491
+ else if (e.key === 'End')
492
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_moveStop).call(this, i, 100, true);
493
+ else if (e.key === 'Delete' || e.key === 'Backspace')
494
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_removeStop).call(this, i);
495
+ else
496
+ return;
497
+ e.preventDefault();
498
+ }, _CmColorPicker_pickSwatch = function _CmColorPicker_pickSwatch(value) {
499
+ const g = parseGradient(value);
500
+ if (g && this.gradient) {
501
+ this._grad = g;
502
+ this._stop = 0;
503
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setHsvaFrom).call(this, g.stops[0].color);
504
+ }
505
+ else {
506
+ const c = parseColor(value);
507
+ if (!c)
508
+ return;
509
+ this._grad = null;
510
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_setHsvaFrom).call(this, c);
511
+ }
512
+ this._drafts = {};
513
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_write).call(this, true);
514
+ }, _CmColorPicker_swatchGroup = function _CmColorPicker_swatchGroup(title, list) {
515
+ if (!list.length)
516
+ return nothing;
517
+ const id = `${__classPrivateFieldGet(this, _CmColorPicker_id, "f")}-${title}`;
518
+ return html `<div class="group" role="group" aria-labelledby=${id}>
519
+ <h3 id=${id}>${this.t(title)}</h3>
520
+ <div class="sws">${list.map((s) => {
521
+ const label = s.name ? this.t('swatch', { name: s.name, value: s.value }) : s.value;
522
+ const on = !!this.value && sameColor(s.value, this.value);
523
+ return html `<button type="button" class="sw checker" part="swatch" aria-pressed=${on ? 'true' : 'false'} aria-label=${label} title=${s.name || s.value}
524
+ @click=${() => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_pickSwatch).call(this, s.value)}><span style="background:${s.value}"></span></button>`;
525
+ })}</div>
526
+ </div>`;
527
+ }, _CmColorPicker_boxes = function _CmColorPicker_boxes() {
528
+ const c = __classPrivateFieldGet(this, _CmColorPicker_instances, "a", _CmColorPicker_rgba_get), d = this._drafts, f = this.format;
529
+ const box = (key, label, value, num = true) => html `<input class="box ${num ? 'num' : ''}"
530
+ type="text" inputmode=${num ? 'numeric' : 'text'} autocomplete="off" spellcheck="false" aria-label=${label}
531
+ .value=${live(d[key] ?? String(value))} aria-invalid=${d[key] !== undefined && !__classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_fromBoxes).call(this, key, d[key]) ? 'true' : nothing}
532
+ @input=${(e) => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onBox).call(this, e, key, false)} @change=${(e) => __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onBox).call(this, e, key, true)}
533
+ @keydown=${(e) => { if (e.key === 'Enter')
534
+ __classPrivateFieldGet(this, _CmColorPicker_instances, "m", _CmColorPicker_onBox).call(this, e, key, true); }} />`;
535
+ const hsl = rgbToHsl(c);
536
+ return html `<div class="boxes">
537
+ ${f === 'hex' ? box('hex', this.t('hex'), toHex6(c), false) : nothing}
538
+ ${f === 'rgb' ? [box('r', this.t('red'), c.r), box('g', this.t('green'), c.g), box('b', this.t('blue'), c.b)] : nothing}
539
+ ${f === 'hsl' ? [box('h', this.t('hue'), Math.round(hsl.h)), box('s', this.t('saturation'), Math.round(hsl.s)), box('l', this.t('lightness'), Math.round(hsl.l))] : nothing}
540
+ ${this.alpha ? box('a', this.t('opacity'), Math.round(this._hsva.a * 100)) : nothing}
541
+ </div>`;
542
+ };
543
+ CmColorPicker.properties = {
544
+ value: {},
545
+ format: { reflect: true },
546
+ formats: {},
547
+ alpha: { type: Boolean },
548
+ gradient: { type: Boolean },
549
+ swatches: { type: Array },
550
+ brandColors: { type: Array, attribute: 'brand-colors' },
551
+ recentColors: { type: Array, attribute: 'recent-colors' },
552
+ source: { attribute: false },
553
+ recentKey: { attribute: 'recent-key' },
554
+ maxRecent: { type: Number, attribute: 'max-recent' },
555
+ eyedropper: { type: Boolean },
556
+ disabled: { type: Boolean, reflect: true },
557
+ _hsva: { state: true },
558
+ _grad: { state: true },
559
+ _stop: { state: true },
560
+ _brand: { state: true },
561
+ _recent: { state: true },
562
+ _drafts: { state: true },
563
+ };
564
+ CmColorPicker.styles = [
565
+ base,
566
+ css `
567
+ :host { display: block; inline-size: 272px; max-inline-size: 100%; color: var(--cm-text-default); font-size: var(--cm-font-size-13); }
568
+ :host([disabled]) { opacity: 0.5; pointer-events: none; }
569
+ .panel { display: flex; flex-direction: column; gap: var(--cm-space-12); }
570
+ .checker {
571
+ background-color: var(--cm-bg-surface);
572
+ background-image: repeating-conic-gradient(var(--cm-border-subtle) 0 25%, transparent 0 50%);
573
+ background-size: 8px 8px;
574
+ }
575
+ .tabs { display: flex; padding: 2px; gap: 2px; border-radius: var(--cm-radius-sm); background: var(--cm-bg-inset); }
576
+ .tabs button {
577
+ flex: 1; height: 28px; border: 0; border-radius: var(--cm-radius-xs); background: none; font: inherit; color: var(--cm-text-tertiary); cursor: pointer;
578
+ }
579
+ .tabs button[aria-checked='true'] { background: var(--cm-bg-surface); color: var(--cm-text-default); font-weight: 500; box-shadow: var(--cm-shadow-sm); }
580
+ .tabs button:focus-visible, button:focus-visible, select:focus-visible, .area:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
581
+ .area {
582
+ position: relative; height: 160px; border-radius: var(--cm-radius-sm); touch-action: none; cursor: crosshair;
583
+ background-image: linear-gradient(to top, black, transparent), linear-gradient(to right, white, transparent); /* scale-exempt: colour data, not theme */
584
+ }
585
+ .thumb {
586
+ position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: var(--cm-radius-full); pointer-events: none;
587
+ border: 2px solid white; box-shadow: 0 0 0 1px rgb(0 0 0 / 0.4), inset 0 0 0 1px rgb(0 0 0 / 0.4); /* scale-exempt: visible on any colour */
588
+ }
589
+ .sliders { display: flex; align-items: center; gap: var(--cm-space-12); }
590
+ .sliders .stack { flex: 1; display: flex; flex-direction: column; gap: var(--cm-space-12); min-width: 0; }
591
+ .preview { position: relative; flex: none; width: 32px; height: 32px; border-radius: var(--cm-radius-full); overflow: hidden; border: var(--cm-border-1) solid var(--cm-border-subtle); }
592
+ .preview span, .sw span { position: absolute; inset: 0; }
593
+ input[type='range'] {
594
+ -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 12px; margin: 0; border-radius: var(--cm-radius-full);
595
+ background: var(--track); cursor: pointer; border: var(--cm-border-1) solid var(--cm-border-subtle);
596
+ }
597
+ input[type='range'].hue { --track: linear-gradient(to right, red, yellow, lime, cyan, blue, magenta, red); } /* scale-exempt: hue track */
598
+ input[type='range']::-webkit-slider-thumb {
599
+ -webkit-appearance: none; width: 16px; height: 16px; border-radius: var(--cm-radius-full);
600
+ border: 2px solid white; box-shadow: 0 0 0 1px rgb(0 0 0 / 0.4); background: transparent; /* scale-exempt: visible on any colour */
601
+ }
602
+ input[type='range']::-moz-range-thumb {
603
+ width: 12px; height: 12px; border-radius: var(--cm-radius-full);
604
+ border: 2px solid white; box-shadow: 0 0 0 1px rgb(0 0 0 / 0.4); background: transparent; /* scale-exempt: visible on any colour */
605
+ }
606
+ input[type='range']:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
607
+ .alpha-wrap { position: relative; border-radius: var(--cm-radius-full); }
608
+ .row { display: flex; align-items: center; gap: var(--cm-space-8); }
609
+ .row > * { min-width: 0; }
610
+ select, .box {
611
+ height: 32px; padding: 0 var(--cm-space-8); font: inherit; font-size: var(--cm-font-size-13); font-variant-numeric: tabular-nums;
612
+ color: var(--cm-text-default); background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-input);
613
+ border-radius: var(--cm-radius-sm); box-sizing: border-box; outline: none;
614
+ }
615
+ select { flex: none; padding-inline-end: var(--cm-space-4); cursor: pointer; }
616
+ .box { flex: 1; width: 100%; }
617
+ .box.num { padding: 0 var(--cm-space-4); text-align: center; -moz-appearance: textfield; }
618
+ .box::-webkit-inner-spin-button { -webkit-appearance: none; }
619
+ .box:hover:not(:focus), select:hover { border-color: var(--cm-border-strong); }
620
+ .box:focus { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
621
+ .box[aria-invalid='true'] { border-color: var(--cm-border-critical); }
622
+ .boxes { flex: 1; display: flex; gap: var(--cm-space-4); }
623
+ .icon-btn {
624
+ flex: none; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0;
625
+ border: var(--cm-border-1) solid var(--cm-border-input); border-radius: var(--cm-radius-sm); background: var(--cm-bg-surface); color: var(--cm-text-default); cursor: pointer;
626
+ }
627
+ .icon-btn:hover { background: var(--cm-bg-inset); }
628
+ .icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
629
+ .bar { position: relative; height: 24px; margin: 0 8px; border-radius: var(--cm-radius-xs); cursor: copy; border: var(--cm-border-1) solid var(--cm-border-subtle); }
630
+ .bar .fill { position: absolute; inset: 0; border-radius: inherit; }
631
+ .handle {
632
+ position: absolute; top: -4px; width: 16px; height: 32px; margin-inline-start: -8px; padding: 0; cursor: grab; touch-action: none;
633
+ border-radius: var(--cm-radius-xs); border: 2px solid var(--cm-bg-surface); box-shadow: 0 0 0 1px var(--cm-border-strong);
634
+ }
635
+ .handle[aria-current='true'] { box-shadow: 0 0 0 2px var(--cm-border-strong); }
636
+ .group { display: flex; flex-direction: column; gap: var(--cm-space-8); }
637
+ .group h3 { margin: 0; font-size: var(--cm-font-size-12); line-height: 16px; font-weight: 500; color: var(--cm-text-tertiary); }
638
+ .sws { display: flex; flex-wrap: wrap; gap: var(--cm-space-8); }
639
+ .sw {
640
+ position: relative; width: 24px; height: 24px; padding: 0; overflow: hidden; cursor: pointer; border-radius: var(--cm-radius-full);
641
+ border: var(--cm-border-1) solid var(--cm-border-input);
642
+ }
643
+ .sw[aria-pressed='true'] { box-shadow: 0 0 0 2px var(--cm-bg-surface), 0 0 0 4px var(--cm-border-strong); }
644
+ .sw:focus-visible { outline-offset: 4px; }
645
+ .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
646
+ `,
647
+ ];
648
+ define('cm-color-picker', CmColorPicker);