@sequent-org/moodboard 1.2.61 → 1.2.63

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 +40 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequent-org/moodboard",
3
- "version": "1.2.61",
3
+ "version": "1.2.63",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
package/src/ui/Topbar.js CHANGED
@@ -37,7 +37,7 @@ export class Topbar {
37
37
  this.createTopbar();
38
38
  this.attachEvents();
39
39
  // Активируем дефолтную кнопку (line) до прихода события из ядра
40
- this.setActive('line');
40
+ // не подсвечиваем дефолт до прихода актуального типа из ядра
41
41
 
42
42
  // Синхронизация активного состояния по событию из ядра
43
43
  this.eventBus.on(Events.UI.GridCurrent, ({ type }) => {
@@ -50,11 +50,13 @@ export class Topbar {
50
50
  this.setPaintButtonHex(btnHex);
51
51
  });
52
52
 
53
- // Инициализация цвета кнопки "краска" из текущего фона доски, если доступен
53
+ // Инициализация цвета кнопки "краска" из настроек (или фона рендерера)
54
54
  try {
55
- const bgHex = this._getCurrentBoardBackgroundHex();
55
+ const ap = window?.moodboard?.coreMoodboard?.settingsApplier;
56
+ const bgHex = (ap && ap.get && ap.get().backgroundColor) || this._getCurrentBoardBackgroundHex();
56
57
  if (bgHex) {
57
- const mapped = this.mapBoardToBtnHex(bgHex);
58
+ this._currentBoardHex = String(bgHex).toLowerCase();
59
+ const mapped = this.mapBoardToBtnHex(this._currentBoardHex);
58
60
  this.setPaintButtonHex(mapped);
59
61
  }
60
62
  } catch (_) {}
@@ -178,7 +180,7 @@ export class Topbar {
178
180
  /** Возвращает текущий цвет фона канваса как hex-строку #RRGGBB */
179
181
  _getCurrentBoardBackgroundHex() {
180
182
  try {
181
- const app = window?.moodboard?.core?.pixi?.app;
183
+ const app = window?.moodboard?.coreMoodboard?.pixi?.app || window?.moodboard?.core?.pixi?.app;
182
184
  const colorInt = app?.renderer?.background?.color ?? app?.renderer?.backgroundColor;
183
185
  if (typeof colorInt !== 'number') return null;
184
186
  const hex = `#${colorInt.toString(16).padStart(6, '0')}`;
@@ -197,12 +199,32 @@ export class Topbar {
197
199
  setPaintButtonHex(btnHex) {
198
200
  if (!btnHex) return;
199
201
  if (this._paintBtn) {
200
- try { this._paintBtn.style.setProperty('--paint-btn-color', btnHex); } catch (_) {}
202
+ try {
203
+ this._paintBtn.style.setProperty('--paint-btn-color', btnHex);
204
+ // Прямое применение фона/бордера, чтобы цвет был виден сразу
205
+ this._paintBtn.style.background = btnHex;
206
+ const darker = this._darkenHex ? this._darkenHex(btnHex, 0.35) : btnHex;
207
+ this._paintBtn.style.borderColor = darker;
208
+ } catch (_) {}
201
209
  } else {
202
210
  this._pendingPaintHex = btnHex;
203
211
  }
204
212
  }
205
213
 
214
+ /** Утилита: затемнить hex-цвет на долю amount */
215
+ _darkenHex(hex, amount = 0.25) {
216
+ try {
217
+ const h = String(hex).replace('#','');
218
+ const r = parseInt(h.substring(0,2), 16);
219
+ const g = parseInt(h.substring(2,4), 16);
220
+ const b = parseInt(h.substring(4,6), 16);
221
+ const dr = Math.max(0, Math.min(255, Math.round(r * (1 - amount))));
222
+ const dg = Math.max(0, Math.min(255, Math.round(g * (1 - amount))));
223
+ const db = Math.max(0, Math.min(255, Math.round(b * (1 - amount))));
224
+ return `#${dr.toString(16).padStart(2,'0')}${dg.toString(16).padStart(2,'0')}${db.toString(16).padStart(2,'0')}`;
225
+ } catch (_) { return hex; }
226
+ }
227
+
206
228
  setActive(type) {
207
229
  const buttons = this.element.querySelectorAll('.moodboard-topbar__button');
208
230
  buttons.forEach((b) => b.classList.remove('moodboard-topbar__button--active'));
@@ -255,8 +277,9 @@ export class Topbar {
255
277
  b.style.borderColor = darken(c.hex, 0.35);
256
278
  // Цвет галочки — чёрный для максимальной видимости
257
279
  b.style.color = '#111';
258
- // Для надёжного сравнения — сохраняем исходный hex в dataset
280
+ // Для надёжного сравнения — сохраняем оба значения в dataset
259
281
  b.dataset.hex = String(c.hex).toLowerCase();
282
+ b.dataset.board = String(c.board).toLowerCase();
260
283
  // Галочка по центру
261
284
  const tick = document.createElement('i');
262
285
  tick.className = 'moodboard-topbar__paint-tick';
@@ -279,11 +302,16 @@ export class Topbar {
279
302
  });
280
303
  pop.appendChild(grid);
281
304
 
282
- // Выделяем активный цвет галочкой
305
+ // Выделяем активный цвет галочкой по фактическому boardHex
283
306
  try {
284
- const boardHex = this._getCurrentBoardBackgroundHex();
285
- const targetHex = (this.mapBoardToBtnHex(boardHex) || '#B3E5FC').toLowerCase();
286
- const match = grid.querySelector(`[data-hex="${targetHex}"]`);
307
+ const ap = window?.moodboard?.coreMoodboard?.settingsApplier;
308
+ const boardHex = (
309
+ (ap && ap.get && ap.get().backgroundColor) ||
310
+ this._currentBoardHex ||
311
+ this._getCurrentBoardBackgroundHex() ||
312
+ ''
313
+ ).toLowerCase();
314
+ const match = boardHex ? grid.querySelector(`[data-board="${boardHex}"]`) : null;
287
315
  if (match) match.classList.add('is-active');
288
316
  } catch (_) {}
289
317
 
@@ -293,16 +321,7 @@ export class Topbar {
293
321
  pop.style.left = `${rect.left - this.element.getBoundingClientRect().left}px`;
294
322
  pop.style.top = `${rect.bottom - this.element.getBoundingClientRect().top + 6}px`;
295
323
 
296
- // Подсветить текущий активный кружок галочкой)
297
- try {
298
- const currentBtnHex = (this._paintBtn && getComputedStyle(this._paintBtn).getPropertyValue('--paint-btn-color')) || '';
299
- const normalized = currentBtnHex.trim() || '#B3E5FC';
300
- const match = Array.from(grid.children).find((el) => {
301
- const bg = el && el.style && el.style.background ? el.style.background.toLowerCase() : '';
302
- return bg === normalized.toLowerCase();
303
- });
304
- if (match) match.classList.add('is-active');
305
- } catch (_) {}
324
+ // (дополнительная подсветка не требуется см. блок выше)
306
325
 
307
326
  this.element.appendChild(pop);
308
327
  this._paintPopover = pop;