@sequent-org/moodboard 1.2.83 → 1.2.85

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.83",
3
+ "version": "1.2.85",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
@@ -7,10 +7,12 @@ export class BaseGrid {
7
7
  constructor(options = {}) {
8
8
  this.type = 'base';
9
9
  this.enabled = options.enabled ?? false;
10
- this.size = options.size || 20;
11
- this.color = options.color || 0xE0E0E0;
12
- this.opacity = options.opacity || 0.5;
13
- this.lineWidth = options.lineWidth || 1;
10
+ // Значения параметров визуала не задаём по умолчанию здесь.
11
+ // Они должны приходить из GridFactory.getDefaultOptions(type).
12
+ this.size = options.size;
13
+ this.color = options.color;
14
+ this.opacity = options.opacity;
15
+ this.lineWidth = options.lineWidth;
14
16
 
15
17
  // Размеры области отрисовки
16
18
  this.width = options.width || 1920;
@@ -18,7 +20,9 @@ export class BaseGrid {
18
20
 
19
21
  // PIXI графика
20
22
  this.graphics = new PIXI.Graphics();
21
- this.graphics.alpha = this.opacity;
23
+ if (typeof this.opacity === 'number') {
24
+ this.graphics.alpha = this.opacity;
25
+ }
22
26
 
23
27
  // Настройки привязки
24
28
  this.snapEnabled = options.snapEnabled ?? true;
@@ -9,14 +9,14 @@ export class LineGrid extends BaseGrid {
9
9
  this.type = 'line';
10
10
 
11
11
  // Дополнительные настройки для линейной сетки
12
- this.showSubGrid = options.showSubGrid ?? false;
13
- this.subGridDivisions = options.subGridDivisions || 4;
14
- this.subGridColor = options.subGridColor || 0xE3E3E3;
15
- this.subGridOpacity = options.subGridOpacity || 0.45;
16
- // Более тонкие основные линии и более контрастные
17
- this.lineWidth = Math.max(0.5, (options.lineWidth || this.lineWidth) / 2);
18
- this.color = options.color || 0xB0B0B0;
19
- this.opacity = options.opacity || 0.9;
12
+ // Параметры не задаём по умолчанию здесь — их поставляет GridFactory.
13
+ this.showSubGrid = options.showSubGrid;
14
+ this.subGridDivisions = options.subGridDivisions;
15
+ this.subGridColor = options.subGridColor;
16
+ this.subGridOpacity = options.subGridOpacity;
17
+ this.lineWidth = options.lineWidth;
18
+ this.color = options.color;
19
+ this.opacity = options.opacity;
20
20
  }
21
21
 
22
22
  /**
@@ -24,7 +24,9 @@ export class LineGrid extends BaseGrid {
24
24
  */
25
25
  createVisual() {
26
26
  // Применяем непрозрачность на графику (умножится на alpha линий)
27
- this.graphics.alpha = this.opacity;
27
+ if (typeof this.opacity === 'number') {
28
+ this.graphics.alpha = this.opacity;
29
+ }
28
30
  try {
29
31
  // В новых версиях можно указать alignment для большей чёткости
30
32
  this.graphics.lineStyle({ width: this.lineWidth, color: this.color, alpha: 1, alignment: 0.5 });
@@ -19,6 +19,7 @@ import { FilePropertiesPanel } from '../ui/FilePropertiesPanel.js';
19
19
  import { AlignmentGuides } from '../tools/AlignmentGuides.js';
20
20
  import { ImageUploadService } from '../services/ImageUploadService.js';
21
21
  import { SettingsApplier } from '../services/SettingsApplier.js';
22
+ import { GridFactory } from '../grid/GridFactory.js';
22
23
 
23
24
  /**
24
25
  * Готовый MoodBoard с UI - главный класс пакета
@@ -101,13 +102,6 @@ export class MoodBoard {
101
102
  // Инициализируем UI
102
103
  this.initToolbar();
103
104
  this.initTopbar();
104
- // Включаем дефолтную сетку (вариант 1 — line), если у доски нет сохранённой
105
- try {
106
- const savedGridType = this.coreMoodboard?.state?.state?.board?.grid?.type;
107
- if (!savedGridType && this.settingsApplier) {
108
- this.settingsApplier.apply({ grid: { type: 'line' } });
109
- }
110
- } catch (_) {}
111
105
  this.initZoombar();
112
106
  this.initMapbar();
113
107
  this.initContextMenu();
@@ -15,7 +15,8 @@ export class SettingsApplier {
15
15
 
16
16
  set(partial) {
17
17
  this.settings = { ...this.settings, ...(partial || {}) };
18
- this.apply(this.settings);
18
+ // Применяем только изменённые части, чтобы не трогать сетку при смене фона и наоборот
19
+ this.apply(partial || {});
19
20
  // Сообщаем системе об изменении настроек для автосохранения
20
21
  try {
21
22
  this.eventBus && this.eventBus.emit(Events.Grid.BoardDataChanged, { settings: this.get() });
@@ -26,12 +27,13 @@ export class SettingsApplier {
26
27
  return { ...this.settings };
27
28
  }
28
29
 
29
- apply(settings = {}) {
30
- this.settings = { ...this.settings, ...settings };
30
+ apply(partial = {}) {
31
+ // Копим полные настройки, но применяем только то, что пришло в partial
32
+ this.settings = { ...this.settings, ...partial };
31
33
  const s = this.settings;
32
34
 
33
35
  // 1) Фон
34
- if (s.backgroundColor && this.pixi?.app?.renderer) {
36
+ if (partial.backgroundColor && this.pixi?.app?.renderer) {
35
37
  const bgInt = this._toIntColor(s.backgroundColor);
36
38
  if (bgInt != null) this.pixi.app.renderer.backgroundColor = bgInt;
37
39
  // Синхронизация UI цвета (если доступен topbar)
@@ -43,17 +45,22 @@ export class SettingsApplier {
43
45
  }
44
46
  }
45
47
 
46
- // 2) Сетка
47
- if (s.grid && s.grid.type) {
48
+ // 2) Сетка — применяем только если grid пришёл в partial
49
+ if (partial.grid && s.grid && s.grid.type) {
48
50
  try {
49
51
  const payload = { type: s.grid.type };
50
- // Пробрасываем дополнительные опции, если есть
51
- const options = s.grid.options || {
52
- size: s.grid.size,
53
- color: this._maybeInt(s.grid.color),
54
- enabled: s.grid.visible !== false
55
- };
56
- if (options) payload.options = options;
52
+ // Пробрасываем только явно заданные опции, чтобы не затирать дефолты фабрики
53
+ const overrides = {};
54
+ if (s.grid.options && typeof s.grid.options === 'object') {
55
+ Object.keys(s.grid.options).forEach((k) => {
56
+ const v = s.grid.options[k];
57
+ if (v !== undefined) overrides[k] = k === 'color' ? this._maybeInt(v) : v;
58
+ });
59
+ }
60
+ if (s.grid.size !== undefined) overrides.size = s.grid.size;
61
+ if (s.grid.color !== undefined) overrides.color = this._maybeInt(s.grid.color);
62
+ if (s.grid.visible !== undefined) overrides.enabled = s.grid.visible !== false;
63
+ if (Object.keys(overrides).length > 0) payload.options = overrides;
57
64
  this.eventBus.emit(Events.UI.GridChange, payload);
58
65
  if (this.ui.topbar && s.grid.type) {
59
66
  this.ui.topbar.setActive(s.grid.type);
@@ -62,7 +69,7 @@ export class SettingsApplier {
62
69
  }
63
70
 
64
71
  // 3) Зум
65
- if (s.zoom && (typeof s.zoom.current === 'number')) {
72
+ if (partial.zoom && s.zoom && (typeof s.zoom.current === 'number')) {
66
73
  const world = this.pixi?.worldLayer || this.pixi?.app?.stage;
67
74
  if (world) {
68
75
  const z = Math.max(0.1, Math.min(5, s.zoom.current));
@@ -72,7 +79,7 @@ export class SettingsApplier {
72
79
  }
73
80
 
74
81
  // 4) Панорамирование (позиция мира)
75
- if (s.pan && typeof s.pan.x === 'number' && typeof s.pan.y === 'number') {
82
+ if (partial.pan && s.pan && typeof s.pan.x === 'number' && typeof s.pan.y === 'number') {
76
83
  const world = this.pixi?.worldLayer || this.pixi?.app?.stage;
77
84
  if (world) {
78
85
  world.x = s.pan.x;