@sequent-org/moodboard 1.2.98 → 1.2.100

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.98",
3
+ "version": "1.2.100",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
@@ -2688,15 +2688,23 @@ export class SelectTool extends BaseTool {
2688
2688
  try {
2689
2689
  const view = this.app?.view;
2690
2690
  const worldLayerRef = this.textEditor.world || (this.app?.stage);
2691
- const viewRes = (this.app?.renderer?.resolution) || (view && view.width && view.clientWidth ? (view.width / view.clientWidth) : 1);
2692
2691
  const cssLeft = this.textEditor._cssLeftPx;
2693
2692
  const cssTop = this.textEditor._cssTopPx;
2694
- if (isFinite(cssLeft) && isFinite(cssTop) && worldLayerRef) {
2693
+ if (view && view.parentElement && isFinite(cssLeft) && isFinite(cssTop) && worldLayerRef) {
2695
2694
  // Ждем один тик, чтобы HtmlTextLayer успел обновить DOM
2696
2695
  setTimeout(() => {
2697
2696
  try {
2698
- const desiredGlobal = new PIXI.Point(Math.round(cssLeft * viewRes), Math.round(cssTop * viewRes));
2699
- const desiredWorld = worldLayerRef.toLocal(desiredGlobal);
2697
+ // Инвертируем ту же трансформацию, что использует HtmlHandlesLayer/HtmlTextLayer:
2698
+ // world toGlobal → offset → CSS px
2699
+ const containerRect = view.parentElement.getBoundingClientRect();
2700
+ const viewRect = view.getBoundingClientRect();
2701
+ const offsetLeft = viewRect.left - containerRect.left;
2702
+ const offsetTop = viewRect.top - containerRect.top;
2703
+ // CSS → экранные координаты внутри canvas
2704
+ const screenX = cssLeft - offsetLeft;
2705
+ const screenY = cssTop - offsetTop;
2706
+ // Экранные → мировые координаты через toLocal
2707
+ const desiredWorld = worldLayerRef.toLocal(new PIXI.Point(screenX, screenY));
2700
2708
  const newPos = { x: Math.round(desiredWorld.x), y: Math.round(desiredWorld.y) };
2701
2709
  this.eventBus.emit(Events.Object.StateChanged, {
2702
2710
  objectId,
@@ -259,7 +259,7 @@ export class HtmlTextLayer {
259
259
  if (!el || !this.core) return;
260
260
 
261
261
  console.log(`🔍 HtmlTextLayer: обновляю позицию для текста ${objectId}`);
262
-
262
+
263
263
  const world = this.core.pixi.worldLayer || this.core.pixi.app.stage;
264
264
  const s = world?.scale?.x || 1;
265
265
  const tx = world?.x || 0;
@@ -309,7 +309,12 @@ export class HtmlTextLayer {
309
309
  // Позиция и габариты в CSS координатах - используем тот же подход что в HtmlHandlesLayer
310
310
  const worldLayer = this.core.pixi.worldLayer || this.core.pixi.app.stage;
311
311
  const view = this.core.pixi.app.view;
312
-
312
+ // Эти переменные нужны и для лога ниже, поэтому задаём их тут
313
+ let logLeft = 0;
314
+ let logTop = 0;
315
+ let logWidth = 0;
316
+ let logHeight = 0;
317
+
313
318
  if (worldLayer && view && view.parentElement) {
314
319
  const containerRect = view.parentElement.getBoundingClientRect();
315
320
  const viewRect = view.getBoundingClientRect();
@@ -319,19 +324,27 @@ export class HtmlTextLayer {
319
324
  // Преобразуем мировые координаты в экранные через toGlobal
320
325
  const tl = worldLayer.toGlobal(new PIXI.Point(x, y));
321
326
  const br = worldLayer.toGlobal(new PIXI.Point(x + w, y + h));
322
-
323
- // CSS координаты с учетом offset
324
- const left = offsetLeft + tl.x;
325
- const top = offsetTop + tl.y;
326
- const width = Math.max(1, br.x - tl.x);
327
- const height = Math.max(1, br.y - tl.y);
328
-
327
+
328
+ // toGlobal() возвращает координаты в device-пикселях с учётом resolution.
329
+ // Для CSS нам нужны логические пиксели, поэтому делим на res.
330
+ const left = offsetLeft + tl.x / res;
331
+ const top = offsetTop + tl.y / res;
332
+ const width = Math.max(1, (br.x - tl.x) / res);
333
+ const height = Math.max(1, (br.y - tl.y) / res);
334
+
335
+ // Применяем к элементу
329
336
  el.style.left = `${left}px`;
330
337
  el.style.top = `${top}px`;
331
338
  if (w && h) {
332
339
  el.style.width = `${width}px`;
333
340
  el.style.height = `${height}px`;
334
341
  }
342
+
343
+ // Значения для лога
344
+ logLeft = left;
345
+ logTop = top;
346
+ logWidth = width;
347
+ logHeight = height;
335
348
  } else {
336
349
  // Fallback к старому методу
337
350
  const left = (tx + s * x) / res;
@@ -339,9 +352,15 @@ export class HtmlTextLayer {
339
352
  el.style.left = `${left}px`;
340
353
  el.style.top = `${top}px`;
341
354
  if (w && h) {
342
- el.style.width = `${Math.max(1, (w * s) / res)}px`;
343
- el.style.height = `${Math.max(1, (h * s) / res)}px`;
355
+ const cssW = Math.max(1, (w * s) / res);
356
+ const cssH = Math.max(1, (h * s) / res);
357
+ el.style.width = `${cssW}px`;
358
+ el.style.height = `${cssH}px`;
359
+ logWidth = cssW;
360
+ logHeight = cssH;
344
361
  }
362
+ logLeft = left;
363
+ logTop = top;
345
364
  }
346
365
  // Поворот вокруг центра (как у PIXI и HTML-ручек)
347
366
  el.style.transformOrigin = 'center center';
@@ -357,15 +376,19 @@ export class HtmlTextLayer {
357
376
  try {
358
377
  el.style.height = 'auto';
359
378
  // Добавим небольшой нижний отступ для хвостов букв, чтобы не отсекались (например, у «з»)
360
- const h = Math.max(1, Math.round(el.scrollHeight + 2));
361
- el.style.height = `${h}px`;
379
+ const hCss = Math.max(1, Math.round(el.scrollHeight + 2));
380
+ el.style.height = `${hCss}px`;
381
+ // Обновим высоту для лога, если её ещё не устанавливали
382
+ if (!logHeight) {
383
+ logHeight = hCss;
384
+ }
362
385
  } catch (_) {}
363
386
 
364
387
  console.log(`🔍 HtmlTextLayer: позиция обновлена для ${objectId}:`, {
365
- left: `${left}px`,
366
- top: `${top}px`,
367
- width: `${Math.max(1, (w * s) / res)}px`,
368
- height: `${Math.max(1, (h * s) / res)}px`,
388
+ left: `${logLeft}px`,
389
+ top: `${logTop}px`,
390
+ width: `${logWidth}px`,
391
+ height: `${logHeight}px`,
369
392
  fontSize: `${fontSizePx}px`,
370
393
  content: content,
371
394
  visibility: el.style.visibility,