@aquera/nile-elements 1.6.9 → 1.7.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 (55) hide show
  1. package/README.md +3 -0
  2. package/dist/index.cjs.js +1 -1
  3. package/dist/index.esm.js +1 -1
  4. package/dist/index.js +291 -123
  5. package/dist/nile-color-picker/index.cjs.js +2 -0
  6. package/dist/nile-color-picker/index.cjs.js.map +1 -0
  7. package/dist/nile-color-picker/index.esm.js +1 -0
  8. package/dist/nile-color-picker/nile-color-picker.cjs.js +2 -0
  9. package/dist/nile-color-picker/nile-color-picker.cjs.js.map +1 -0
  10. package/dist/nile-color-picker/nile-color-picker.css.cjs.js +2 -0
  11. package/dist/nile-color-picker/nile-color-picker.css.cjs.js.map +1 -0
  12. package/dist/nile-color-picker/nile-color-picker.css.esm.js +1 -0
  13. package/dist/nile-color-picker/nile-color-picker.esm.js +111 -0
  14. package/dist/nile-color-swatch/index.cjs.js +2 -0
  15. package/dist/nile-color-swatch/index.cjs.js.map +1 -0
  16. package/dist/nile-color-swatch/index.esm.js +1 -0
  17. package/dist/nile-color-swatch/nile-color-swatch.cjs.js +2 -0
  18. package/dist/nile-color-swatch/nile-color-swatch.cjs.js.map +1 -0
  19. package/dist/nile-color-swatch/nile-color-swatch.css.cjs.js +2 -0
  20. package/dist/nile-color-swatch/nile-color-swatch.css.cjs.js.map +1 -0
  21. package/dist/nile-color-swatch/nile-color-swatch.css.esm.js +44 -0
  22. package/dist/nile-color-swatch/nile-color-swatch.esm.js +16 -0
  23. package/dist/src/index.d.ts +3 -0
  24. package/dist/src/index.js +2 -0
  25. package/dist/src/index.js.map +1 -1
  26. package/dist/src/nile-color-picker/index.d.ts +3 -0
  27. package/dist/src/nile-color-picker/index.js +3 -0
  28. package/dist/src/nile-color-picker/index.js.map +1 -0
  29. package/dist/src/nile-color-picker/nile-color-picker.css.d.ts +1 -0
  30. package/dist/src/nile-color-picker/nile-color-picker.css.js +228 -0
  31. package/dist/src/nile-color-picker/nile-color-picker.css.js.map +1 -0
  32. package/dist/src/nile-color-picker/nile-color-picker.d.ts +92 -0
  33. package/dist/src/nile-color-picker/nile-color-picker.js +613 -0
  34. package/dist/src/nile-color-picker/nile-color-picker.js.map +1 -0
  35. package/dist/src/nile-color-swatch/index.d.ts +1 -0
  36. package/dist/src/nile-color-swatch/index.js +2 -0
  37. package/dist/src/nile-color-swatch/index.js.map +1 -0
  38. package/dist/src/nile-color-swatch/nile-color-swatch.css.d.ts +1 -0
  39. package/dist/src/nile-color-swatch/nile-color-swatch.css.js +46 -0
  40. package/dist/src/nile-color-swatch/nile-color-swatch.css.js.map +1 -0
  41. package/dist/src/nile-color-swatch/nile-color-swatch.d.ts +15 -0
  42. package/dist/src/nile-color-swatch/nile-color-swatch.js +66 -0
  43. package/dist/src/nile-color-swatch/nile-color-swatch.js.map +1 -0
  44. package/dist/src/version.js +1 -1
  45. package/dist/src/version.js.map +1 -1
  46. package/dist/tsconfig.tsbuildinfo +1 -1
  47. package/package.json +4 -2
  48. package/src/index.ts +3 -0
  49. package/src/nile-color-picker/index.ts +3 -0
  50. package/src/nile-color-picker/nile-color-picker.css.ts +225 -0
  51. package/src/nile-color-picker/nile-color-picker.ts +541 -0
  52. package/src/nile-color-swatch/index.ts +1 -0
  53. package/src/nile-color-swatch/nile-color-swatch.css.ts +46 -0
  54. package/src/nile-color-swatch/nile-color-swatch.ts +72 -0
  55. package/vscode-html-custom-data.json +126 -20
