@sequent-org/moodboard 1.2.78 → 1.2.80

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.78",
3
+ "version": "1.2.80",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
@@ -30,6 +30,21 @@ export class HtmlHandlesLayer {
30
30
  this.layer.className = 'moodboard-html-handles';
31
31
  this.container.appendChild(this.layer);
32
32
 
33
+ // Обновление при изменении размеров окна/масштаба (DPR)
34
+ window.addEventListener('resize', () => this.update(), { passive: true });
35
+ // Некоторые браузеры меняют devicePixelRatio без resize — страхуемся
36
+ if (typeof window !== 'undefined' && 'matchMedia' in window) {
37
+ try {
38
+ // media-query, реагирующая на изменение DPR
39
+ const mq = window.matchMedia(`(resolution: ${window.devicePixelRatio || 1}dppx)`);
40
+ if (mq && mq.addEventListener) {
41
+ mq.addEventListener('change', () => this.update());
42
+ } else if (mq && mq.addListener) {
43
+ mq.addListener(() => this.update());
44
+ }
45
+ } catch (_) {}
46
+ }
47
+
33
48
  // Подписки: обновлять при изменениях выбора и трансформациях
34
49
  this.eventBus.on(Events.Tool.SelectionAdd, () => this.update());
35
50
  this.eventBus.on(Events.Tool.SelectionRemove, () => this.update());
@@ -185,8 +200,8 @@ export class HtmlHandlesLayer {
185
200
  _showBounds(worldBounds, id) {
186
201
  if (!this.layer) return;
187
202
  // Преобразуем world координаты в CSS-пиксели
188
- const res = (this.core.pixi.app.renderer?.resolution) || 1;
189
203
  const view = this.core.pixi.app.view;
204
+ const res = (this.core.pixi.app.renderer?.resolution) || 1;
190
205
  const containerRect = this.container.getBoundingClientRect();
191
206
  const viewRect = view.getBoundingClientRect();
192
207
  const offsetLeft = viewRect.left - containerRect.left;
@@ -209,11 +224,13 @@ export class HtmlHandlesLayer {
209
224
  isFrameTarget = mbType === 'frame';
210
225
  }
211
226
 
212
- // Вычисляем позицию и размер в CSS координатах, округляем до целых px
213
- const cssX = offsetLeft + (worldX + worldBounds.x * worldScale) / res;
214
- const cssY = offsetTop + (worldY + worldBounds.y * worldScale) / res;
215
- const cssWidth = Math.max(1, (worldBounds.width * worldScale) / res);
216
- const cssHeight = Math.max(1, (worldBounds.height * worldScale) / res);
227
+ // Вычисляем позицию и размер через математику сцены (toGlobal) и переводим в CSS px
228
+ const tl = world.toGlobal(new PIXI.Point(worldBounds.x, worldBounds.y));
229
+ const br = world.toGlobal(new PIXI.Point(worldBounds.x + worldBounds.width, worldBounds.y + worldBounds.height));
230
+ const cssX = offsetLeft + (tl.x / res);
231
+ const cssY = offsetTop + (tl.y / res);
232
+ const cssWidth = Math.max(1, (br.x - tl.x) / res);
233
+ const cssHeight = Math.max(1, (br.y - tl.y) / res);
217
234
 
218
235
  const left = Math.round(cssX);
219
236
  const top = Math.round(cssY);