@sequent-org/moodboard 1.2.93 → 1.2.94

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.93",
3
+ "version": "1.2.94",
4
4
  "type": "module",
5
5
  "description": "Interactive moodboard",
6
6
  "main": "./src/index.js",
@@ -2829,72 +2829,79 @@ export class SelectTool extends BaseTool {
2829
2829
  * Получение коэффициента масштабирования браузера
2830
2830
  */
2831
2831
  _getBrowserZoomFactor() {
2832
- // Множественные методы определения масштаба браузера для надежности
2833
- let zoomFactors = [];
2834
-
2835
- try {
2836
- // Метод 1: Через window размеры
2837
- const outerInnerRatio = window.outerWidth / window.innerWidth;
2838
- if (isFinite(outerInnerRatio) && outerInnerRatio > 0.1 && outerInnerRatio < 10) {
2839
- zoomFactors.push({ method: 'outerInner', value: outerInnerRatio });
2840
- }
2841
- } catch (_) {}
2842
-
2832
+ // Новый подход: через измерение canvas размеров
2843
2833
  try {
2844
- // Метод 2: Через visualViewport если доступно
2845
- if (window.visualViewport) {
2846
- const vpZoom = window.innerWidth / window.visualViewport.width;
2847
- if (isFinite(vpZoom) && vpZoom > 0.1 && vpZoom < 10) {
2848
- zoomFactors.push({ method: 'visualViewport', value: vpZoom });
2834
+ if (this.app && this.app.view) {
2835
+ const canvas = this.app.view;
2836
+
2837
+ // Получаем CSS размеры и реальные размеры canvas
2838
+ const cssWidth = canvas.clientWidth;
2839
+ const cssHeight = canvas.clientHeight;
2840
+ const realWidth = canvas.width;
2841
+ const realHeight = canvas.height;
2842
+
2843
+ // Проверяем device pixel ratio
2844
+ const dpr = window.devicePixelRatio || 1;
2845
+
2846
+ // Вычисляем ожидаемые реальные размеры с учетом DPR
2847
+ const expectedRealWidth = cssWidth * dpr;
2848
+ const expectedRealHeight = cssHeight * dpr;
2849
+
2850
+ // Если реальные размеры отличаются от ожидаемых, значит есть zoom
2851
+ let zoomFactorW = 1.0;
2852
+ let zoomFactorH = 1.0;
2853
+
2854
+ if (expectedRealWidth > 0) {
2855
+ zoomFactorW = realWidth / expectedRealWidth;
2856
+ }
2857
+ if (expectedRealHeight > 0) {
2858
+ zoomFactorH = realHeight / expectedRealHeight;
2859
+ }
2860
+
2861
+ // Берем среднее значение или наиболее близкое к 1.0
2862
+ const avgZoom = (zoomFactorW + zoomFactorH) / 2;
2863
+
2864
+ console.log('🔍 Canvas zoom detection:', {
2865
+ css: { width: cssWidth, height: cssHeight },
2866
+ real: { width: realWidth, height: realHeight },
2867
+ dpr,
2868
+ expected: { width: expectedRealWidth, height: expectedRealHeight },
2869
+ zoom: { width: zoomFactorW, height: zoomFactorH, avg: avgZoom }
2870
+ });
2871
+
2872
+ // Если обнаружили разумное отклонение от 1.0, используем его
2873
+ if (isFinite(avgZoom) && avgZoom > 0.1 && avgZoom < 10 && Math.abs(avgZoom - 1.0) > 0.01) {
2874
+ return avgZoom;
2849
2875
  }
2850
2876
  }
2851
2877
  } catch (_) {}
2852
2878
 
2879
+ // Fallback: простой метод через screen размеры
2853
2880
  try {
2854
- // Метод 3: Через тестовый элемент (проверяем разные единицы)
2855
- const testEl = document.createElement('div');
2856
- testEl.style.position = 'absolute';
2857
- testEl.style.left = '-9999px';
2858
- testEl.style.top = '-9999px';
2859
- testEl.style.width = '100px';
2860
- testEl.style.height = '100px';
2861
- testEl.style.visibility = 'hidden';
2862
- testEl.style.pointerEvents = 'none';
2863
-
2864
- document.body.appendChild(testEl);
2865
-
2866
- const rect = testEl.getBoundingClientRect();
2867
- const elemZoom = 100 / rect.width;
2868
-
2869
- document.body.removeChild(testEl);
2881
+ // Сравниваем screen.width с window.innerWidth
2882
+ const screenRatio = screen.width / window.innerWidth;
2883
+ const dpr = window.devicePixelRatio || 1;
2884
+ const expectedRatio = dpr;
2870
2885
 
2871
- if (isFinite(elemZoom) && elemZoom > 0.1 && elemZoom < 10) {
2872
- zoomFactors.push({ method: 'testElement', value: elemZoom });
2886
+ if (Math.abs(screenRatio - expectedRatio) > 0.1) {
2887
+ const zoomFactor = screenRatio / expectedRatio;
2888
+
2889
+ console.log('🔍 Screen zoom detection:', {
2890
+ screen: { width: screen.width, height: screen.height },
2891
+ window: { innerWidth: window.innerWidth, innerHeight: window.innerHeight },
2892
+ screenRatio,
2893
+ expectedRatio,
2894
+ zoomFactor
2895
+ });
2896
+
2897
+ if (isFinite(zoomFactor) && zoomFactor > 0.1 && zoomFactor < 10) {
2898
+ return zoomFactor;
2899
+ }
2873
2900
  }
2874
2901
  } catch (_) {}
2875
2902
 
2876
- // Логирование всех методов для диагностики
2877
- console.log('🔍 Zoom detection methods:', zoomFactors);
2878
-
2879
- // Выбираем наиболее подходящий результат
2880
- if (zoomFactors.length === 0) {
2881
- return 1.0; // Fallback
2882
- }
2883
-
2884
- // Если есть visualViewport, предпочитаем его
2885
- const vpMethod = zoomFactors.find(f => f.method === 'visualViewport');
2886
- if (vpMethod) {
2887
- return vpMethod.value;
2888
- }
2889
-
2890
- // Иначе берем outerInner как наиболее стабильный
2891
- const outerMethod = zoomFactors.find(f => f.method === 'outerInner');
2892
- if (outerMethod) {
2893
- return outerMethod.value;
2894
- }
2895
-
2896
- // Последний fallback - первый доступный метод
2897
- return zoomFactors[0].value;
2903
+ console.log('🔍 Zoom detection: using fallback (no zoom correction)');
2904
+ return 1.0; // Fallback: без коррекции
2898
2905
  }
2899
2906
 
2900
2907
  }
@@ -376,69 +376,61 @@ export class HtmlTextLayer {
376
376
  * Получение коэффициента масштабирования браузера
377
377
  */
378
378
  _getBrowserZoomFactor() {
379
- // Множественные методы определения масштаба браузера для надежности
380
- let zoomFactors = [];
381
-
382
- try {
383
- // Метод 1: Через window размеры
384
- const outerInnerRatio = window.outerWidth / window.innerWidth;
385
- if (isFinite(outerInnerRatio) && outerInnerRatio > 0.1 && outerInnerRatio < 10) {
386
- zoomFactors.push({ method: 'outerInner', value: outerInnerRatio });
387
- }
388
- } catch (_) {}
389
-
379
+ // Новый подход: через измерение canvas размеров
390
380
  try {
391
- // Метод 2: Через visualViewport если доступно
392
- if (window.visualViewport) {
393
- const vpZoom = window.innerWidth / window.visualViewport.width;
394
- if (isFinite(vpZoom) && vpZoom > 0.1 && vpZoom < 10) {
395
- zoomFactors.push({ method: 'visualViewport', value: vpZoom });
381
+ if (this.core && this.core.pixi && this.core.pixi.app && this.core.pixi.app.view) {
382
+ const canvas = this.core.pixi.app.view;
383
+
384
+ // Получаем CSS размеры и реальные размеры canvas
385
+ const cssWidth = canvas.clientWidth;
386
+ const cssHeight = canvas.clientHeight;
387
+ const realWidth = canvas.width;
388
+ const realHeight = canvas.height;
389
+
390
+ // Проверяем device pixel ratio
391
+ const dpr = window.devicePixelRatio || 1;
392
+
393
+ // Вычисляем ожидаемые реальные размеры с учетом DPR
394
+ const expectedRealWidth = cssWidth * dpr;
395
+ const expectedRealHeight = cssHeight * dpr;
396
+
397
+ // Если реальные размеры отличаются от ожидаемых, значит есть zoom
398
+ let zoomFactorW = 1.0;
399
+ let zoomFactorH = 1.0;
400
+
401
+ if (expectedRealWidth > 0) {
402
+ zoomFactorW = realWidth / expectedRealWidth;
403
+ }
404
+ if (expectedRealHeight > 0) {
405
+ zoomFactorH = realHeight / expectedRealHeight;
406
+ }
407
+
408
+ // Берем среднее значение
409
+ const avgZoom = (zoomFactorW + zoomFactorH) / 2;
410
+
411
+ // Если обнаружили разумное отклонение от 1.0, используем его
412
+ if (isFinite(avgZoom) && avgZoom > 0.1 && avgZoom < 10 && Math.abs(avgZoom - 1.0) > 0.01) {
413
+ return avgZoom;
396
414
  }
397
415
  }
398
416
  } catch (_) {}
399
417
 
418
+ // Fallback: простой метод через screen размеры
400
419
  try {
401
- // Метод 3: Через тестовый элемент (проверяем разные единицы)
402
- const testEl = document.createElement('div');
403
- testEl.style.position = 'absolute';
404
- testEl.style.left = '-9999px';
405
- testEl.style.top = '-9999px';
406
- testEl.style.width = '100px';
407
- testEl.style.height = '100px';
408
- testEl.style.visibility = 'hidden';
409
- testEl.style.pointerEvents = 'none';
410
-
411
- document.body.appendChild(testEl);
412
-
413
- const rect = testEl.getBoundingClientRect();
414
- const elemZoom = 100 / rect.width;
420
+ const screenRatio = screen.width / window.innerWidth;
421
+ const dpr = window.devicePixelRatio || 1;
422
+ const expectedRatio = dpr;
415
423
 
416
- document.body.removeChild(testEl);
417
-
418
- if (isFinite(elemZoom) && elemZoom > 0.1 && elemZoom < 10) {
419
- zoomFactors.push({ method: 'testElement', value: elemZoom });
424
+ if (Math.abs(screenRatio - expectedRatio) > 0.1) {
425
+ const zoomFactor = screenRatio / expectedRatio;
426
+
427
+ if (isFinite(zoomFactor) && zoomFactor > 0.1 && zoomFactor < 10) {
428
+ return zoomFactor;
429
+ }
420
430
  }
421
431
  } catch (_) {}
422
432
 
423
- // Выбираем наиболее подходящий результат
424
- if (zoomFactors.length === 0) {
425
- return 1.0; // Fallback
426
- }
427
-
428
- // Если есть visualViewport, предпочитаем его
429
- const vpMethod = zoomFactors.find(f => f.method === 'visualViewport');
430
- if (vpMethod) {
431
- return vpMethod.value;
432
- }
433
-
434
- // Иначе берем outerInner как наиболее стабильный
435
- const outerMethod = zoomFactors.find(f => f.method === 'outerInner');
436
- if (outerMethod) {
437
- return outerMethod.value;
438
- }
439
-
440
- // Последний fallback - первый доступный метод
441
- return zoomFactors[0].value;
433
+ return 1.0; // Fallback: без коррекции
442
434
  }
443
435
  }
444
436