@@ -0,0 +1,613 @@
1
+ import { __decorate } from "tslib";
2
+ import { LitElement, html, nothing } from 'lit';
3
+ import { customElement, property, state } from 'lit/decorators.js';
4
+ import { getCssText } from './nile-color-picker.css';
5
+ import '../nile-dropdown/nile-dropdown';
6
+ import '../nile-menu/nile-menu';
7
+ import '../nile-menu-item/nile-menu-item';
8
+ export const DEFAULT_PALETTE = [
9
+ { color: '#131316', name: 'Black' },
10
+ { color: '#26272B', name: 'Dark Gray' },
11
+ { color: '#525252', name: 'Gray' },
12
+ { color: '#737373', name: 'Medium Gray' },
13
+ { color: '#A3A3A3', name: 'Silver' },
14
+ { color: '#D6D6D6', name: 'Light Gray' },
15
+ { color: '#F5F5F5', name: 'Off White' },
16
+ { color: '#FFFFFF', name: 'White' },
17
+ { color: '#CA8504', name: 'Yellow 3' },
18
+ { color: '#C01048', name: 'Red 3' },
19
+ { color: '#DD2590', name: 'Pink 3' },
20
+ { color: '#155EEF', name: 'Blue Dark 3' },
21
+ { color: '#444CE7', name: 'Indigo 3' },
22
+ { color: '#7A5AF8', name: 'Purple 3' },
23
+ { color: '#3E4784', name: 'Gray Blue 3' },
24
+ { color: '#087443', name: 'Green 3' },
25
+ { color: '#FDE272', name: 'Yellow 2' },
26
+ { color: '#FEA3B4', name: 'Red 2' },
27
+ { color: '#FAA7E0', name: 'Pink 2' },
28
+ { color: '#528BFF', name: 'Blue Dark 2' },
29
+ { color: '#A4BCFD', name: 'Indigo 2' },
30
+ { color: '#BDB4FE', name: 'Purple 2' },
31
+ { color: '#B3B8DB', name: 'Gray Blue 2' },
32
+ { color: '#73E2A3', name: 'Green 2' },
33
+ { color: '#FEFBE8', name: 'Yellow 1' },
34
+ { color: '#FFF1F3', name: 'Red 1' },
35
+ { color: '#FDF2FA', name: 'Pink 1' },
36
+ { color: '#EFF4FF', name: 'Blue Dark 1' },
37
+ { color: '#EEF4FF', name: 'Indigo 1' },
38
+ { color: '#F4F3FF', name: 'Purple 1' },
39
+ { color: '#F8F9FC', name: 'Gray Blue 1' },
40
+ { color: '#EDFCF2', name: 'Green 1' },
41
+ ];
42
+ /* ── color math helpers ──────────────────────────────────────────────── */
43
+ export function hexToRgb(hex) {
44
+ const h = hex.replace('#', '');
45
+ return [parseInt(h.slice(0, 2), 16), parseInt(h.slice(2, 4), 16), parseInt(h.slice(4, 6), 16)];
46
+ }
47
+ export function rgbToHex(r, g, b) {
48
+ return '#' + [r, g, b].map(v => v.toString(16).padStart(2, '0')).join('').toUpperCase();
49
+ }
50
+ export function rgbToHsv(r, g, b) {
51
+ r /= 255;
52
+ g /= 255;
53
+ b /= 255;
54
+ const max = Math.max(r, g, b), min = Math.min(r, g, b), d = max - min;
55
+ let h = 0;
56
+ if (d !== 0) {
57
+ if (max === r)
58
+ h = ((g - b) / d + 6) % 6;
59
+ else if (max === g)
60
+ h = (b - r) / d + 2;
61
+ else
62
+ h = (r - g) / d + 4;
63
+ h *= 60;
64
+ }
65
+ return [h, max === 0 ? 0 : d / max, max];
66
+ }
67
+ export function hsvToRgb(h, s, v) {
68
+ const c = v * s, x = c * (1 - Math.abs(((h / 60) % 2) - 1)), m = v - c;
69
+ let r = 0, g = 0, b = 0;
70
+ if (h < 60) {
71
+ r = c;
72
+ g = x;
73
+ }
74
+ else if (h < 120) {
75
+ r = x;
76
+ g = c;
77
+ }
78
+ else if (h < 180) {
79
+ g = c;
80
+ b = x;
81
+ }
82
+ else if (h < 240) {
83
+ g = x;
84
+ b = c;
85
+ }
86
+ else if (h < 300) {
87
+ r = x;
88
+ b = c;
89
+ }
90
+ else {
91
+ r = c;
92
+ b = x;
93
+ }
94
+ return [Math.round((r + m) * 255), Math.round((g + m) * 255), Math.round((b + m) * 255)];
95
+ }
96
+ let NileColorPicker = class NileColorPicker extends LitElement {
97
+ constructor() {
98
+ super(...arguments);
99
+ this.type = 'swatches';
100
+ /** Currently selected hex color value. */
101
+ this.value = '#000000';
102
+ /** What to show in swatch tooltips. */
103
+ this.swatchTooltip = 'name';
104
+ /** How many recent/custom colors to display. */
105
+ this.recentColorsCount = 3;
106
+ /** Show a "No Fill" button (useful for background-color use cases). */
107
+ this.noFill = false;
108
+ this.mode = 'inline';
109
+ /** Show the SV gradient canvas (the large colour area). Applies when type="picker". */
110
+ this.showCanvas = true;
111
+ /** Show the hue slider row (rainbow bar + eyedropper). Applies when type="picker". */
112
+ this.showHue = true;
113
+ /** Show the HEX / RGB input row. Applies when type="picker". */
114
+ this.showInputs = true;
115
+ /** Show the Cancel / Okay action buttons. Applies when type="picker". */
116
+ this.showActions = true;
117
+ this.open = false;
118
+ /** Custom palette. Accepts a JSON array of `{ color, name }` objects or plain
119
+ * hex strings. Falls back to the built-in palette when empty. */
120
+ this.palette = [];
121
+ /* ── internal state ──────────────────────────────────────────────── */
122
+ this._view = 'swatches';
123
+ this._recentColors = [];
124
+ // picker canvas state
125
+ this._hue = 220;
126
+ this._sat = 0.7;
127
+ this._val = 0.93;
128
+ this._colorMode = 'HEX';
129
+ this._hexInput = '#366AEE';
130
+ this._r = 54;
131
+ this._g = 106;
132
+ this._b = 238;
133
+ this._svCanvas = null;
134
+ this._hueCanvas = null;
135
+ this._draggingSV = false;
136
+ this._draggingHue = false;
137
+ this._pendingColor = '#366AEE';
138
+ this._onSVMouseDown = (e) => { e.preventDefault(); this._draggingSV = true; this._updateSV(e); };
139
+ this._onHueMouseDown = (e) => { e.preventDefault(); this._draggingHue = true; this._updateHue(e); };
140
+ this._onGlobalMouseMove = (e) => {
141
+ if (this._draggingSV)
142
+ this._updateSV(e);
143
+ if (this._draggingHue)
144
+ this._updateHue(e);
145
+ };
146
+ this._onGlobalMouseUp = () => {
147
+ const wasDraggingSV = this._draggingSV;
148
+ const wasDraggingHue = this._draggingHue;
149
+ if (!this.showActions && this._view === 'picker' && (wasDraggingSV || wasDraggingHue)) {
150
+ this._commitPickerIfNoActions();
151
+ }
152
+ this._draggingSV = false;
153
+ this._draggingHue = false;
154
+ };
155
+ this._onHexInput = (e) => {
156
+ let val = (e.detail?.value ?? e.target.value ?? '').trim();
157
+ if (!val.startsWith('#'))
158
+ val = '#' + val;
159
+ if (/^#[0-9a-f]{6}$/i.test(val)) {
160
+ const [r, g, b] = hexToRgb(val);
161
+ [this._hue, this._sat, this._val] = rgbToHsv(r, g, b);
162
+ this._syncInputs();
163
+ if (this._view === 'picker')
164
+ this._commitPickerIfNoActions();
165
+ }
166
+ };
167
+ this._onRgbInput = (ch, e) => {
168
+ const raw = e.detail?.value ?? e.target.value;
169
+ const v = Math.max(0, Math.min(255, parseInt(String(raw), 10) || 0));
170
+ if (ch === 'r')
171
+ this._r = v;
172
+ else if (ch === 'g')
173
+ this._g = v;
174
+ else
175
+ this._b = v;
176
+ [this._hue, this._sat, this._val] = rgbToHsv(this._r, this._g, this._b);
177
+ this._syncInputs();
178
+ if (this._view === 'picker')
179
+ this._commitPickerIfNoActions();
180
+ };
181
+ this._onColorModeSelect = (e) => {
182
+ e.stopPropagation();
183
+ const v = e.detail?.value;
184
+ if (v === 'HEX' || v === 'RGB') {
185
+ this._colorMode = v;
186
+ }
187
+ };
188
+ this._pickEyedropper = async () => {
189
+ const Ctor = window.EyeDropper;
190
+ if (!Ctor) {
191
+ this._openPicker();
192
+ return;
193
+ }
194
+ try {
195
+ const result = await new Ctor().open();
196
+ if (result?.sRGBHex)
197
+ this._apply(result.sRGBHex);
198
+ }
199
+ catch { /* cancelled */ }
200
+ };
201
+ }
202
+ createRenderRoot() { return this; }
203
+ /* ── lifecycle ───────────────────────────────────────────────────── */
204
+ connectedCallback() {
205
+ super.connectedCallback();
206
+ this._view = this.type;
207
+ if (this.type === 'picker') {
208
+ const [r, g, b] = hexToRgb(this._norm(this.value));
209
+ [this._hue, this._sat, this._val] = rgbToHsv(r, g, b);
210
+ this._syncInputs();
211
+ }
212
+ this._injectCss();
213
+ document.addEventListener('mousemove', this._onGlobalMouseMove);
214
+ document.addEventListener('mouseup', this._onGlobalMouseUp);
215
+ }
216
+ disconnectedCallback() {
217
+ document.removeEventListener('mousemove', this._onGlobalMouseMove);
218
+ document.removeEventListener('mouseup', this._onGlobalMouseUp);
219
+ super.disconnectedCallback();
220
+ }
221
+ updated(changed) {
222
+ if (changed.has('type')) {
223
+ this._view = this.type;
224
+ if (this.type === 'picker') {
225
+ const [r, g, b] = hexToRgb(this._norm(this.value));
226
+ [this._hue, this._sat, this._val] = rgbToHsv(r, g, b);
227
+ this._syncInputs();
228
+ }
229
+ }
230
+ if (changed.has('value') && this.type === 'picker' && this._view === 'picker' &&
231
+ !this._draggingSV && !this._draggingHue) {
232
+ const [r, g, b] = hexToRgb(this._norm(this.value));
233
+ [this._hue, this._sat, this._val] = rgbToHsv(r, g, b);
234
+ this._syncInputs();
235
+ }
236
+ if (this._view === 'picker') {
237
+ requestAnimationFrame(() => {
238
+ this._svCanvas = this.querySelector('.ncp-sv-canvas');
239
+ this._hueCanvas = this.querySelector('.ncp-hue-canvas');
240
+ this._drawSV();
241
+ this._drawHue();
242
+ });
243
+ }
244
+ }
245
+ /* ── public API ──────────────────────────────────────────────────── */
246
+ /** Reset the view back to the default type (call this when the host popover closes). */
247
+ reset() {
248
+ this._view = this.type;
249
+ }
250
+ _injectCss() {
251
+ if (this.querySelector('style[data-nile-color-picker]'))
252
+ return;
253
+ const style = document.createElement('style');
254
+ style.setAttribute('data-nile-color-picker', '');
255
+ style.textContent = getCssText();
256
+ this.insertBefore(style, this.firstChild);
257
+ }
258
+ _norm(hex) {
259
+ const t = hex.trim();
260
+ if (/^#[0-9a-f]{6}$/i.test(t))
261
+ return t.toUpperCase();
262
+ if (/^#[0-9a-f]{3}$/i.test(t)) {
263
+ const [a, b, c] = t.slice(1).toUpperCase().split('');
264
+ return `#${a}${a}${b}${b}${c}${c}`;
265
+ }
266
+ return '#000000';
267
+ }
268
+ get _paletteColors() {
269
+ return this.palette.length > 0 ? this.palette : DEFAULT_PALETTE;
270
+ }
271
+ _emit(value) {
272
+ this.dispatchEvent(new CustomEvent('nile-change', {
273
+ detail: { value },
274
+ bubbles: true,
275
+ composed: true,
276
+ }));
277
+ }
278
+ _apply(color) {
279
+ const hex = this._norm(color);
280
+ this.value = hex;
281
+ const entry = { color: hex, name: hex };
282
+ this._recentColors = [entry, ...this._recentColors.filter(e => this._norm(e.color) !== hex)].slice(0, this.recentColorsCount);
283
+ this._emit(hex);
284
+ if (this.mode === 'popover' && this._view === 'swatches') {
285
+ this._closePopover();
286
+ }
287
+ }
288
+ _closePopover() {
289
+ const pop = this.querySelector('nile-popover');
290
+ if (pop)
291
+ pop.isShow = false;
292
+ }
293
+ _openPicker() {
294
+ const [r, g, b] = hexToRgb(this._norm(this.value));
295
+ const [h, s, v] = rgbToHsv(r, g, b);
296
+ this._hue = h;
297
+ this._sat = s;
298
+ this._val = v;
299
+ this._syncInputs();
300
+ this._view = 'picker';
301
+ }
302
+ _syncInputs() {
303
+ const [r, g, b] = hsvToRgb(this._hue, this._sat, this._val);
304
+ const hex = rgbToHex(r, g, b);
305
+ this._hexInput = hex;
306
+ this._r = r;
307
+ this._g = g;
308
+ this._b = b;
309
+ this._pendingColor = hex;
310
+ }
311
+ _drawSV() {
312
+ const canvas = this._svCanvas;
313
+ if (!canvas)
314
+ return;
315
+ const ctx = canvas.getContext('2d');
316
+ if (!ctx)
317
+ return;
318
+ const { width: w, height: h } = canvas;
319
+ const [hr, hg, hb] = hsvToRgb(this._hue, 1, 1);
320
+ ctx.fillStyle = `rgb(${hr},${hg},${hb})`;
321
+ ctx.fillRect(0, 0, w, h);
322
+ const wg = ctx.createLinearGradient(0, 0, w, 0);
323
+ wg.addColorStop(0, 'rgba(255,255,255,1)');
324
+ wg.addColorStop(1, 'rgba(255,255,255,0)');
325
+ ctx.fillStyle = wg;
326
+ ctx.fillRect(0, 0, w, h);
327
+ const bg = ctx.createLinearGradient(0, 0, 0, h);
328
+ bg.addColorStop(0, 'rgba(0,0,0,0)');
329
+ bg.addColorStop(1, 'rgba(0,0,0,1)');
330
+ ctx.fillStyle = bg;
331
+ ctx.fillRect(0, 0, w, h);
332
+ }
333
+ _drawHue() {
334
+ const canvas = this._hueCanvas;
335
+ if (!canvas)
336
+ return;
337
+ const ctx = canvas.getContext('2d');
338
+ if (!ctx)
339
+ return;
340
+ const grad = ctx.createLinearGradient(0, 0, canvas.width, 0);
341
+ ['#FF0000', '#FFFF00', '#00FF00', '#00FFFF', '#0000FF', '#FF00FF', '#FF0000']
342
+ .forEach((c, i, a) => grad.addColorStop(i / (a.length - 1), c));
343
+ ctx.fillStyle = grad;
344
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
345
+ }
346
+ _commitPickerIfNoActions() {
347
+ if (this.showActions)
348
+ return;
349
+ this._apply(this._pendingColor);
350
+ if (this.mode === 'popover') {
351
+ if (this.type === 'swatches')
352
+ this._view = 'swatches';
353
+ this._closePopover();
354
+ }
355
+ }
356
+ _updateSV(e) {
357
+ const canvas = this._svCanvas;
358
+ if (!canvas)
359
+ return;
360
+ const rect = canvas.getBoundingClientRect();
361
+ this._sat = Math.max(0, Math.min(e.clientX - rect.left, rect.width)) / rect.width;
362
+ this._val = 1 - Math.max(0, Math.min(e.clientY - rect.top, rect.height)) / rect.height;
363
+ this._syncInputs();
364
+ }
365
+ _updateHue(e) {
366
+ const canvas = this._hueCanvas;
367
+ if (!canvas)
368
+ return;
369
+ const rect = canvas.getBoundingClientRect();
370
+ this._hue = (Math.max(0, Math.min(e.clientX - rect.left, rect.width)) / rect.width) * 360;
371
+ this._syncInputs();
372
+ }
373
+ _renderSwatch(entry) {
374
+ const norm = this._norm(entry.color);
375
+ const isActive = this._norm(this.value) === norm;
376
+ const tip = this.swatchTooltip === 'name'
377
+ ? (entry.name || norm)
378
+ : this.swatchTooltip === 'value'
379
+ ? norm
380
+ : entry.name ? `${entry.name} (${norm})` : norm;
381
+ return html `
382
+ <nile-lite-tooltip content=${tip}>
383
+ <nile-color-swatch
384
+ color=${norm}
385
+ ?active=${isActive}
386
+ @click=${() => this._apply(norm)}
387
+ ></nile-color-swatch>
388
+ </nile-lite-tooltip>
389
+ `;
390
+ }
391
+ _renderSwatchesView() {
392
+ const recent = this._recentColors.slice(0, this.recentColorsCount);
393
+ return html `
394
+ <div class="ncp-panel">
395
+ <div class="ncp-palette-grid">
396
+ ${this._paletteColors.map(e => this._renderSwatch(e))}
397
+ </div>
398
+
399
+ ${this.noFill ? html `
400
+ <button class="ncp-no-fill" @click=${() => this._emit('none')}>
401
+ <nile-glyph name="disabled"></nile-glyph>
402
+ <span>No Fill</span>
403
+ </button>
404
+ ` : nothing}
405
+
406
+ <div class="ncp-custom-section">
407
+ <p class="ncp-custom-title">Custom</p>
408
+ <div class="ncp-custom-row">
409
+ ${recent.map(e => this._renderSwatch(e))}
410
+ <nile-lite-tooltip content="Add custom color">
411
+ <button class="ncp-action-btn" @click=${() => this._openPicker()}>
412
+ <nile-glyph name="plus"></nile-glyph>
413
+ </button>
414
+ </nile-lite-tooltip>
415
+ <nile-lite-tooltip content="Pick from screen">
416
+ <button class="ncp-action-btn" @click=${this._pickEyedropper}>
417
+ <nile-glyph name="colorize" size="12"></nile-glyph>
418
+ </button>
419
+ </nile-lite-tooltip>
420
+ </div>
421
+ </div>
422
+ </div>
423
+ `;
424
+ }
425
+ _renderPickerView() {
426
+ const svX = this._sat * 100;
427
+ const svY = (1 - this._val) * 100;
428
+ const hueX = (this._hue / 360) * 100;
429
+ return html `
430
+ <div class="ncp-panel ncp-panel--picker">
431
+
432
+ ${this.showCanvas ? html `
433
+ <div class="ncp-sv-area" @mousedown=${this._onSVMouseDown}>
434
+ <canvas class="ncp-sv-canvas" width="244" height="130"></canvas>
435
+ <div class="ncp-sv-thumb" style="left:${svX}%;top:${svY}%">
436
+ <div class="ncp-sv-thumb-inner"></div>
437
+ </div>
438
+ </div>
439
+ ` : nothing}
440
+
441
+ ${this.showHue ? html `
442
+ <div class="ncp-hue-row">
443
+ <div class="ncp-hue-wrap" @mousedown=${this._onHueMouseDown}>
444
+ <canvas class="ncp-hue-canvas" width="244" height="14"></canvas>
445
+ <div class="ncp-hue-thumb" style="left:${hueX}%"></div>
446
+ </div>
447
+ <button class="ncp-eyedropper" title="Pick from screen" @click=${this._pickEyedropper}>
448
+ <nile-glyph name="colorize" size="16"></nile-glyph>
449
+ </button>
450
+ </div>
451
+ ` : nothing}
452
+
453
+ ${this.showInputs ? html `
454
+ <div class="ncp-input-row">
455
+ <nile-dropdown class="ncp-mode-dropdown" placement="bottom-start" distance="4" hoist>
456
+ <nile-button slot="trigger" class="ncp-mode-btn" variant="tertiary">
457
+ ${this._colorMode} <nile-icon name="arrowdown" size="12"></nile-icon>
458
+ </nile-button>
459
+ <nile-menu @nile-select=${this._onColorModeSelect}>
460
+ <nile-menu-item value="HEX" ?active=${this._colorMode === 'HEX'}>HEX</nile-menu-item>
461
+ <nile-menu-item value="RGB" ?active=${this._colorMode === 'RGB'}>RGB</nile-menu-item>
462
+ </nile-menu>
463
+ </nile-dropdown>
464
+ ${this._colorMode === 'HEX'
465
+ ? html `<nile-input class="ncp-hex" .value=${this._hexInput} @nile-input=${this._onHexInput}></nile-input>`
466
+ : html `
467
+ <nile-input class="ncp-rgb" type="number" min="0" max="255" .value=${String(this._r)} @nile-input=${(e) => this._onRgbInput('r', e)}></nile-input>
468
+ <nile-input class="ncp-rgb" type="number" min="0" max="255" .value=${String(this._g)} @nile-input=${(e) => this._onRgbInput('g', e)}></nile-input>
469
+ <nile-input class="ncp-rgb" type="number" min="0" max="255" .value=${String(this._b)} @nile-input=${(e) => this._onRgbInput('b', e)}></nile-input>
470
+ `}
471
+ </div>
472
+ ` : nothing}
473
+
474
+ ${this.showActions ? html `
475
+ <div class="ncp-picker-actions">
476
+ ${this.type === 'swatches'
477
+ ? html `<nile-button variant="secondary" size="small" @click=${() => { this._view = 'swatches'; }}>Cancel</nile-button>`
478
+ : nothing}
479
+ <nile-button variant="primary" size="small" @click=${() => { this._apply(this._pendingColor); if (this.type === 'swatches')
480
+ this._view = 'swatches'; this._closePopover(); }}>Okay</nile-button>
481
+ </div>
482
+ ` : nothing}
483
+
484
+ </div>
485
+ `;
486
+ }
487
+ _renderTrigger() {
488
+ const isNoFill = this.value === 'none';
489
+ const displayColor = isNoFill ? null : this._norm(this.value);
490
+ return html `
491
+ <button
492
+ slot="anchor"
493
+ class="ncp-trigger${isNoFill ? ' ncp-trigger--no-fill' : ''}"
494
+ type="button"
495
+ aria-label=${isNoFill ? 'No Fill' : displayColor}
496
+ style=${isNoFill ? '' : `background:${displayColor}`}
497
+ ></button>
498
+ `;
499
+ }
500
+ render() {
501
+ const panel = this._view === 'picker' ? this._renderPickerView() : this._renderSwatchesView();
502
+ if (this.mode === 'popover') {
503
+ return html `
504
+ <nile-popover
505
+ .arrow=${false}
506
+ flip
507
+ .open=${this.open}
508
+ placement="bottom-start"
509
+ id="color-picker-popover"
510
+ distance="8"
511
+ @nile-hide=${() => this.reset()}
512
+ >
513
+ ${this._renderTrigger()}
514
+ ${panel}
515
+ </nile-popover>
516
+ `;
517
+ }
518
+ return panel;
519
+ }
520
+ };
521
+ __decorate([
522
+ property({ type: String, attribute: true, reflect: true })
523
+ ], NileColorPicker.prototype, "type", void 0);
524
+ __decorate([
525
+ property({ type: String, attribute: true, reflect: true })
526
+ ], NileColorPicker.prototype, "value", void 0);
527
+ __decorate([
528
+ property({ type: String, reflect: true })
529
+ ], NileColorPicker.prototype, "swatchTooltip", void 0);
530
+ __decorate([
531
+ property({ type: Number, reflect: true })
532
+ ], NileColorPicker.prototype, "recentColorsCount", void 0);
533
+ __decorate([
534
+ property({ type: Boolean, reflect: true })
535
+ ], NileColorPicker.prototype, "noFill", void 0);
536
+ __decorate([
537
+ property({ type: String, reflect: true })
538
+ ], NileColorPicker.prototype, "mode", void 0);
539
+ __decorate([
540
+ property({ type: Boolean, reflect: true })
541
+ ], NileColorPicker.prototype, "showCanvas", void 0);
542
+ __decorate([
543
+ property({ type: Boolean, reflect: true })
544
+ ], NileColorPicker.prototype, "showHue", void 0);
545
+ __decorate([
546
+ property({ type: Boolean, reflect: true })
547
+ ], NileColorPicker.prototype, "showInputs", void 0);
548
+ __decorate([
549
+ property({ type: Boolean, reflect: true })
550
+ ], NileColorPicker.prototype, "showActions", void 0);
551
+ __decorate([
552
+ property({ type: Boolean, reflect: true, attribute: true })
553
+ ], NileColorPicker.prototype, "open", void 0);
554
+ __decorate([
555
+ property({
556
+ attribute: 'palette',
557
+ converter: {
558
+ fromAttribute: (value) => {
559
+ try {
560
+ const parsed = JSON.parse(value);
561
+ if (!Array.isArray(parsed))
562
+ return [];
563
+ return parsed.map((e) => {
564
+ if (typeof e === 'string')
565
+ return { color: e, name: e };
566
+ if (e && typeof e.color === 'string')
567
+ return { color: e.color, name: e.name || e.color };
568
+ return null;
569
+ }).filter(Boolean);
570
+ }
571
+ catch {
572
+ return [];
573
+ }
574
+ },
575
+ toAttribute: (v) => JSON.stringify(v),
576
+ },
577
+ })
578
+ ], NileColorPicker.prototype, "palette", void 0);
579
+ __decorate([
580
+ state()
581
+ ], NileColorPicker.prototype, "_view", void 0);
582
+ __decorate([
583
+ state()
584
+ ], NileColorPicker.prototype, "_recentColors", void 0);
585
+ __decorate([
586
+ state()
587
+ ], NileColorPicker.prototype, "_hue", void 0);
588
+ __decorate([
589
+ state()
590
+ ], NileColorPicker.prototype, "_sat", void 0);
591
+ __decorate([
592
+ state()
593
+ ], NileColorPicker.prototype, "_val", void 0);
594
+ __decorate([
595
+ state()
596
+ ], NileColorPicker.prototype, "_colorMode", void 0);
597
+ __decorate([
598
+ state()
599
+ ], NileColorPicker.prototype, "_hexInput", void 0);
600
+ __decorate([
601
+ state()
602
+ ], NileColorPicker.prototype, "_r", void 0);
603
+ __decorate([
604
+ state()
605
+ ], NileColorPicker.prototype, "_g", void 0);
606
+ __decorate([
607
+ state()
608
+ ], NileColorPicker.prototype, "_b", void 0);
609
+ NileColorPicker = __decorate([
610
+ customElement('nile-color-picker')
611
+ ], NileColorPicker);
612
+ export { NileColorPicker };
613
+ //# sourceMappingURL=nile-color-picker.js.map