@sequent-org/moodboard 1.2.54 → 1.2.55
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/package.json +1 -1
- package/src/ui/Topbar.js +32 -15
package/package.json
CHANGED
package/src/ui/Topbar.js
CHANGED
|
@@ -253,8 +253,9 @@ export class Topbar {
|
|
|
253
253
|
b.style.borderColor = darken(c.hex, 0.35);
|
|
254
254
|
// Цвет галочки — чёрный для максимальной видимости
|
|
255
255
|
b.style.color = '#111';
|
|
256
|
-
// Для надёжного сравнения — сохраняем
|
|
257
|
-
b.dataset.hex = String(c.hex).toLowerCase();
|
|
256
|
+
// Для надёжного сравнения — сохраняем оба значения в dataset
|
|
257
|
+
b.dataset.hex = String(c.hex).toLowerCase(); // цвет кружка-кнопки
|
|
258
|
+
b.dataset.board = String(c.board).toLowerCase(); // фактический цвет фона доски
|
|
258
259
|
// Галочка по центру
|
|
259
260
|
const tick = document.createElement('i');
|
|
260
261
|
tick.className = 'moodboard-topbar__paint-tick';
|
|
@@ -277,21 +278,37 @@ export class Topbar {
|
|
|
277
278
|
});
|
|
278
279
|
pop.appendChild(grid);
|
|
279
280
|
|
|
280
|
-
// Выделяем активный цвет галочкой (надежно — по data-
|
|
281
|
+
// Выделяем активный цвет галочкой (надежно — по data-board, с fallback ближайшего)
|
|
281
282
|
try {
|
|
282
|
-
//
|
|
283
|
-
const
|
|
284
|
-
//
|
|
285
|
-
let
|
|
286
|
-
//
|
|
287
|
-
if (!
|
|
288
|
-
const
|
|
289
|
-
|
|
283
|
+
// Текущий цвет фона доски (#rrggbb)
|
|
284
|
+
const currentBoardHex = (this._getCurrentBoardBackgroundHex() || '').toLowerCase();
|
|
285
|
+
// Пытаемся найти точное совпадение по data-board
|
|
286
|
+
let match = currentBoardHex ? grid.querySelector(`[data-board="${currentBoardHex}"]`) : null;
|
|
287
|
+
// Если точного совпадения нет — выбираем ближайший по евклидовой дистанции в RGB
|
|
288
|
+
if (!match) {
|
|
289
|
+
const hexToRgb = (hex) => {
|
|
290
|
+
try {
|
|
291
|
+
const h = hex.replace('#','');
|
|
292
|
+
return {
|
|
293
|
+
r: parseInt(h.substring(0,2), 16),
|
|
294
|
+
g: parseInt(h.substring(2,4), 16),
|
|
295
|
+
b: parseInt(h.substring(4,6), 16)
|
|
296
|
+
};
|
|
297
|
+
} catch (_) { return { r: 0, g: 0, b: 0 }; }
|
|
298
|
+
};
|
|
299
|
+
const dist2 = (a, b) => {
|
|
300
|
+
const dr = a.r - b.r, dg = a.g - b.g, db = a.b - b.b;
|
|
301
|
+
return dr*dr + dg*dg + db*db;
|
|
302
|
+
};
|
|
303
|
+
const target = hexToRgb(currentBoardHex || '#f7fbff');
|
|
304
|
+
let best = null, bestD = Infinity;
|
|
305
|
+
Array.from(grid.children).forEach((el) => {
|
|
306
|
+
const boardHex = el.dataset.board || '';
|
|
307
|
+
const d = dist2(target, hexToRgb(boardHex));
|
|
308
|
+
if (d < bestD) { bestD = d; best = el; }
|
|
309
|
+
});
|
|
310
|
+
match = best;
|
|
290
311
|
}
|
|
291
|
-
// 4) Фолбэк — первый цвет из палитры
|
|
292
|
-
if (!targetHex) targetHex = '#B3E5FC';
|
|
293
|
-
const normalized = String(targetHex).trim().toLowerCase();
|
|
294
|
-
const match = grid.querySelector(`[data-hex="${normalized}"]`);
|
|
295
312
|
if (match) match.classList.add('is-active');
|
|
296
313
|
} catch (_) {}
|
|
297
314
|
|