kingkont 0.13.0 → 0.13.1
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 +1 -1
- package/renderer/media.js +37 -9
package/package.json
CHANGED
package/renderer/media.js
CHANGED
|
@@ -14,31 +14,59 @@ const _canvasFrame = $('canvasFrame');
|
|
|
14
14
|
// layout-affecting свойство, его смена на каждом wheel-tick форсила 751ms Layout.
|
|
15
15
|
// Транформ на canvas идёт через GPU (will-change: transform → composited),
|
|
16
16
|
// scroll-bounds во время burst могут быть слегка off, на idle подстраиваются.
|
|
17
|
+
// Канвас-frame теперь с padding'ом вокруг .canvas (см. styles.css
|
|
18
|
+
// .canvas-frame --canvas-pad-x/y). Координаты:
|
|
19
|
+
// - frame-coords: 0..(6000*z + 2*padX). Лево-верх frame = (0,0).
|
|
20
|
+
// - canvas-coords: 0..6000 (до scale). Канвас расположен в frame'е
|
|
21
|
+
// по offset (padX, padY) и масштабирован transform: scale(z).
|
|
22
|
+
// - mouseInFrame = scrollLeft + (mouseClient - wrapClient)
|
|
23
|
+
// - contentCoord = (mouseInFrame - padX) / z
|
|
24
|
+
function _getFramePadding() {
|
|
25
|
+
const cs = getComputedStyle(_canvasFrame);
|
|
26
|
+
return {
|
|
27
|
+
padX: parseInt(cs.getPropertyValue('--canvas-pad-x')) || 0,
|
|
28
|
+
padY: parseInt(cs.getPropertyValue('--canvas-pad-y')) || 0,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
17
31
|
let _frameSizeTimer = null;
|
|
18
32
|
function applyZoomStyles(z) {
|
|
19
33
|
canvas.style.transform = `scale(${z})`;
|
|
20
34
|
clearTimeout(_frameSizeTimer);
|
|
21
35
|
_frameSizeTimer = setTimeout(() => {
|
|
22
36
|
_frameSizeTimer = null;
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
const { padX, padY } = _getFramePadding();
|
|
38
|
+
// Frame-размер = scaled-canvas + padding с обеих сторон.
|
|
39
|
+
// Раньше padding не учитывался → frame ужимался при zoom-out → весь
|
|
40
|
+
// padding-skill терялся, ноды с отрицательными coord'ами становились
|
|
41
|
+
// неперехватываемыми скроллом.
|
|
42
|
+
_canvasFrame.style.width = (6000 * z + 2 * padX) + 'px';
|
|
43
|
+
_canvasFrame.style.height = (4000 * z + 2 * padY) + 'px';
|
|
25
44
|
}, 200);
|
|
26
45
|
}
|
|
27
46
|
function applyZoom(nextZoom, anchorClientX, anchorClientY) {
|
|
28
47
|
nextZoom = Math.max(ZOOM_MIN, Math.min(ZOOM_MAX, nextZoom));
|
|
29
48
|
if (nextZoom === state.zoom) return;
|
|
30
49
|
const rect = canvasWrap.getBoundingClientRect();
|
|
31
|
-
|
|
50
|
+
const { padX, padY } = _getFramePadding();
|
|
51
|
+
// Якорь = mouse client coord (или центр если не задан).
|
|
32
52
|
const ax = anchorClientX ?? (rect.left + rect.width / 2);
|
|
33
53
|
const ay = anchorClientY ?? (rect.top + rect.height / 2);
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
54
|
+
// mouse внутри wrap (без учёта scroll).
|
|
55
|
+
const mouseWrapX = ax - rect.left;
|
|
56
|
+
const mouseWrapY = ay - rect.top;
|
|
57
|
+
// mouse в frame-coords (со scroll).
|
|
58
|
+
const mouseFrameX = canvasWrap.scrollLeft + mouseWrapX;
|
|
59
|
+
const mouseFrameY = canvasWrap.scrollTop + mouseWrapY;
|
|
60
|
+
// mouse в canvas content-coords (вычитаем padding и делим на zoom).
|
|
61
|
+
const contentX = (mouseFrameX - padX) / state.zoom;
|
|
62
|
+
const contentY = (mouseFrameY - padY) / state.zoom;
|
|
38
63
|
state.zoom = nextZoom;
|
|
39
64
|
applyZoomStyles(nextZoom);
|
|
40
|
-
|
|
41
|
-
|
|
65
|
+
// После нового zoom: contentCoord должен оказаться там же где был курсор.
|
|
66
|
+
// newMouseFrame = contentCoord * nextZoom + padX
|
|
67
|
+
// newScrollLeft = newMouseFrame - mouseWrapX
|
|
68
|
+
canvasWrap.scrollLeft = contentX * nextZoom + padX - mouseWrapX;
|
|
69
|
+
canvasWrap.scrollTop = contentY * nextZoom + padY - mouseWrapY;
|
|
42
70
|
$('zoomLabel').textContent = Math.round(nextZoom * 100) + '%';
|
|
43
71
|
scheduleViewSave();
|
|
44
72
|
}
|