@sequent-org/moodboard 1.2.79 → 1.2.81

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.79",
3
+ "version": "1.2.81",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
@@ -201,11 +201,7 @@ export class HtmlHandlesLayer {
201
201
  if (!this.layer) return;
202
202
  // Преобразуем world координаты в CSS-пиксели
203
203
  const view = this.core.pixi.app.view;
204
- // Динамически вычисляем фактическое соотношение пикселей canvas/CSS,
205
- // чтобы корректно работать при зуме браузера
206
- const res = (view && view.width && view.clientWidth)
207
- ? (view.width / view.clientWidth)
208
- : (this.core.pixi.app.renderer?.resolution || 1);
204
+ const rendererRes = (this.core.pixi.app.renderer?.resolution) || 1;
209
205
  const containerRect = this.container.getBoundingClientRect();
210
206
  const viewRect = view.getBoundingClientRect();
211
207
  const offsetLeft = viewRect.left - containerRect.left;
@@ -228,11 +224,15 @@ export class HtmlHandlesLayer {
228
224
  isFrameTarget = mbType === 'frame';
229
225
  }
230
226
 
231
- // Вычисляем позицию и размер в CSS координатах, округляем до целых px
232
- const cssX = offsetLeft + (worldX + worldBounds.x * worldScale) / res;
233
- const cssY = offsetTop + (worldY + worldBounds.y * worldScale) / res;
234
- const cssWidth = Math.max(1, (worldBounds.width * worldScale) / res);
235
- 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
+ // Отношение пикселей canvas к CSS-пикселям (устойчиво к зуму браузера и autoDensity)
231
+ const pxPerCss = (view && view.width && viewRect.width) ? (view.width / viewRect.width) : rendererRes;
232
+ const cssX = offsetLeft + (tl.x / pxPerCss);
233
+ const cssY = offsetTop + (tl.y / pxPerCss);
234
+ const cssWidth = Math.max(1, (br.x - tl.x) / pxPerCss);
235
+ const cssHeight = Math.max(1, (br.y - tl.y) / pxPerCss);
236
236
 
237
237
  const left = Math.round(cssX);
238
238
  const top = Math.round(cssY);
@@ -394,10 +394,9 @@ export class HtmlHandlesLayer {
394
394
  const world = this.core.pixi.worldLayer || this.core.pixi.app.stage;
395
395
  const s = world?.scale?.x || 1;
396
396
  const view = this.core.pixi.app.view;
397
- const res = (view && view.width && view.clientWidth)
398
- ? (view.width / view.clientWidth)
399
- : (this.core.pixi.app.renderer?.resolution || 1);
400
- return { dxWorld: (dx * res) / s, dyWorld: (dy * res) / s };
397
+ const viewRect = view.getBoundingClientRect();
398
+ const pxPerCss = (view && view.width && viewRect.width) ? (view.width / viewRect.width) : ((this.core.pixi.app.renderer?.resolution) || 1);
399
+ return { dxWorld: (dx * pxPerCss) / s, dyWorld: (dy * pxPerCss) / s };
401
400
  }
402
401
 
403
402
  _onHandleDown(e, box) {
@@ -410,11 +409,9 @@ export class HtmlHandlesLayer {
410
409
  const tx = world?.x || 0;
411
410
  const ty = world?.y || 0;
412
411
  const view = this.core.pixi.app.view;
413
- const res = (view && view.width && view.clientWidth)
414
- ? (view.width / view.clientWidth)
415
- : (this.core.pixi.app.renderer?.resolution || 1);
416
- const containerRect = this.container.getBoundingClientRect();
417
412
  const viewRect = view.getBoundingClientRect();
413
+ const pxPerCss = (view && view.width && viewRect.width) ? (view.width / viewRect.width) : ((this.core.pixi.app.renderer?.resolution) || 1);
414
+ const containerRect = this.container.getBoundingClientRect();
418
415
  const offsetLeft = viewRect.left - containerRect.left;
419
416
  const offsetTop = viewRect.top - containerRect.top;
420
417
 
@@ -425,10 +422,10 @@ export class HtmlHandlesLayer {
425
422
  height: parseFloat(box.style.height),
426
423
  };
427
424
  const startScreen = {
428
- x: (startCSS.left - offsetLeft) * res,
429
- y: (startCSS.top - offsetTop) * res,
430
- w: startCSS.width * res,
431
- h: startCSS.height * res,
425
+ x: (startCSS.left - offsetLeft) * pxPerCss,
426
+ y: (startCSS.top - offsetTop) * pxPerCss,
427
+ w: startCSS.width * pxPerCss,
428
+ h: startCSS.height * pxPerCss,
432
429
  };
433
430
  const startWorld = {
434
431
  x: (startScreen.x - tx) / s,
@@ -571,10 +568,10 @@ export class HtmlHandlesLayer {
571
568
  this._repositionBoxChildren(box);
572
569
 
573
570
  // Перевод в мировые координаты
574
- const screenX = (newLeft - offsetLeft) * res;
575
- const screenY = (newTop - offsetTop) * res;
576
- const screenW = newW * res;
577
- const screenH = newH * res;
571
+ const screenX = (newLeft - offsetLeft) * pxPerCss;
572
+ const screenY = (newTop - offsetTop) * pxPerCss;
573
+ const screenW = newW * pxPerCss;
574
+ const screenH = newH * pxPerCss;
578
575
  const worldX = (screenX - tx) / s;
579
576
  const worldY = (screenY - ty) / s;
580
577
  const worldW = screenW / s;
@@ -619,10 +616,10 @@ export class HtmlHandlesLayer {
619
616
  width: parseFloat(box.style.width),
620
617
  height: parseFloat(box.style.height),
621
618
  };
622
- const screenX = (endCSS.left - offsetLeft) * res;
623
- const screenY = (endCSS.top - offsetTop) * res;
624
- const screenW = endCSS.width * res;
625
- const screenH = endCSS.height * res;
619
+ const screenX = (endCSS.left - offsetLeft) * pxPerCss;
620
+ const screenY = (endCSS.top - offsetTop) * pxPerCss;
621
+ const screenW = endCSS.width * pxPerCss;
622
+ const screenH = endCSS.height * pxPerCss;
626
623
  const worldX = (screenX - tx) / s;
627
624
  const worldY = (screenY - ty) / s;
628
625
  const worldW = screenW / s;
@@ -689,11 +686,9 @@ export class HtmlHandlesLayer {
689
686
  const tx = world?.x || 0;
690
687
  const ty = world?.y || 0;
691
688
  const view = this.core.pixi.app.view;
692
- const res = (view && view.width && view.clientWidth)
693
- ? (view.width / view.clientWidth)
694
- : (this.core.pixi.app.renderer?.resolution || 1);
695
- const containerRect = this.container.getBoundingClientRect();
696
689
  const viewRect = view.getBoundingClientRect();
690
+ const pxPerCss = (view && view.width && viewRect.width) ? (view.width / viewRect.width) : ((this.core.pixi.app.renderer?.resolution) || 1);
691
+ const containerRect = this.container.getBoundingClientRect();
697
692
  const offsetLeft = viewRect.left - containerRect.left;
698
693
  const offsetTop = viewRect.top - containerRect.top;
699
694
 
@@ -705,10 +700,10 @@ export class HtmlHandlesLayer {
705
700
  height: parseFloat(box.style.height),
706
701
  };
707
702
  const startScreen = {
708
- x: (startCSS.left - offsetLeft) * res,
709
- y: (startCSS.top - offsetTop) * res,
710
- w: startCSS.width * res,
711
- h: startCSS.height * res,
703
+ x: (startCSS.left - offsetLeft) * pxPerCss,
704
+ y: (startCSS.top - offsetTop) * pxPerCss,
705
+ w: startCSS.width * pxPerCss,
706
+ h: startCSS.height * pxPerCss,
712
707
  };
713
708
  const startWorld = {
714
709
  x: (startScreen.x - tx) / s,
@@ -836,10 +831,10 @@ export class HtmlHandlesLayer {
836
831
  this._repositionBoxChildren(box);
837
832
 
838
833
  // Перевод в мировые координаты
839
- const screenX = (newLeft - offsetLeft) * res;
840
- const screenY = (newTop - offsetTop) * res;
841
- const screenW = newW * res;
842
- const screenH = newH * res;
834
+ const screenX = (newLeft - offsetLeft) * pxPerCss;
835
+ const screenY = (newTop - offsetTop) * pxPerCss;
836
+ const screenW = newW * pxPerCss;
837
+ const screenH = newH * pxPerCss;
843
838
  const worldX = (screenX - tx) / s;
844
839
  const worldY = (screenY - ty) / s;
845
840
  const worldW = screenW / s;
@@ -873,10 +868,10 @@ export class HtmlHandlesLayer {
873
868
  width: parseFloat(box.style.width),
874
869
  height: parseFloat(box.style.height),
875
870
  };
876
- const screenX = (endCSS.left - offsetLeft) * res;
877
- const screenY = (endCSS.top - offsetTop) * res;
878
- const screenW = endCSS.width * res;
879
- const screenH = endCSS.height * res;
871
+ const screenX = (endCSS.left - offsetLeft) * pxPerCss;
872
+ const screenY = (endCSS.top - offsetTop) * pxPerCss;
873
+ const screenW = endCSS.width * pxPerCss;
874
+ const screenH = endCSS.height * pxPerCss;
880
875
  const worldX = (screenX - tx) / s;
881
876
  const worldY = (screenY - ty) / s;
882
877
  const worldW = screenW / s;
@@ -898,7 +893,7 @@ export class HtmlHandlesLayer {
898
893
  el.style.width = `${Math.max(1, Math.round(endCSS.width))}px`;
899
894
  el.style.height = 'auto';
900
895
  const measured = Math.max(1, Math.round(el.scrollHeight));
901
- finalWorldH = (measured * res) / s;
896
+ finalWorldH = (measured * pxPerCss) / s;
902
897
  }
903
898
  } catch (_) {}
904
899
  }