@sequent-org/moodboard 1.2.53 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/ui/Topbar.js +34 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequent-org/moodboard",
3
- "version": "1.2.53",
3
+ "version": "1.2.55",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
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
- // Для надёжного сравнения — сохраняем исходный hex в dataset
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,11 +278,37 @@ export class Topbar {
277
278
  });
278
279
  pop.appendChild(grid);
279
280
 
280
- // Выделяем активный цвет галочкой
281
+ // Выделяем активный цвет галочкой (надежно — по data-board, с fallback ближайшего)
281
282
  try {
282
- const boardHex = this._getCurrentBoardBackgroundHex();
283
- const targetHex = (this.mapBoardToBtnHex(boardHex) || '#B3E5FC').toLowerCase();
284
- const match = grid.querySelector(`[data-hex="${targetHex}"]`);
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;
311
+ }
285
312
  if (match) match.classList.add('is-active');
286
313
  } catch (_) {}
287
314
 
@@ -291,16 +318,7 @@ export class Topbar {
291
318
  pop.style.left = `${rect.left - this.element.getBoundingClientRect().left}px`;
292
319
  pop.style.top = `${rect.bottom - this.element.getBoundingClientRect().top + 6}px`;
293
320
 
294
- // Подсветить текущий активный кружок галочкой)
295
- try {
296
- const currentBtnHex = (this._paintBtn && getComputedStyle(this._paintBtn).getPropertyValue('--paint-btn-color')) || '';
297
- const normalized = currentBtnHex.trim() || '#B3E5FC';
298
- const match = Array.from(grid.children).find((el) => {
299
- const bg = el && el.style && el.style.background ? el.style.background.toLowerCase() : '';
300
- return bg === normalized.toLowerCase();
301
- });
302
- if (match) match.classList.add('is-active');
303
- } catch (_) {}
321
+ // (дополнительная подсветка не требуется активируем по data-hex выше)
304
322
 
305
323
  this.element.appendChild(pop);
306
324
  this._paintPopover = pop;