@sequent-org/moodboard 1.2.56 → 1.2.60

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequent-org/moodboard",
3
- "version": "1.2.56",
3
+ "version": "1.2.60",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
@@ -223,10 +223,6 @@ export class MoodBoard {
223
223
  : color;
224
224
  if (this.coreMoodboard?.pixi?.app?.renderer) {
225
225
  this.coreMoodboard.pixi.app.renderer.backgroundColor = hex;
226
- // Сигнализируем, что настройки доски изменились (для автосохранения)
227
- try {
228
- this.coreMoodboard.eventBus.emit(Events.Grid.BoardDataChanged, { settings: { backgroundColor: color } });
229
- } catch (_) {}
230
226
  }
231
227
  });
232
228
  }
@@ -32,12 +32,7 @@ export class ZoomPanController {
32
32
  world.scale.set(newScale);
33
33
  world.x = x - worldX * newScale;
34
34
  world.y = y - worldY * newScale;
35
- const pct = Math.round(newScale * 100);
36
- this.eventBus.emit(Events.UI.ZoomPercent, { percentage: pct });
37
- // Сигнализируем об изменении настроек (чтобы сохранить текущий зум)
38
- try {
39
- this.eventBus.emit(Events.Grid.BoardDataChanged, { settings: { zoom: { current: newScale, percentage: pct } } });
40
- } catch (_) {}
35
+ this.eventBus.emit(Events.UI.ZoomPercent, { percentage: Math.round(newScale * 100) });
41
36
  });
42
37
 
43
38
  // Кнопки зума из UI
