@sequent-org/moodboard 1.2.55 → 1.2.57
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 -8
package/package.json
CHANGED
package/src/ui/Topbar.js
CHANGED
|
@@ -11,6 +11,7 @@ export class Topbar {
|
|
|
11
11
|
this.theme = theme;
|
|
12
12
|
this.element = null;
|
|
13
13
|
this._paintPopover = null;
|
|
14
|
+
this._currentBoardHex = null; // фактический цвет фона доски (#rrggbb)
|
|
14
15
|
// Загружаем иконки
|
|
15
16
|
this.iconLoader = new TopbarIconLoader();
|
|
16
17
|
this.icons = this.iconLoader.icons;
|
|
@@ -42,18 +43,31 @@ export class Topbar {
|
|
|
42
43
|
this.setActive(type);
|
|
43
44
|
});
|
|
44
45
|
|
|
45
|
-
// Обновляем цвет кнопки "краски" при выборе цвета фона
|
|
46
|
-
this.eventBus.on(Events.UI.PaintPick, ({ btnHex }) => {
|
|
47
|
-
|
|
48
|
-
|
|
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);
|
|
49
64
|
});
|
|
50
65
|
|
|
51
66
|
// Инициализация цвета кнопки "краска" из текущего фона доски, если доступен
|
|
52
67
|
try {
|
|
53
68
|
const bgHex = this._getCurrentBoardBackgroundHex();
|
|
54
69
|
if (bgHex) {
|
|
55
|
-
|
|
56
|
-
this.setPaintButtonHex(mapped);
|
|
70
|
+
this.setCurrentBoardHex(bgHex);
|
|
57
71
|
}
|
|
58
72
|
} catch (_) {}
|
|
59
73
|
}
|
|
@@ -176,7 +190,8 @@ export class Topbar {
|
|
|
176
190
|
/** Возвращает текущий цвет фона канваса как hex-строку #RRGGBB */
|
|
177
191
|
_getCurrentBoardBackgroundHex() {
|
|
178
192
|
try {
|
|
179
|
-
|
|
193
|
+
// Предпочтительно из CoreMoodBoard (актуальный путь в проекте)
|
|
194
|
+
const app = window?.moodboard?.coreMoodboard?.pixi?.app || window?.moodboard?.core?.pixi?.app;
|
|
180
195
|
const colorInt = app?.renderer?.background?.color ?? app?.renderer?.backgroundColor;
|
|
181
196
|
if (typeof colorInt !== 'number') return null;
|
|
182
197
|
const hex = `#${colorInt.toString(16).padStart(6, '0')}`;
|
|
@@ -201,6 +216,15 @@ export class Topbar {
|
|
|
201
216
|
}
|
|
202
217
|
}
|
|
203
218
|
|
|
219
|
+
/** Задать текущий фактический цвет фона и синхронизировать кнопку */
|
|
220
|
+
setCurrentBoardHex(boardHex) {
|
|
221
|
+
if (!boardHex) return;
|
|
222
|
+
const v = String(boardHex).toLowerCase();
|
|
223
|
+
this._currentBoardHex = v.startsWith('#') ? v : `#${v}`;
|
|
224
|
+
const mapped = this.mapBoardToBtnHex(this._currentBoardHex) || this._currentBoardHex;
|
|
225
|
+
this.setPaintButtonHex(mapped);
|
|
226
|
+
}
|
|
227
|
+
|
|
204
228
|
setActive(type) {
|
|
205
229
|
const buttons = this.element.querySelectorAll('.moodboard-topbar__button');
|
|
206
230
|
buttons.forEach((b) => b.classList.remove('moodboard-topbar__button--active'));
|
|
@@ -281,7 +305,7 @@ export class Topbar {
|
|
|
281
305
|
// Выделяем активный цвет галочкой (надежно — по data-board, с fallback ближайшего)
|
|
282
306
|
try {
|
|
283
307
|
// Текущий цвет фона доски (#rrggbb)
|
|
284
|
-
const currentBoardHex = (this._getCurrentBoardBackgroundHex() || '').toLowerCase();
|
|
308
|
+
const currentBoardHex = (this._currentBoardHex || this._getCurrentBoardBackgroundHex() || '').toLowerCase();
|
|
285
309
|
// Пытаемся найти точное совпадение по data-board
|
|
286
310
|
let match = currentBoardHex ? grid.querySelector(`[data-board="${currentBoardHex}"]`) : null;
|
|
287
311
|
// Если точного совпадения нет — выбираем ближайший по евклидовой дистанции в RGB
|