@sequent-org/moodboard 1.0.7 → 1.0.9

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.0.7",
3
+ "version": "1.0.9",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
@@ -17,7 +17,8 @@ export class PixiEngine {
17
17
  backgroundColor: this.options.backgroundColor,
18
18
  antialias: true,
19
19
  resolution: (typeof window !== 'undefined' && window.devicePixelRatio) ? window.devicePixelRatio : 1,
20
- autoDensity: true
20
+ autoDensity: true,
21
+ resizeTo: this.container // Автоматически изменять размер при изменении контейнера
21
22
  });
22
23
 
23
24
  this.container.appendChild(this.app.view);
@@ -433,6 +434,17 @@ export class PixiEngine {
433
434
  return null;
434
435
  }
435
436
 
437
+ /**
438
+ * Изменяет размер PIXI приложения
439
+ * @param {number} width - новая ширина
440
+ * @param {number} height - новая высота
441
+ */
442
+ resize(width, height) {
443
+ if (this.app && this.app.renderer) {
444
+ this.app.renderer.resize(width, height);
445
+ }
446
+ }
447
+
436
448
  destroy() {
437
449
  this.app.destroy(true);
438
450
  }
package/src/core/index.js CHANGED
@@ -36,6 +36,37 @@ export class CoreMoodBoard {
36
36
  backgroundColor: 0xF5F5F5,
37
37
  ...options
38
38
  };
39
+
40
+ // Устанавливаем размеры контейнера, если они не заданы
41
+ if (!this.options.width || this.options.width === 800) {
42
+ this.options.width = this.container.clientWidth || 800;
43
+ }
44
+ if (!this.options.height || this.options.height === 600) {
45
+ this.options.height = this.container.clientHeight || 600;
46
+ }
47
+
48
+ // Создаем ResizeObserver для отслеживания изменений размера контейнера
49
+ this.resizeObserver = null;
50
+ if (typeof ResizeObserver !== 'undefined') {
51
+ this.resizeObserver = new ResizeObserver((entries) => {
52
+ for (const entry of entries) {
53
+ const { width, height } = entry.contentRect;
54
+ if (this.pixi && this.pixi.app) {
55
+ // Обновляем размеры PIXI приложения
56
+ this.pixi.resize(width, height);
57
+ // Обновляем размеры в опциях
58
+ this.options.width = width;
59
+ this.options.height = height;
60
+ // Обновляем размеры рабочего пространства
61
+ if (this.workspaceManager) {
62
+ this.workspaceManager.updateSize();
63
+ }
64
+ // Уведомляем о изменении размера
65
+ this.eventBus.emit('resize', { width, height });
66
+ }
67
+ }
68
+ });
69
+ }
39
70
 
40
71
  this.eventBus = new EventBus();
41
72
  this.state = new StateManager(this.eventBus);
@@ -72,6 +103,11 @@ export class CoreMoodBoard {
72
103
  try {
73
104
  await this.pixi.init();
74
105
  this.keyboard.startListening(); // Запускаем прослушивание клавиатуры
106
+
107
+ // Запускаем отслеживание изменения размера контейнера
108
+ if (this.resizeObserver) {
109
+ this.resizeObserver.observe(this.container);
110
+ }
75
111
 
76
112
  // Инициализируем систему инструментов
77
113
  await this.initTools();
@@ -1623,6 +1659,12 @@ export class CoreMoodBoard {
1623
1659
  }
1624
1660
 
1625
1661
  destroy() {
1662
+ // Останавливаем отслеживание изменения размера
1663
+ if (this.resizeObserver) {
1664
+ this.resizeObserver.disconnect();
1665
+ this.resizeObserver = null;
1666
+ }
1667
+
1626
1668
  this.saveManager.destroy();
1627
1669
  this.keyboard.destroy();
1628
1670
  this.history.destroy();
@@ -322,6 +322,26 @@ export class MoodBoard {
322
322
  }
323
323
  }
324
324
 
325
+ /**
326
+ * Обновляет размеры холста
327
+ */
328
+ updateSize() {
329
+ if (this.workspaceManager) {
330
+ return this.workspaceManager.updateSize();
331
+ }
332
+ return null;
333
+ }
334
+
335
+ /**
336
+ * Получает текущие размеры холста
337
+ */
338
+ getSize() {
339
+ if (this.workspaceManager) {
340
+ return this.workspaceManager.getCanvasSize();
341
+ }
342
+ return { width: 800, height: 600 };
343
+ }
344
+
325
345
  /**
326
346
  * Очистка ресурсов
327
347
  */
@@ -83,12 +83,29 @@ export class WorkspaceManager {
83
83
  return { width: 800, height: 600 };
84
84
  }
85
85
 
86
+ // Получаем размеры родительского контейнера
87
+ const parentWidth = this.container.clientWidth;
88
+ const parentHeight = this.container.clientHeight;
89
+
86
90
  return {
87
- width: this.canvasContainer.clientWidth,
88
- height: this.canvasContainer.clientHeight
91
+ width: parentWidth || 800,
92
+ height: parentHeight || 600
89
93
  };
90
94
  }
91
95
 
96
+ /**
97
+ * Обновляет размеры рабочего пространства
98
+ */
99
+ updateSize() {
100
+ if (this.canvasContainer && this.container) {
101
+ const size = this.getCanvasSize();
102
+ this.canvasContainer.style.width = size.width + 'px';
103
+ this.canvasContainer.style.height = size.height + 'px';
104
+ return size;
105
+ }
106
+ return null;
107
+ }
108
+
92
109
  /**
93
110
  * Очистка ресурсов
94
111
  */
@@ -15,10 +15,9 @@
15
15
  }
16
16
 
17
17
  .moodboard-workspace {
18
- position: fixed;
19
- inset: 0;
20
- width: 100vw;
21
- height: 100vh;
18
+ position: relative;
19
+ width: 100%;
20
+ height: 100%;
22
21
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
23
22
  overflow: hidden;
24
23
  }
@@ -175,7 +174,10 @@
175
174
  /* Canvas Container */
176
175
  .moodboard-workspace__canvas {
177
176
  position: absolute;
178
- inset: 0;
177
+ top: 0;
178
+ left: 0;
179
+ right: 0;
180
+ bottom: 0;
179
181
  overflow: hidden;
180
182
  }
181
183