package/src/ui/Topbar.js CHANGED
@@ -11,7 +11,6 @@ export class Topbar {
11
11
  this.theme = theme;
12
12
  this.element = null;
13
13
  this._paintPopover = null;
14
- this._currentBoardHex = null; // фактический цвет фона доски (#rrggbb)
15
14
  // Загружаем иконки
16
15
  this.iconLoader = new TopbarIconLoader();
17
16
  this.icons = this.iconLoader.icons;
@@ -37,37 +36,26 @@ export class Topbar {
37
36
 
38
37
  this.createTopbar();
39
38
  this.attachEvents();
39
+ // Активируем дефолтную кнопку (line) до прихода события из ядра
40
+ this.setActive('line');
40
41
 
41
42
  // Синхронизация активного состояния по событию из ядра
42
43
  this.eventBus.on(Events.UI.GridCurrent, ({ type }) => {
43
44
  this.setActive(type);
44
45
  });
45
46
 
46
- // Обновляем цвет кнопки "краски" и текущий board-hex при выборе цвета фона
47
- this.eventBus.on(Events.UI.PaintPick, ({ btnHex, color }) => {
48
- // color — фактический цвет фона доски (может быть #rrggbb или number)
49
- const normalizeHex = (v) => {
50
- if (!v) return null;
51
- if (typeof v === 'number') {
52
- return `#${v.toString(16).padStart(6,'0')}`.toLowerCase();
53
- }
54
- if (typeof v === 'string') {
55
- const s = v.startsWith('#') ? v : `#${v}`;
56
- return s.toLowerCase();
57
- }
58
- return null;
59
- };
60
- const boardHex = normalizeHex(color);
61
- if (boardHex) this._currentBoardHex = boardHex;
62
- const mapped = btnHex || this.mapBoardToBtnHex(boardHex);
63
- if (mapped) this.setPaintButtonHex(mapped);
47
+ // Обновляем цвет кнопки "краски" при выборе цвета фона
48
+ this.eventBus.on(Events.UI.PaintPick, ({ btnHex }) => {
49
+ if (!btnHex) return;
50
+ this.setPaintButtonHex(btnHex);
64
51
  });
65
52
 
66
53
  // Инициализация цвета кнопки "краска" из текущего фона доски, если доступен
67
54
  try {
68
55
  const bgHex = this._getCurrentBoardBackgroundHex();
69
56
  if (bgHex) {
70
- this.setCurrentBoardHex(bgHex);
57
+ const mapped = this.mapBoardToBtnHex(bgHex);
58
+ this.setPaintButtonHex(mapped);
71
59
  }
72
60
  } catch (_) {}
73
61
  }
@@ -215,15 +203,6 @@ export class Topbar {
215
203
  }
216
204
  }
217
205
 
218
- /** Задать текущий фактический цвет фона и синхронизировать кнопку */
219
- setCurrentBoardHex(boardHex) {
220
- if (!boardHex) return;
221
- const v = String(boardHex).toLowerCase();
222
- this._currentBoardHex = v.startsWith('#') ? v : `#${v}`;
223
- const mapped = this.mapBoardToBtnHex(this._currentBoardHex) || this._currentBoardHex;
224
- this.setPaintButtonHex(mapped);
225
- }
226
-
227
206
  setActive(type) {
228
207
  const buttons = this.element.querySelectorAll('.moodboard-topbar__button');
229
208
  buttons.forEach((b) => b.classList.remove('moodboard-topbar__button--active'));
@@ -276,9 +255,8 @@ export class Topbar {
276
255
  b.style.borderColor = darken(c.hex, 0.35);
277
256
  // Цвет галочки — чёрный для максимальной видимости
278
257
  b.style.color = '#111';
279
- // Для надёжного сравнения — сохраняем оба значения в dataset
280
- b.dataset.hex = String(c.hex).toLowerCase(); // цвет кружка-кнопки
281
- b.dataset.board = String(c.board).toLowerCase(); // фактический цвет фона доски
258
+ // Для надёжного сравнения — сохраняем исходный hex в dataset
259
+ b.dataset.hex = String(c.hex).toLowerCase();
282
260
  // Галочка по центру
283
261
  const tick = document.createElement('i');
284
262
  tick.className = 'moodboard-topbar__paint-tick';
@@ -301,37 +279,11 @@ export class Topbar {
301
279
  });
302
280
  pop.appendChild(grid);
303
281
 
304
- // Выделяем активный цвет галочкой (надежно — по data-board, с fallback ближайшего)
282
+ // Выделяем активный цвет галочкой
305
283
  try {
306
- // Текущий цвет фона доски (#rrggbb)
307
- const currentBoardHex = (this._currentBoardHex || this._getCurrentBoardBackgroundHex() || '').toLowerCase();
308
- // Пытаемся найти точное совпадение по data-board
309
- let match = currentBoardHex ? grid.querySelector(`[data-board="${currentBoardHex}"]`) : null;
310
- // Если точного совпадения нет — выбираем ближайший по евклидовой дистанции в RGB
311
- if (!match) {
312
- const hexToRgb = (hex) => {
313
- try {
314
- const h = hex.replace('#','');
315
- return {
316
- r: parseInt(h.substring(0,2), 16),
317
- g: parseInt(h.substring(2,4), 16),
318
- b: parseInt(h.substring(4,6), 16)
319
- };
320
- } catch (_) { return { r: 0, g: 0, b: 0 }; }
321
- };
322
- const dist2 = (a, b) => {
323
- const dr = a.r - b.r, dg = a.g - b.g, db = a.b - b.b;
324
- return dr*dr + dg*dg + db*db;
325
- };
326
- const target = hexToRgb(currentBoardHex || '#f7fbff');
327
- let best = null, bestD = Infinity;
328
- Array.from(grid.children).forEach((el) => {
329
- const boardHex = el.dataset.board || '';
330
- const d = dist2(target, hexToRgb(boardHex));
331
- if (d < bestD) { bestD = d; best = el; }
332
- });
333
- match = best;
334
- }
284
+ const boardHex = this._getCurrentBoardBackgroundHex();
285
+ const targetHex = (this.mapBoardToBtnHex(boardHex) || '#B3E5FC').toLowerCase();
286
+ const match = grid.querySelector(`[data-hex="${targetHex}"]`);
335
287
  if (match) match.classList.add('is-active');
336
288
  } catch (_) {}
337
289
 
@@ -341,7 +293,16 @@ export class Topbar {
341
293
  pop.style.left = `${rect.left - this.element.getBoundingClientRect().left}px`;
342
294
  pop.style.top = `${rect.bottom - this.element.getBoundingClientRect().top + 6}px`;
343
295
 
344
- // (дополнительная подсветка не требуется активируем по data-hex выше)
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 (_) {}
345
306
 
346
307
  this.element.appendChild(pop);
347
308
  this._paintPopover = pop;