@sequent-org/moodboard 1.2.41 → 1.2.43

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.41",
3
+ "version": "1.2.43",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
@@ -1990,7 +1990,7 @@ export class SelectTool extends BaseTool {
1990
1990
  ];
1991
1991
  } else {
1992
1992
  // Для обычного текста используем стандартное позиционирование
1993
- // Динамически компенсируем внутренние отступы textarea, чтобы каретка оказалась ровно в точке клика
1993
+ // Динамически компенсируем внутренние отступы textarea для точного совпадения со статичным текстом
1994
1994
  let padTop = 0;
1995
1995
  let padLeft = 0;
1996
1996
  let lineHeightPx = 0;
@@ -2011,15 +2011,38 @@ export class SelectTool extends BaseTool {
2011
2011
  if (r && isFinite(r.height)) lineHeightPx = r.height;
2012
2012
  } catch (_) {}
2013
2013
  }
2014
- const leftPx = create ? Math.round(screenPos.x - padLeft) : Math.round(screenPos.x);
2015
- const topPx = create ? Math.round(screenPos.y - padTop - (lineHeightPx / 2)) : Math.round(screenPos.y);
2014
+
2015
+ // Базовая точка позиционирования: для редактирования берём точные координаты статичного HTML-текста,
2016
+ // для создания — используем рассчитанные screenPos
2017
+ let baseLeftPx = screenPos.x;
2018
+ let baseTopPx = screenPos.y;
2019
+ try {
2020
+ if (!create && objectId && typeof window !== 'undefined' && window.moodboardHtmlTextLayer) {
2021
+ const el = window.moodboardHtmlTextLayer.idToEl.get(objectId);
2022
+ if (el) {
2023
+ const cssLeft = parseFloat(el.style.left || 'NaN');
2024
+ const cssTop = parseFloat(el.style.top || 'NaN');
2025
+ if (isFinite(cssLeft)) baseLeftPx = cssLeft;
2026
+ if (isFinite(cssTop)) baseTopPx = cssTop;
2027
+ }
2028
+ }
2029
+ } catch (_) {}
2030
+
2031
+ const leftPx = Math.round(baseLeftPx - padLeft);
2032
+ const topPx = create
2033
+ ? Math.round(baseTopPx - padTop - (lineHeightPx / 2)) // по клику совмещаем центр строки с точкой клика
2034
+ : Math.round(baseTopPx - padTop); // при редактировании совмещаем верх контента
2016
2035
  wrapper.style.left = `${leftPx}px`;
2017
2036
  wrapper.style.top = `${topPx}px`;
2037
+ // Сохраняем CSS-позицию редактора для точной синхронизации при закрытии
2038
+ this.textEditor._cssLeftPx = leftPx;
2039
+ this.textEditor._cssTopPx = topPx;
2018
2040
  // Диагностика: логируем позицию инпута и вычисленные параметры позиционирования
2019
2041
  try {
2020
2042
  console.log('🧭 Text input', {
2021
2043
  input: { left: leftPx, top: topPx },
2022
2044
  screenPos,
2045
+ baseFromStatic: (!create && objectId) ? { left: baseLeftPx, top: baseTopPx } : null,
2023
2046
  padding: { top: padTop, left: padLeft },
2024
2047
  lineHeightPx,
2025
2048
  caretCenterY: create ? (topPx + padTop + (lineHeightPx / 2)) : topPx,
@@ -2592,6 +2615,29 @@ export class SelectTool extends BaseTool {
2592
2615
  const el = window.moodboardHtmlTextLayer.idToEl.get(objectId);
2593
2616
  if (el) {
2594
2617
  this.eventBus.emit(Events.Tool.ShowObjectText, { objectId });
2618
+ // После отображения статичного текста — выровняем его позицию ровно под textarea
2619
+ try {
2620
+ const view = this.app?.view;
2621
+ const worldLayerRef = this.textEditor.world || (this.app?.stage);
2622
+ const viewRes = (this.app?.renderer?.resolution) || (view && view.width && view.clientWidth ? (view.width / view.clientWidth) : 1);
2623
+ const cssLeft = this.textEditor._cssLeftPx;
2624
+ const cssTop = this.textEditor._cssTopPx;
2625
+ if (isFinite(cssLeft) && isFinite(cssTop) && worldLayerRef) {
2626
+ // Ждем один тик, чтобы HtmlTextLayer успел обновить DOM
2627
+ setTimeout(() => {
2628
+ try {
2629
+ const desiredGlobal = new PIXI.Point(Math.round(cssLeft * viewRes), Math.round(cssTop * viewRes));
2630
+ const desiredWorld = worldLayerRef.toLocal(desiredGlobal);
2631
+ const newPos = { x: Math.round(desiredWorld.x), y: Math.round(desiredWorld.y) };
2632
+ this.eventBus.emit(Events.Object.StateChanged, {
2633
+ objectId,
2634
+ updates: { position: newPos }
2635
+ });
2636
+ console.log('🧭 Text post-show align', { objectId, cssLeft, cssTop, newPos });
2637
+ } catch (_) {}
2638
+ }, 0);
2639
+ }
2640
+ } catch (_) {}
2595
2641
  } else {
2596
2642
  console.warn(`❌ SelectTool: HTML-элемент для объекта ${objectId} не найден, пропускаем ShowObjectText`);
2597
2643
  }