@openmaic/renderer 0.0.2 → 0.0.3
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/DESIGN.md +7 -1
- package/README.md +11 -3
- package/dist/SlideCanvas.d.ts +12 -1
- package/dist/SlideCanvas.js +105 -0
- package/dist/SlideCanvas.js.map +1 -0
- package/dist/SlideElement.d.ts +3 -2
- package/dist/SlideElement.js +60 -0
- package/dist/SlideElement.js.map +1 -0
- package/dist/context.d.ts +2 -1
- package/dist/context.js +27 -0
- package/dist/context.js.map +1 -0
- package/dist/editing/EditableSlideCanvas.d.ts +26 -0
- package/dist/editing/EditableSlideCanvas.js +352 -0
- package/dist/editing/EditableSlideCanvas.js.map +1 -0
- package/dist/editing/core/drag.d.ts +108 -0
- package/dist/editing/core/drag.js +119 -0
- package/dist/editing/core/drag.js.map +1 -0
- package/dist/editing/core/geometry.d.ts +48 -0
- package/dist/editing/core/geometry.js +186 -0
- package/dist/editing/core/geometry.js.map +1 -0
- package/dist/editing/core/intent.d.ts +39 -0
- package/dist/editing/core/intent.js +35 -0
- package/dist/editing/core/intent.js.map +1 -0
- package/dist/editing/core/line-drag.d.ts +19 -0
- package/dist/editing/core/line-drag.js +163 -0
- package/dist/editing/core/line-drag.js.map +1 -0
- package/dist/editing/core/marquee.d.ts +56 -0
- package/dist/editing/core/marquee.js +74 -0
- package/dist/editing/core/marquee.js.map +1 -0
- package/dist/editing/core/resize.d.ts +121 -0
- package/dist/editing/core/resize.js +392 -0
- package/dist/editing/core/resize.js.map +1 -0
- package/dist/editing/core/rotate.d.ts +37 -0
- package/dist/editing/core/rotate.js +74 -0
- package/dist/editing/core/rotate.js.map +1 -0
- package/dist/editing/core/selection.d.ts +68 -0
- package/dist/editing/core/selection.js +108 -0
- package/dist/editing/core/selection.js.map +1 -0
- package/dist/editing/core/snapping.d.ts +54 -0
- package/dist/editing/core/snapping.js +96 -0
- package/dist/editing/core/snapping.js.map +1 -0
- package/dist/editing/handles/BorderLine.d.ts +15 -0
- package/dist/editing/handles/BorderLine.js +17 -0
- package/dist/editing/handles/BorderLine.js.map +1 -0
- package/dist/editing/handles/LineHandles.d.ts +28 -0
- package/dist/editing/handles/LineHandles.js +51 -0
- package/dist/editing/handles/LineHandles.js.map +1 -0
- package/dist/editing/handles/MarqueeBox.d.ts +19 -0
- package/dist/editing/handles/MarqueeBox.js +26 -0
- package/dist/editing/handles/MarqueeBox.js.map +1 -0
- package/dist/editing/handles/ResizeHandles.d.ts +31 -0
- package/dist/editing/handles/ResizeHandles.js +44 -0
- package/dist/editing/handles/ResizeHandles.js.map +1 -0
- package/dist/editing/handles/RotateHandle.d.ts +26 -0
- package/dist/editing/handles/RotateHandle.js +52 -0
- package/dist/editing/handles/RotateHandle.js.map +1 -0
- package/dist/editing/handles/SelectionOverlay.d.ts +18 -0
- package/dist/editing/handles/SelectionOverlay.js +35 -0
- package/dist/editing/handles/SelectionOverlay.js.map +1 -0
- package/dist/editing/index.d.ts +3 -0
- package/dist/editing/index.js +4 -0
- package/dist/editing/index.js.map +1 -0
- package/dist/editing/types.d.ts +107 -0
- package/dist/editing/types.js +7 -0
- package/dist/editing/types.js.map +1 -0
- package/dist/editing/useEditGesture.d.ts +46 -0
- package/dist/editing/useEditGesture.js +217 -0
- package/dist/editing/useEditGesture.js.map +1 -0
- package/dist/editing/useLineHandleGesture.d.ts +35 -0
- package/dist/editing/useLineHandleGesture.js +112 -0
- package/dist/editing/useLineHandleGesture.js.map +1 -0
- package/dist/editing/useMarqueeGesture.d.ts +43 -0
- package/dist/editing/useMarqueeGesture.js +157 -0
- package/dist/editing/useMarqueeGesture.js.map +1 -0
- package/dist/editing/useResizeGesture.d.ts +43 -0
- package/dist/editing/useResizeGesture.js +137 -0
- package/dist/editing/useResizeGesture.js.map +1 -0
- package/dist/editing/useRotateGesture.d.ts +47 -0
- package/dist/editing/useRotateGesture.js +128 -0
- package/dist/editing/useRotateGesture.js.map +1 -0
- package/dist/effects/HighlightOverlay.js +44 -0
- package/dist/effects/HighlightOverlay.js.map +1 -0
- package/dist/effects/LaserOverlay.js +40 -0
- package/dist/effects/LaserOverlay.js.map +1 -0
- package/dist/effects/SpotlightOverlay.d.ts +3 -1
- package/dist/effects/SpotlightOverlay.js +99 -0
- package/dist/effects/SpotlightOverlay.js.map +1 -0
- package/dist/effects/ZoomWrapper.js +19 -0
- package/dist/effects/ZoomWrapper.js.map +1 -0
- package/dist/elements/chart/BaseChartElement.js +22 -0
- package/dist/elements/chart/BaseChartElement.js.map +1 -0
- package/dist/elements/chart/Chart.js +83 -0
- package/dist/elements/chart/Chart.js.map +1 -0
- package/dist/elements/chart/chartOption.js +178 -0
- package/dist/elements/chart/chartOption.js.map +1 -0
- package/dist/elements/code/BaseCodeElement.js +525 -0
- package/dist/elements/code/BaseCodeElement.js.map +1 -0
- package/dist/elements/image/BaseImageElement.d.ts +4 -4
- package/dist/elements/image/BaseImageElement.js +76 -0
- package/dist/elements/image/BaseImageElement.js.map +1 -0
- package/dist/elements/image/ImageOutline.js +30 -0
- package/dist/elements/image/ImageOutline.js.map +1 -0
- package/dist/elements/image/clipPaths.js +130 -0
- package/dist/elements/image/clipPaths.js.map +1 -0
- package/dist/elements/image/useClipImage.js +40 -0
- package/dist/elements/image/useClipImage.js.map +1 -0
- package/dist/elements/image/useFilter.d.ts +1 -0
- package/dist/elements/image/useFilter.js +35 -0
- package/dist/elements/image/useFilter.js.map +1 -0
- package/dist/elements/index.js +14 -9
- package/dist/elements/index.js.map +1 -1
- package/dist/elements/latex/BaseLatexElement.js +94 -0
- package/dist/elements/latex/BaseLatexElement.js.map +1 -0
- package/dist/elements/line/BaseLineElement.js +72 -0
- package/dist/elements/line/BaseLineElement.js.map +1 -0
- package/dist/elements/line/LinePointMarker.js +19 -0
- package/dist/elements/line/LinePointMarker.js.map +1 -0
- package/dist/elements/shape/BaseShapeElement.js +174 -0
- package/dist/elements/shape/BaseShapeElement.js.map +1 -0
- package/dist/elements/shape/GradientDefs.js +11 -0
- package/dist/elements/shape/GradientDefs.js.map +1 -0
- package/dist/elements/shape/PatternDefs.js +8 -0
- package/dist/elements/shape/PatternDefs.js.map +1 -0
- package/dist/elements/shared/ElementOutline.js +13 -0
- package/dist/elements/shared/ElementOutline.js.map +1 -0
- package/dist/elements/shared/useElementFill.js +15 -0
- package/dist/elements/shared/useElementFill.js.map +1 -0
- package/dist/elements/shared/useElementFlip.js +18 -0
- package/dist/elements/shared/useElementFlip.js.map +1 -0
- package/dist/elements/shared/useElementOutline.js +19 -0
- package/dist/elements/shared/useElementOutline.js.map +1 -0
- package/dist/elements/shared/useElementShadow.js +15 -0
- package/dist/elements/shared/useElementShadow.js.map +1 -0
- package/dist/elements/table/BaseTableElement.js +21 -0
- package/dist/elements/table/BaseTableElement.js.map +1 -0
- package/dist/elements/table/StaticTable.js +117 -0
- package/dist/elements/table/StaticTable.js.map +1 -0
- package/dist/elements/table/tableUtils.js +28 -0
- package/dist/elements/table/tableUtils.js.map +1 -0
- package/dist/elements/text/BaseTextElement.js +46 -0
- package/dist/elements/text/BaseTextElement.js.map +1 -0
- package/dist/elements/video/BaseVideoElement.d.ts +3 -1
- package/dist/elements/video/BaseVideoElement.js +36 -0
- package/dist/elements/video/BaseVideoElement.js.map +1 -0
- package/dist/hooks/useSlideBackgroundStyle.js +43 -0
- package/dist/hooks/useSlideBackgroundStyle.js.map +1 -0
- package/dist/hooks/useViewportSize.d.ts +2 -0
- package/dist/hooks/useViewportSize.js +71 -0
- package/dist/hooks/useViewportSize.js.map +1 -0
- package/dist/index.js +11 -31
- package/dist/index.js.map +1 -1
- package/dist/snapshot/index.d.ts +1 -0
- package/dist/snapshot/index.js +93 -28
- package/dist/snapshot/index.js.map +1 -1
- package/dist/snapshot/katex-fonts-embed.d.ts +10 -0
- package/dist/snapshot/katex-fonts-embed.js +13 -0
- package/dist/snapshot/katex-fonts-embed.js.map +1 -0
- package/dist/snapshot/measure.d.ts +32 -0
- package/dist/snapshot/measure.js +129 -0
- package/dist/snapshot/measure.js.map +1 -0
- package/dist/styles.js +50 -0
- package/dist/styles.js.map +1 -0
- package/dist/types/effects.d.ts +2 -0
- package/dist/utils/cn.js +9 -0
- package/dist/utils/cn.js.map +1 -0
- package/dist/utils/element.js +85 -0
- package/dist/utils/element.js.map +1 -0
- package/dist/utils/geometry.d.ts +2 -2
- package/dist/utils/geometry.js +44 -0
- package/dist/utils/geometry.js.map +1 -0
- package/package.json +14 -4
- package/dist/chunks/BaseCodeElement-Bh-Bfdz6.js +0 -1742
- package/dist/chunks/BaseCodeElement-Bh-Bfdz6.js.map +0 -1
- package/dist/chunks/SlideCanvas-KcCxfrYE.js +0 -477
- package/dist/chunks/SlideCanvas-KcCxfrYE.js.map +0 -1
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { resolveSnapping } from './drag.js';
|
|
2
|
+
import { buildAlignLines, snapRange } from './snapping.js';
|
|
3
|
+
|
|
4
|
+
/** All eight handles, in the app's render order (row-major, top to bottom). */
|
|
5
|
+
const RESIZE_HANDLES = [
|
|
6
|
+
'left-top',
|
|
7
|
+
'top',
|
|
8
|
+
'right-top',
|
|
9
|
+
'left',
|
|
10
|
+
'right',
|
|
11
|
+
'left-bottom',
|
|
12
|
+
'bottom',
|
|
13
|
+
'right-bottom',
|
|
14
|
+
];
|
|
15
|
+
/** The diagonally/axially opposite handle — the visually fixed point of a resize. */
|
|
16
|
+
const OPPOSITE_HANDLE = {
|
|
17
|
+
'left-top': 'right-bottom',
|
|
18
|
+
top: 'bottom',
|
|
19
|
+
'right-top': 'left-bottom',
|
|
20
|
+
left: 'right',
|
|
21
|
+
right: 'left',
|
|
22
|
+
'left-bottom': 'right-top',
|
|
23
|
+
bottom: 'top',
|
|
24
|
+
'right-bottom': 'left-top',
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Minimum size (canvas units) an element may be resized down to, per type.
|
|
28
|
+
* Mirrors the app's element config so the package clamps identically.
|
|
29
|
+
*/
|
|
30
|
+
const ELEMENT_MIN_SIZE = {
|
|
31
|
+
text: 40,
|
|
32
|
+
image: 20,
|
|
33
|
+
shape: 20,
|
|
34
|
+
chart: 200,
|
|
35
|
+
table: 30,
|
|
36
|
+
video: 250,
|
|
37
|
+
audio: 20,
|
|
38
|
+
latex: 20,
|
|
39
|
+
};
|
|
40
|
+
/** Fallback minimum size for element types missing from {@link ELEMENT_MIN_SIZE}. */
|
|
41
|
+
const DEFAULT_MIN_SIZE = 20;
|
|
42
|
+
/**
|
|
43
|
+
* Positions (canvas units) of the eight resize points of a ROTATED box: each
|
|
44
|
+
* un-rotated frame point rotated about the box center by `angle` (degrees,
|
|
45
|
+
* CSS-clockwise). At `angle === 0` this degenerates to the plain frame points
|
|
46
|
+
* (e.g. `left-top` = `(left, top)`), so it also serves as the single source of
|
|
47
|
+
* truth for handle placement at any rotation.
|
|
48
|
+
*/
|
|
49
|
+
function getRotateElementPoints(element, angle) {
|
|
50
|
+
const { left, top, width, height } = element;
|
|
51
|
+
const radius = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) / 2;
|
|
52
|
+
const auxiliaryAngle = (Math.atan(height / width) * 180) / Math.PI;
|
|
53
|
+
const tlbraRadian = ((180 - angle - auxiliaryAngle) * Math.PI) / 180;
|
|
54
|
+
const trblaRadian = ((auxiliaryAngle - angle) * Math.PI) / 180;
|
|
55
|
+
const taRadian = ((90 - angle) * Math.PI) / 180;
|
|
56
|
+
const raRadian = (angle * Math.PI) / 180;
|
|
57
|
+
const halfWidth = width / 2;
|
|
58
|
+
const halfHeight = height / 2;
|
|
59
|
+
const middleLeft = left + halfWidth;
|
|
60
|
+
const middleTop = top + halfHeight;
|
|
61
|
+
return {
|
|
62
|
+
'left-top': {
|
|
63
|
+
left: middleLeft + radius * Math.cos(tlbraRadian),
|
|
64
|
+
top: middleTop - radius * Math.sin(tlbraRadian),
|
|
65
|
+
},
|
|
66
|
+
top: {
|
|
67
|
+
left: middleLeft + halfHeight * Math.cos(taRadian),
|
|
68
|
+
top: middleTop - halfHeight * Math.sin(taRadian),
|
|
69
|
+
},
|
|
70
|
+
'right-top': {
|
|
71
|
+
left: middleLeft + radius * Math.cos(trblaRadian),
|
|
72
|
+
top: middleTop - radius * Math.sin(trblaRadian),
|
|
73
|
+
},
|
|
74
|
+
right: {
|
|
75
|
+
left: middleLeft + halfWidth * Math.cos(raRadian),
|
|
76
|
+
top: middleTop + halfWidth * Math.sin(raRadian),
|
|
77
|
+
},
|
|
78
|
+
'right-bottom': {
|
|
79
|
+
left: middleLeft - radius * Math.cos(tlbraRadian),
|
|
80
|
+
top: middleTop + radius * Math.sin(tlbraRadian),
|
|
81
|
+
},
|
|
82
|
+
bottom: {
|
|
83
|
+
left: middleLeft - halfHeight * Math.sin(raRadian),
|
|
84
|
+
top: middleTop + halfHeight * Math.cos(raRadian),
|
|
85
|
+
},
|
|
86
|
+
'left-bottom': {
|
|
87
|
+
left: middleLeft - radius * Math.cos(trblaRadian),
|
|
88
|
+
top: middleTop + radius * Math.sin(trblaRadian),
|
|
89
|
+
},
|
|
90
|
+
left: {
|
|
91
|
+
left: middleLeft - halfWidth * Math.cos(raRadian),
|
|
92
|
+
top: middleTop - halfWidth * Math.sin(raRadian),
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The point opposite the operated handle on a rotated box — the base point
|
|
98
|
+
* that must stay visually fixed while the box resizes (e.g. dragging
|
|
99
|
+
* `right-bottom` keeps the rotated `left-top` corner in place).
|
|
100
|
+
*/
|
|
101
|
+
function getOppositePoint(handle, points) {
|
|
102
|
+
return points[OPPOSITE_HANDLE[handle]];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The visual cursor cycle a handle's cursor advances through as the element
|
|
106
|
+
* rotates: every +45deg of rotation shifts a handle's on-screen direction one
|
|
107
|
+
* step clockwise (nwse -> ns -> nesw -> ew -> nwse ...).
|
|
108
|
+
*/
|
|
109
|
+
const CURSOR_CYCLE = [
|
|
110
|
+
'nwse-resize',
|
|
111
|
+
'ns-resize',
|
|
112
|
+
'nesw-resize',
|
|
113
|
+
'ew-resize',
|
|
114
|
+
];
|
|
115
|
+
/** Each handle's cursor at rotation 0 as an index into {@link CURSOR_CYCLE}. */
|
|
116
|
+
const CURSOR_BASE_INDEX = {
|
|
117
|
+
'left-top': 0,
|
|
118
|
+
'right-bottom': 0,
|
|
119
|
+
top: 1,
|
|
120
|
+
bottom: 1,
|
|
121
|
+
'right-top': 2,
|
|
122
|
+
'left-bottom': 2,
|
|
123
|
+
left: 3,
|
|
124
|
+
right: 3,
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Rotation-aware resize cursor for a handle: bucket `rotate` to the nearest of
|
|
128
|
+
* 0/45/90/135 (mod 180, +-22.5deg thresholds, negatives wrap the same way),
|
|
129
|
+
* then advance the handle's rotation-0 cursor one {@link CURSOR_CYCLE} step per
|
|
130
|
+
* 45deg bucket. Reproduces the app's full handle x bucket cursor table.
|
|
131
|
+
*/
|
|
132
|
+
function getResizeCursor(handle, rotate) {
|
|
133
|
+
let bucket;
|
|
134
|
+
if (rotate > -22.5 && rotate <= 22.5)
|
|
135
|
+
bucket = 0;
|
|
136
|
+
else if (rotate > 22.5 && rotate <= 67.5)
|
|
137
|
+
bucket = 45;
|
|
138
|
+
else if (rotate > 67.5 && rotate <= 112.5)
|
|
139
|
+
bucket = 90;
|
|
140
|
+
else if (rotate > 112.5 && rotate <= 157.5)
|
|
141
|
+
bucket = 135;
|
|
142
|
+
else if (rotate > 157.5 || rotate <= -157.5)
|
|
143
|
+
bucket = 0;
|
|
144
|
+
else if (rotate > -157.5 && rotate <= -112.5)
|
|
145
|
+
bucket = 45;
|
|
146
|
+
else if (rotate > -112.5 && rotate <= -67.5)
|
|
147
|
+
bucket = 90;
|
|
148
|
+
else
|
|
149
|
+
bucket = 135; // (-67.5, -22.5]
|
|
150
|
+
return CURSOR_CYCLE[(CURSOR_BASE_INDEX[handle] + bucket / 45) % 4];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Which resize handles a box element exposes, by kind (app parity):
|
|
154
|
+
* - `code`: none — the app renders no resize points for code blocks.
|
|
155
|
+
* - `text`: only the width axis, since text height follows content — `left`/
|
|
156
|
+
* `right`, or `top`/`bottom` when the text is vertical.
|
|
157
|
+
* - everything else: all eight points.
|
|
158
|
+
* Line elements never reach here (they have endpoint handles, not a box).
|
|
159
|
+
*/
|
|
160
|
+
function getResizeHandles(element) {
|
|
161
|
+
if (element.type === 'code')
|
|
162
|
+
return [];
|
|
163
|
+
if (element.type === 'text') {
|
|
164
|
+
return element.vertical ? ['top', 'bottom'] : ['left', 'right'];
|
|
165
|
+
}
|
|
166
|
+
return RESIZE_HANDLES;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Apply a resize delta to a single box element. Composition, per the app:
|
|
170
|
+
*
|
|
171
|
+
* - **Un-rotated**: the moving edge(s) follow the pointer delta directly; the
|
|
172
|
+
* moving corner/edge position is snapped against `others`/the canvas BEFORE
|
|
173
|
+
* min-size clamping (aspect lock recomputes the other axis from whichever
|
|
174
|
+
* axis snapped); resizing from a left/top edge shifts `left`/`top` so the
|
|
175
|
+
* opposite edge stays put. Rotated siblings and lines are excluded from the
|
|
176
|
+
* snap candidates (their axis-aligned bboxes are not meaningful snap edges).
|
|
177
|
+
* - **Rotated**: the pointer delta is first rotated into the element's local
|
|
178
|
+
* axes; the same per-handle size math applies; then the position is
|
|
179
|
+
* corrected so the point OPPOSITE the operated handle stays visually fixed
|
|
180
|
+
* (resizing changes where the rotated opposite corner lands, so `left`/`top`
|
|
181
|
+
* must compensate). No snapping for rotated elements (app parity).
|
|
182
|
+
*
|
|
183
|
+
* Aspect lock (`aspectModifier` held, or the element's own `fixedRatio`) only
|
|
184
|
+
* affects the four CORNER handles: the vertical delta is recomputed from the
|
|
185
|
+
* horizontal one at the origin's aspect ratio. Edge handles ignore it.
|
|
186
|
+
*
|
|
187
|
+
* Min-size clamping uses the per-type {@link ELEMENT_MIN_SIZE}; under aspect
|
|
188
|
+
* lock the limit is scaled so both axes reach their minimum together.
|
|
189
|
+
*/
|
|
190
|
+
function computeResize(input) {
|
|
191
|
+
const { element, handle, others, viewport, deltaCanvas, aspectModifier, snapping } = input;
|
|
192
|
+
const originLeft = element.left;
|
|
193
|
+
const originTop = element.top;
|
|
194
|
+
const originWidth = element.width;
|
|
195
|
+
const originHeight = element.height;
|
|
196
|
+
const rotate = element.rotate || 0;
|
|
197
|
+
const rotateRadian = (Math.PI * rotate) / 180;
|
|
198
|
+
const fixedRatio = Boolean(aspectModifier) || ('fixedRatio' in element && Boolean(element.fixedRatio));
|
|
199
|
+
const aspectRatio = originWidth / originHeight;
|
|
200
|
+
const minSize = ELEMENT_MIN_SIZE[element.type] ?? DEFAULT_MIN_SIZE;
|
|
201
|
+
// Clamp a candidate size to the per-type minimum. Under aspect lock the
|
|
202
|
+
// shorter axis governs: scale the limits so width and height hit their
|
|
203
|
+
// minimums at the same aspect-locked step (app parity).
|
|
204
|
+
const getSizeWithinRange = (size, axis) => {
|
|
205
|
+
if (!fixedRatio)
|
|
206
|
+
return size < minSize ? minSize : size;
|
|
207
|
+
let minWidth = minSize;
|
|
208
|
+
let minHeight = minSize;
|
|
209
|
+
const ratio = originWidth / originHeight;
|
|
210
|
+
if (ratio < 1)
|
|
211
|
+
minHeight = minSize / ratio;
|
|
212
|
+
if (ratio > 1)
|
|
213
|
+
minWidth = minSize * ratio;
|
|
214
|
+
if (axis === 'width')
|
|
215
|
+
return size < minWidth ? minWidth : size;
|
|
216
|
+
return size < minHeight ? minHeight : size;
|
|
217
|
+
};
|
|
218
|
+
let left = originLeft;
|
|
219
|
+
let top = originTop;
|
|
220
|
+
let width = originWidth;
|
|
221
|
+
let height = originHeight;
|
|
222
|
+
let guides = [];
|
|
223
|
+
// ROTATED path: rotate the pointer delta into element-local axes, apply the
|
|
224
|
+
// per-handle size math, then correct the position so the opposite point
|
|
225
|
+
// stays fixed. No alignment snapping for rotated elements (app parity —
|
|
226
|
+
// axis-aligned snap lines are meaningless against a rotated frame).
|
|
227
|
+
if (rotate) {
|
|
228
|
+
const revisedX = Math.cos(rotateRadian) * deltaCanvas.x + Math.sin(rotateRadian) * deltaCanvas.y;
|
|
229
|
+
let revisedY = Math.cos(rotateRadian) * deltaCanvas.y - Math.sin(rotateRadian) * deltaCanvas.x;
|
|
230
|
+
// Aspect lock (corners only): derive the local vertical delta from the
|
|
231
|
+
// horizontal one so the box scales at the origin's ratio.
|
|
232
|
+
if (fixedRatio) {
|
|
233
|
+
if (handle === 'right-bottom' || handle === 'left-top')
|
|
234
|
+
revisedY = revisedX / aspectRatio;
|
|
235
|
+
if (handle === 'left-bottom' || handle === 'right-top')
|
|
236
|
+
revisedY = -revisedX / aspectRatio;
|
|
237
|
+
}
|
|
238
|
+
// Per-handle size/position math in the local frame. The position computed
|
|
239
|
+
// here still needs the opposite-point correction below: resizing a rotated
|
|
240
|
+
// box moves where its rotated opposite point lands, and only a `left`/`top`
|
|
241
|
+
// shift keeps it visually fixed. The SIZE needs no correction — the delta
|
|
242
|
+
// was already rotated into local axes above.
|
|
243
|
+
if (handle === 'right-bottom') {
|
|
244
|
+
width = getSizeWithinRange(originWidth + revisedX, 'width');
|
|
245
|
+
height = getSizeWithinRange(originHeight + revisedY, 'height');
|
|
246
|
+
}
|
|
247
|
+
else if (handle === 'left-bottom') {
|
|
248
|
+
width = getSizeWithinRange(originWidth - revisedX, 'width');
|
|
249
|
+
height = getSizeWithinRange(originHeight + revisedY, 'height');
|
|
250
|
+
left = originLeft - (width - originWidth);
|
|
251
|
+
}
|
|
252
|
+
else if (handle === 'left-top') {
|
|
253
|
+
width = getSizeWithinRange(originWidth - revisedX, 'width');
|
|
254
|
+
height = getSizeWithinRange(originHeight - revisedY, 'height');
|
|
255
|
+
left = originLeft - (width - originWidth);
|
|
256
|
+
top = originTop - (height - originHeight);
|
|
257
|
+
}
|
|
258
|
+
else if (handle === 'right-top') {
|
|
259
|
+
width = getSizeWithinRange(originWidth + revisedX, 'width');
|
|
260
|
+
height = getSizeWithinRange(originHeight - revisedY, 'height');
|
|
261
|
+
top = originTop - (height - originHeight);
|
|
262
|
+
}
|
|
263
|
+
else if (handle === 'top') {
|
|
264
|
+
height = getSizeWithinRange(originHeight - revisedY, 'height');
|
|
265
|
+
top = originTop - (height - originHeight);
|
|
266
|
+
}
|
|
267
|
+
else if (handle === 'bottom') {
|
|
268
|
+
height = getSizeWithinRange(originHeight + revisedY, 'height');
|
|
269
|
+
}
|
|
270
|
+
else if (handle === 'left') {
|
|
271
|
+
width = getSizeWithinRange(originWidth - revisedX, 'width');
|
|
272
|
+
left = originLeft - (width - originWidth);
|
|
273
|
+
}
|
|
274
|
+
else if (handle === 'right') {
|
|
275
|
+
width = getSizeWithinRange(originWidth + revisedX, 'width');
|
|
276
|
+
}
|
|
277
|
+
// Opposite-point correction: capture where the opposite point sat on the
|
|
278
|
+
// ORIGINAL box, recompute it on the resized box, and shift `left`/`top`
|
|
279
|
+
// back by the drift so the opposite handle stays visually fixed.
|
|
280
|
+
const basePoint = getOppositePoint(handle, getRotateElementPoints({ left: originLeft, top: originTop, width: originWidth, height: originHeight }, rotate));
|
|
281
|
+
const currentPoint = getOppositePoint(handle, getRotateElementPoints({ left, top, width, height }, rotate));
|
|
282
|
+
left -= currentPoint.left - basePoint.left;
|
|
283
|
+
top -= currentPoint.top - basePoint.top;
|
|
284
|
+
return { props: { left, top, width, height }, guides };
|
|
285
|
+
}
|
|
286
|
+
// UN-ROTATED path: the pointer delta applies directly, with alignment
|
|
287
|
+
// snapping of the moving corner/edge and simple left/top shifts.
|
|
288
|
+
let moveX = deltaCanvas.x;
|
|
289
|
+
let moveY = deltaCanvas.y;
|
|
290
|
+
// Aspect lock (corners only), pre-snap: same derivation as the rotated path.
|
|
291
|
+
if (fixedRatio) {
|
|
292
|
+
if (handle === 'right-bottom' || handle === 'left-top')
|
|
293
|
+
moveY = moveX / aspectRatio;
|
|
294
|
+
if (handle === 'left-bottom' || handle === 'right-top')
|
|
295
|
+
moveY = -moveX / aspectRatio;
|
|
296
|
+
}
|
|
297
|
+
const resolved = resolveSnapping(snapping);
|
|
298
|
+
const lines = resolved
|
|
299
|
+
? buildAlignLines(
|
|
300
|
+
// Rotated siblings and lines are excluded from resize snap candidates
|
|
301
|
+
// (app parity): a rotated element's axis-aligned bbox edges are not
|
|
302
|
+
// where anything visually aligns, and a line has no box to align to.
|
|
303
|
+
others.filter((o) => o.type !== 'line' && !(o.rotate ?? 0)), viewport, resolved.opts)
|
|
304
|
+
: null;
|
|
305
|
+
// Snap the MOVING point (the operated corner, or the moving edge on one
|
|
306
|
+
// axis) against the candidate lines, BEFORE clamping. A degenerate
|
|
307
|
+
// single-point range makes `snapRange` probe exactly that point; edge
|
|
308
|
+
// handles suppress the non-moving axis by passing it no candidate lines.
|
|
309
|
+
const snapPoint = (probeX, probeY, axes) => {
|
|
310
|
+
if (!lines || !resolved)
|
|
311
|
+
return { dx: 0, dy: 0 };
|
|
312
|
+
const { dx, dy, guides: g, } = snapRange({ minX: probeX, maxX: probeX, minY: probeY, maxY: probeY }, {
|
|
313
|
+
vertical: axes === 'y' ? [] : lines.vertical,
|
|
314
|
+
horizontal: axes === 'x' ? [] : lines.horizontal,
|
|
315
|
+
}, resolved.range);
|
|
316
|
+
guides = g;
|
|
317
|
+
return { dx, dy };
|
|
318
|
+
};
|
|
319
|
+
// Post-snap aspect re-lock (corners): if the vertical axis snapped, it wins
|
|
320
|
+
// and the horizontal delta is recomputed from it; otherwise the horizontal
|
|
321
|
+
// delta drives, exactly as in the pre-snap derivation.
|
|
322
|
+
const relockAspect = (dy, sign) => {
|
|
323
|
+
if (!fixedRatio)
|
|
324
|
+
return;
|
|
325
|
+
if (dy !== 0)
|
|
326
|
+
moveX = sign * moveY * aspectRatio;
|
|
327
|
+
else
|
|
328
|
+
moveY = (sign * moveX) / aspectRatio;
|
|
329
|
+
};
|
|
330
|
+
if (handle === 'right-bottom') {
|
|
331
|
+
const { dx, dy } = snapPoint(originLeft + originWidth + moveX, originTop + originHeight + moveY, 'both');
|
|
332
|
+
moveX += dx;
|
|
333
|
+
moveY += dy;
|
|
334
|
+
relockAspect(dy, 1);
|
|
335
|
+
width = getSizeWithinRange(originWidth + moveX, 'width');
|
|
336
|
+
height = getSizeWithinRange(originHeight + moveY, 'height');
|
|
337
|
+
}
|
|
338
|
+
else if (handle === 'left-bottom') {
|
|
339
|
+
const { dx, dy } = snapPoint(originLeft + moveX, originTop + originHeight + moveY, 'both');
|
|
340
|
+
moveX += dx;
|
|
341
|
+
moveY += dy;
|
|
342
|
+
relockAspect(dy, -1);
|
|
343
|
+
width = getSizeWithinRange(originWidth - moveX, 'width');
|
|
344
|
+
height = getSizeWithinRange(originHeight + moveY, 'height');
|
|
345
|
+
left = originLeft - (width - originWidth);
|
|
346
|
+
}
|
|
347
|
+
else if (handle === 'left-top') {
|
|
348
|
+
const { dx, dy } = snapPoint(originLeft + moveX, originTop + moveY, 'both');
|
|
349
|
+
moveX += dx;
|
|
350
|
+
moveY += dy;
|
|
351
|
+
relockAspect(dy, 1);
|
|
352
|
+
width = getSizeWithinRange(originWidth - moveX, 'width');
|
|
353
|
+
height = getSizeWithinRange(originHeight - moveY, 'height');
|
|
354
|
+
left = originLeft - (width - originWidth);
|
|
355
|
+
top = originTop - (height - originHeight);
|
|
356
|
+
}
|
|
357
|
+
else if (handle === 'right-top') {
|
|
358
|
+
const { dx, dy } = snapPoint(originLeft + originWidth + moveX, originTop + moveY, 'both');
|
|
359
|
+
moveX += dx;
|
|
360
|
+
moveY += dy;
|
|
361
|
+
relockAspect(dy, -1);
|
|
362
|
+
width = getSizeWithinRange(originWidth + moveX, 'width');
|
|
363
|
+
height = getSizeWithinRange(originHeight - moveY, 'height');
|
|
364
|
+
top = originTop - (height - originHeight);
|
|
365
|
+
}
|
|
366
|
+
else if (handle === 'left') {
|
|
367
|
+
const { dx } = snapPoint(originLeft + moveX, originTop, 'x');
|
|
368
|
+
moveX += dx;
|
|
369
|
+
width = getSizeWithinRange(originWidth - moveX, 'width');
|
|
370
|
+
left = originLeft - (width - originWidth);
|
|
371
|
+
}
|
|
372
|
+
else if (handle === 'right') {
|
|
373
|
+
const { dx } = snapPoint(originLeft + originWidth + moveX, originTop, 'x');
|
|
374
|
+
moveX += dx;
|
|
375
|
+
width = getSizeWithinRange(originWidth + moveX, 'width');
|
|
376
|
+
}
|
|
377
|
+
else if (handle === 'top') {
|
|
378
|
+
const { dy } = snapPoint(originLeft, originTop + moveY, 'y');
|
|
379
|
+
moveY += dy;
|
|
380
|
+
height = getSizeWithinRange(originHeight - moveY, 'height');
|
|
381
|
+
top = originTop - (height - originHeight);
|
|
382
|
+
}
|
|
383
|
+
else if (handle === 'bottom') {
|
|
384
|
+
const { dy } = snapPoint(originLeft, originTop + originHeight + moveY, 'y');
|
|
385
|
+
moveY += dy;
|
|
386
|
+
height = getSizeWithinRange(originHeight + moveY, 'height');
|
|
387
|
+
}
|
|
388
|
+
return { props: { left, top, width, height }, guides };
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export { ELEMENT_MIN_SIZE, OPPOSITE_HANDLE, RESIZE_HANDLES, computeResize, getResizeCursor, getResizeHandles, getRotateElementPoints };
|
|
392
|
+
//# sourceMappingURL=resize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resize.js","sources":["../../../src/editing/core/resize.ts"],"sourcesContent":["import type { PPTElement, PPTLineElement } from '@openmaic/dsl';\nimport type { SnappingOptions } from '../types';\nimport { resolveSnapping } from './drag';\nimport { buildAlignLines, snapRange, type Guide } from './snapping';\n\n/**\n * Pure, store-free core for the 8-point box resize gesture. Ported from the\n * app's scale-element gesture, but with no React/store/DOM: the caller feeds\n * the ORIGINAL element plus a pointer delta already converted to canvas units,\n * and gets back the new `left/top/width/height` box plus any alignment guides.\n * No `@/` imports — this module only consumes the DSL element shape, the\n * sibling snapping/drag cores, and plain numbers.\n *\n * Scope note: `computeResize` emits ONLY the box props. Kind-specific content\n * recomputation that must track the box (a shape's `pathFormula`/`viewBox`\n * path, a table's `cellMinHeight`, an image's clip mode) is a host/app concern\n * or a later slice — the host can post-process in response to the intent.\n */\n\n/** A selectable element that carries a box model (`width`/`height`/`rotate`). */\nexport type PPTBoxElement = Exclude<PPTElement, PPTLineElement>;\n\n/** The eight resize points on a box element's selection frame. */\nexport type ResizeHandle =\n | 'left-top'\n | 'top'\n | 'right-top'\n | 'left'\n | 'right'\n | 'left-bottom'\n | 'bottom'\n | 'right-bottom';\n\n/** All eight handles, in the app's render order (row-major, top to bottom). */\nexport const RESIZE_HANDLES: readonly ResizeHandle[] = [\n 'left-top',\n 'top',\n 'right-top',\n 'left',\n 'right',\n 'left-bottom',\n 'bottom',\n 'right-bottom',\n];\n\n/** The diagonally/axially opposite handle — the visually fixed point of a resize. */\nexport const OPPOSITE_HANDLE: Record<ResizeHandle, ResizeHandle> = {\n 'left-top': 'right-bottom',\n top: 'bottom',\n 'right-top': 'left-bottom',\n left: 'right',\n right: 'left',\n 'left-bottom': 'right-top',\n bottom: 'top',\n 'right-bottom': 'left-top',\n};\n\n/**\n * Minimum size (canvas units) an element may be resized down to, per type.\n * Mirrors the app's element config so the package clamps identically.\n */\nexport const ELEMENT_MIN_SIZE: Record<string, number> = {\n text: 40,\n image: 20,\n shape: 20,\n chart: 200,\n table: 30,\n video: 250,\n audio: 20,\n latex: 20,\n};\n\n/** Fallback minimum size for element types missing from {@link ELEMENT_MIN_SIZE}. */\nconst DEFAULT_MIN_SIZE = 20;\n\ninterface Box {\n left: number;\n top: number;\n width: number;\n height: number;\n}\n\ninterface Point {\n left: number;\n top: number;\n}\n\n/**\n * Positions (canvas units) of the eight resize points of a ROTATED box: each\n * un-rotated frame point rotated about the box center by `angle` (degrees,\n * CSS-clockwise). At `angle === 0` this degenerates to the plain frame points\n * (e.g. `left-top` = `(left, top)`), so it also serves as the single source of\n * truth for handle placement at any rotation.\n */\nexport function getRotateElementPoints(element: Box, angle: number): Record<ResizeHandle, Point> {\n const { left, top, width, height } = element;\n\n const radius = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2)) / 2;\n const auxiliaryAngle = (Math.atan(height / width) * 180) / Math.PI;\n\n const tlbraRadian = ((180 - angle - auxiliaryAngle) * Math.PI) / 180;\n const trblaRadian = ((auxiliaryAngle - angle) * Math.PI) / 180;\n const taRadian = ((90 - angle) * Math.PI) / 180;\n const raRadian = (angle * Math.PI) / 180;\n\n const halfWidth = width / 2;\n const halfHeight = height / 2;\n\n const middleLeft = left + halfWidth;\n const middleTop = top + halfHeight;\n\n return {\n 'left-top': {\n left: middleLeft + radius * Math.cos(tlbraRadian),\n top: middleTop - radius * Math.sin(tlbraRadian),\n },\n top: {\n left: middleLeft + halfHeight * Math.cos(taRadian),\n top: middleTop - halfHeight * Math.sin(taRadian),\n },\n 'right-top': {\n left: middleLeft + radius * Math.cos(trblaRadian),\n top: middleTop - radius * Math.sin(trblaRadian),\n },\n right: {\n left: middleLeft + halfWidth * Math.cos(raRadian),\n top: middleTop + halfWidth * Math.sin(raRadian),\n },\n 'right-bottom': {\n left: middleLeft - radius * Math.cos(tlbraRadian),\n top: middleTop + radius * Math.sin(tlbraRadian),\n },\n bottom: {\n left: middleLeft - halfHeight * Math.sin(raRadian),\n top: middleTop + halfHeight * Math.cos(raRadian),\n },\n 'left-bottom': {\n left: middleLeft - radius * Math.cos(trblaRadian),\n top: middleTop + radius * Math.sin(trblaRadian),\n },\n left: {\n left: middleLeft - halfWidth * Math.cos(raRadian),\n top: middleTop - halfWidth * Math.sin(raRadian),\n },\n };\n}\n\n/**\n * The point opposite the operated handle on a rotated box — the base point\n * that must stay visually fixed while the box resizes (e.g. dragging\n * `right-bottom` keeps the rotated `left-top` corner in place).\n */\nfunction getOppositePoint(handle: ResizeHandle, points: Record<ResizeHandle, Point>): Point {\n return points[OPPOSITE_HANDLE[handle]];\n}\n\nexport type ResizeCursor = 'nwse-resize' | 'ns-resize' | 'nesw-resize' | 'ew-resize';\n\n/**\n * The visual cursor cycle a handle's cursor advances through as the element\n * rotates: every +45deg of rotation shifts a handle's on-screen direction one\n * step clockwise (nwse -> ns -> nesw -> ew -> nwse ...).\n */\nconst CURSOR_CYCLE: readonly ResizeCursor[] = [\n 'nwse-resize',\n 'ns-resize',\n 'nesw-resize',\n 'ew-resize',\n];\n\n/** Each handle's cursor at rotation 0 as an index into {@link CURSOR_CYCLE}. */\nconst CURSOR_BASE_INDEX: Record<ResizeHandle, number> = {\n 'left-top': 0,\n 'right-bottom': 0,\n top: 1,\n bottom: 1,\n 'right-top': 2,\n 'left-bottom': 2,\n left: 3,\n right: 3,\n};\n\n/**\n * Rotation-aware resize cursor for a handle: bucket `rotate` to the nearest of\n * 0/45/90/135 (mod 180, +-22.5deg thresholds, negatives wrap the same way),\n * then advance the handle's rotation-0 cursor one {@link CURSOR_CYCLE} step per\n * 45deg bucket. Reproduces the app's full handle x bucket cursor table.\n */\nexport function getResizeCursor(handle: ResizeHandle, rotate: number): ResizeCursor {\n let bucket: 0 | 45 | 90 | 135;\n if (rotate > -22.5 && rotate <= 22.5) bucket = 0;\n else if (rotate > 22.5 && rotate <= 67.5) bucket = 45;\n else if (rotate > 67.5 && rotate <= 112.5) bucket = 90;\n else if (rotate > 112.5 && rotate <= 157.5) bucket = 135;\n else if (rotate > 157.5 || rotate <= -157.5) bucket = 0;\n else if (rotate > -157.5 && rotate <= -112.5) bucket = 45;\n else if (rotate > -112.5 && rotate <= -67.5) bucket = 90;\n else bucket = 135; // (-67.5, -22.5]\n\n return CURSOR_CYCLE[(CURSOR_BASE_INDEX[handle] + bucket / 45) % 4];\n}\n\n/**\n * Which resize handles a box element exposes, by kind (app parity):\n * - `code`: none — the app renders no resize points for code blocks.\n * - `text`: only the width axis, since text height follows content — `left`/\n * `right`, or `top`/`bottom` when the text is vertical.\n * - everything else: all eight points.\n * Line elements never reach here (they have endpoint handles, not a box).\n */\nexport function getResizeHandles(element: PPTBoxElement): readonly ResizeHandle[] {\n if (element.type === 'code') return [];\n if (element.type === 'text') {\n return element.vertical ? ['top', 'bottom'] : ['left', 'right'];\n }\n return RESIZE_HANDLES;\n}\n\n/**\n * Single-element resize input for one gesture tick: the ORIGINAL element (as\n * captured at pointer-down — deltas always apply to the origin, never to a\n * previous tick's output), the operated handle, its siblings (`others`, snap\n * candidates), the viewport (canvas bounds for `toCanvas` snapping), the\n * pointer delta already converted to canvas units, whether the aspect-lock\n * modifier (Ctrl/Shift/Meta) is held at THIS tick, and the snapping config.\n */\nexport interface ResizeInput {\n element: PPTBoxElement;\n handle: ResizeHandle;\n others: PPTElement[];\n viewport: { width: number; height: number };\n deltaCanvas: { x: number; y: number };\n aspectModifier?: boolean;\n snapping?: boolean | SnappingOptions;\n}\n\n/** The resized element's new box plus the guides to render, if any. */\nexport interface ResizeResult {\n props: { left: number; top: number; width: number; height: number };\n guides: Guide[];\n}\n\n/**\n * Apply a resize delta to a single box element. Composition, per the app:\n *\n * - **Un-rotated**: the moving edge(s) follow the pointer delta directly; the\n * moving corner/edge position is snapped against `others`/the canvas BEFORE\n * min-size clamping (aspect lock recomputes the other axis from whichever\n * axis snapped); resizing from a left/top edge shifts `left`/`top` so the\n * opposite edge stays put. Rotated siblings and lines are excluded from the\n * snap candidates (their axis-aligned bboxes are not meaningful snap edges).\n * - **Rotated**: the pointer delta is first rotated into the element's local\n * axes; the same per-handle size math applies; then the position is\n * corrected so the point OPPOSITE the operated handle stays visually fixed\n * (resizing changes where the rotated opposite corner lands, so `left`/`top`\n * must compensate). No snapping for rotated elements (app parity).\n *\n * Aspect lock (`aspectModifier` held, or the element's own `fixedRatio`) only\n * affects the four CORNER handles: the vertical delta is recomputed from the\n * horizontal one at the origin's aspect ratio. Edge handles ignore it.\n *\n * Min-size clamping uses the per-type {@link ELEMENT_MIN_SIZE}; under aspect\n * lock the limit is scaled so both axes reach their minimum together.\n */\nexport function computeResize(input: ResizeInput): ResizeResult {\n const { element, handle, others, viewport, deltaCanvas, aspectModifier, snapping } = input;\n\n const originLeft = element.left;\n const originTop = element.top;\n const originWidth = element.width;\n const originHeight = element.height;\n\n const rotate = element.rotate || 0;\n const rotateRadian = (Math.PI * rotate) / 180;\n\n const fixedRatio =\n Boolean(aspectModifier) || ('fixedRatio' in element && Boolean(element.fixedRatio));\n const aspectRatio = originWidth / originHeight;\n\n const minSize = ELEMENT_MIN_SIZE[element.type] ?? DEFAULT_MIN_SIZE;\n // Clamp a candidate size to the per-type minimum. Under aspect lock the\n // shorter axis governs: scale the limits so width and height hit their\n // minimums at the same aspect-locked step (app parity).\n const getSizeWithinRange = (size: number, axis: 'width' | 'height'): number => {\n if (!fixedRatio) return size < minSize ? minSize : size;\n\n let minWidth = minSize;\n let minHeight = minSize;\n const ratio = originWidth / originHeight;\n if (ratio < 1) minHeight = minSize / ratio;\n if (ratio > 1) minWidth = minSize * ratio;\n\n if (axis === 'width') return size < minWidth ? minWidth : size;\n return size < minHeight ? minHeight : size;\n };\n\n let left = originLeft;\n let top = originTop;\n let width = originWidth;\n let height = originHeight;\n let guides: Guide[] = [];\n\n // ROTATED path: rotate the pointer delta into element-local axes, apply the\n // per-handle size math, then correct the position so the opposite point\n // stays fixed. No alignment snapping for rotated elements (app parity —\n // axis-aligned snap lines are meaningless against a rotated frame).\n if (rotate) {\n const revisedX =\n Math.cos(rotateRadian) * deltaCanvas.x + Math.sin(rotateRadian) * deltaCanvas.y;\n let revisedY = Math.cos(rotateRadian) * deltaCanvas.y - Math.sin(rotateRadian) * deltaCanvas.x;\n\n // Aspect lock (corners only): derive the local vertical delta from the\n // horizontal one so the box scales at the origin's ratio.\n if (fixedRatio) {\n if (handle === 'right-bottom' || handle === 'left-top') revisedY = revisedX / aspectRatio;\n if (handle === 'left-bottom' || handle === 'right-top') revisedY = -revisedX / aspectRatio;\n }\n\n // Per-handle size/position math in the local frame. The position computed\n // here still needs the opposite-point correction below: resizing a rotated\n // box moves where its rotated opposite point lands, and only a `left`/`top`\n // shift keeps it visually fixed. The SIZE needs no correction — the delta\n // was already rotated into local axes above.\n if (handle === 'right-bottom') {\n width = getSizeWithinRange(originWidth + revisedX, 'width');\n height = getSizeWithinRange(originHeight + revisedY, 'height');\n } else if (handle === 'left-bottom') {\n width = getSizeWithinRange(originWidth - revisedX, 'width');\n height = getSizeWithinRange(originHeight + revisedY, 'height');\n left = originLeft - (width - originWidth);\n } else if (handle === 'left-top') {\n width = getSizeWithinRange(originWidth - revisedX, 'width');\n height = getSizeWithinRange(originHeight - revisedY, 'height');\n left = originLeft - (width - originWidth);\n top = originTop - (height - originHeight);\n } else if (handle === 'right-top') {\n width = getSizeWithinRange(originWidth + revisedX, 'width');\n height = getSizeWithinRange(originHeight - revisedY, 'height');\n top = originTop - (height - originHeight);\n } else if (handle === 'top') {\n height = getSizeWithinRange(originHeight - revisedY, 'height');\n top = originTop - (height - originHeight);\n } else if (handle === 'bottom') {\n height = getSizeWithinRange(originHeight + revisedY, 'height');\n } else if (handle === 'left') {\n width = getSizeWithinRange(originWidth - revisedX, 'width');\n left = originLeft - (width - originWidth);\n } else if (handle === 'right') {\n width = getSizeWithinRange(originWidth + revisedX, 'width');\n }\n\n // Opposite-point correction: capture where the opposite point sat on the\n // ORIGINAL box, recompute it on the resized box, and shift `left`/`top`\n // back by the drift so the opposite handle stays visually fixed.\n const basePoint = getOppositePoint(\n handle,\n getRotateElementPoints(\n { left: originLeft, top: originTop, width: originWidth, height: originHeight },\n rotate,\n ),\n );\n const currentPoint = getOppositePoint(\n handle,\n getRotateElementPoints({ left, top, width, height }, rotate),\n );\n\n left -= currentPoint.left - basePoint.left;\n top -= currentPoint.top - basePoint.top;\n\n return { props: { left, top, width, height }, guides };\n }\n\n // UN-ROTATED path: the pointer delta applies directly, with alignment\n // snapping of the moving corner/edge and simple left/top shifts.\n let moveX = deltaCanvas.x;\n let moveY = deltaCanvas.y;\n\n // Aspect lock (corners only), pre-snap: same derivation as the rotated path.\n if (fixedRatio) {\n if (handle === 'right-bottom' || handle === 'left-top') moveY = moveX / aspectRatio;\n if (handle === 'left-bottom' || handle === 'right-top') moveY = -moveX / aspectRatio;\n }\n\n const resolved = resolveSnapping(snapping);\n const lines = resolved\n ? buildAlignLines(\n // Rotated siblings and lines are excluded from resize snap candidates\n // (app parity): a rotated element's axis-aligned bbox edges are not\n // where anything visually aligns, and a line has no box to align to.\n others.filter((o) => o.type !== 'line' && !(o.rotate ?? 0)),\n viewport,\n resolved.opts,\n )\n : null;\n\n // Snap the MOVING point (the operated corner, or the moving edge on one\n // axis) against the candidate lines, BEFORE clamping. A degenerate\n // single-point range makes `snapRange` probe exactly that point; edge\n // handles suppress the non-moving axis by passing it no candidate lines.\n const snapPoint = (\n probeX: number,\n probeY: number,\n axes: 'both' | 'x' | 'y',\n ): { dx: number; dy: number } => {\n if (!lines || !resolved) return { dx: 0, dy: 0 };\n const {\n dx,\n dy,\n guides: g,\n } = snapRange(\n { minX: probeX, maxX: probeX, minY: probeY, maxY: probeY },\n {\n vertical: axes === 'y' ? [] : lines.vertical,\n horizontal: axes === 'x' ? [] : lines.horizontal,\n },\n resolved.range,\n );\n guides = g;\n return { dx, dy };\n };\n\n // Post-snap aspect re-lock (corners): if the vertical axis snapped, it wins\n // and the horizontal delta is recomputed from it; otherwise the horizontal\n // delta drives, exactly as in the pre-snap derivation.\n const relockAspect = (dy: number, sign: 1 | -1) => {\n if (!fixedRatio) return;\n if (dy !== 0) moveX = sign * moveY * aspectRatio;\n else moveY = (sign * moveX) / aspectRatio;\n };\n\n if (handle === 'right-bottom') {\n const { dx, dy } = snapPoint(\n originLeft + originWidth + moveX,\n originTop + originHeight + moveY,\n 'both',\n );\n moveX += dx;\n moveY += dy;\n relockAspect(dy, 1);\n width = getSizeWithinRange(originWidth + moveX, 'width');\n height = getSizeWithinRange(originHeight + moveY, 'height');\n } else if (handle === 'left-bottom') {\n const { dx, dy } = snapPoint(originLeft + moveX, originTop + originHeight + moveY, 'both');\n moveX += dx;\n moveY += dy;\n relockAspect(dy, -1);\n width = getSizeWithinRange(originWidth - moveX, 'width');\n height = getSizeWithinRange(originHeight + moveY, 'height');\n left = originLeft - (width - originWidth);\n } else if (handle === 'left-top') {\n const { dx, dy } = snapPoint(originLeft + moveX, originTop + moveY, 'both');\n moveX += dx;\n moveY += dy;\n relockAspect(dy, 1);\n width = getSizeWithinRange(originWidth - moveX, 'width');\n height = getSizeWithinRange(originHeight - moveY, 'height');\n left = originLeft - (width - originWidth);\n top = originTop - (height - originHeight);\n } else if (handle === 'right-top') {\n const { dx, dy } = snapPoint(originLeft + originWidth + moveX, originTop + moveY, 'both');\n moveX += dx;\n moveY += dy;\n relockAspect(dy, -1);\n width = getSizeWithinRange(originWidth + moveX, 'width');\n height = getSizeWithinRange(originHeight - moveY, 'height');\n top = originTop - (height - originHeight);\n } else if (handle === 'left') {\n const { dx } = snapPoint(originLeft + moveX, originTop, 'x');\n moveX += dx;\n width = getSizeWithinRange(originWidth - moveX, 'width');\n left = originLeft - (width - originWidth);\n } else if (handle === 'right') {\n const { dx } = snapPoint(originLeft + originWidth + moveX, originTop, 'x');\n moveX += dx;\n width = getSizeWithinRange(originWidth + moveX, 'width');\n } else if (handle === 'top') {\n const { dy } = snapPoint(originLeft, originTop + moveY, 'y');\n moveY += dy;\n height = getSizeWithinRange(originHeight - moveY, 'height');\n top = originTop - (height - originHeight);\n } else if (handle === 'bottom') {\n const { dy } = snapPoint(originLeft, originTop + originHeight + moveY, 'y');\n moveY += dy;\n height = getSizeWithinRange(originHeight + moveY, 'height');\n }\n\n return { props: { left, top, width, height }, guides };\n}\n"],"names":[],"mappings":";;;AAiCA;AACO,MAAM,cAAc,GAA4B;IACrD,UAAU;IACV,KAAK;IACL,WAAW;IACX,MAAM;IACN,OAAO;IACP,aAAa;IACb,QAAQ;IACR,cAAc;;AAGhB;AACO,MAAM,eAAe,GAAuC;AACjE,IAAA,UAAU,EAAE,cAAc;AAC1B,IAAA,GAAG,EAAE,QAAQ;AACb,IAAA,WAAW,EAAE,aAAa;AAC1B,IAAA,IAAI,EAAE,OAA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M,EAAE;AACxD;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { PPTElement } from '@openmaic/dsl';
|
|
2
|
+
/**
|
|
3
|
+
* Pure, store-free core for the rotate gesture. Ported from the app's
|
|
4
|
+
* rotate-element gesture, but with no React/store/DOM: the caller feeds the
|
|
5
|
+
* ORIGINAL element's box plus the pointer position already converted to canvas
|
|
6
|
+
* units, and gets back the new signed rotation angle. No `@/` imports — this
|
|
7
|
+
* module only consumes the DSL element shape and plain numbers.
|
|
8
|
+
*/
|
|
9
|
+
/** Snap threshold (degrees) around the 45deg multiples. Mirrors the app. */
|
|
10
|
+
export declare const ROTATE_SNAP_RANGE = 5;
|
|
11
|
+
/** Whether an element kind supports the rotate gesture. */
|
|
12
|
+
export declare function canRotate(element: PPTElement): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Rotate input for one gesture tick: the ORIGINAL element's box (the rotation
|
|
15
|
+
* center is its center and never moves during the gesture) and the pointer
|
|
16
|
+
* position in canvas units.
|
|
17
|
+
*/
|
|
18
|
+
export interface RotateInput {
|
|
19
|
+
element: {
|
|
20
|
+
left: number;
|
|
21
|
+
top: number;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
};
|
|
25
|
+
pointerCanvas: {
|
|
26
|
+
x: number;
|
|
27
|
+
y: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The new rotation for a box whose rotate handle is dragged to `pointerCanvas`:
|
|
32
|
+
* the CSS-clockwise angle of center->pointer measured from straight up, snapped
|
|
33
|
+
* to the nearest multiple of 45deg when within {@link ROTATE_SNAP_RANGE}. The
|
|
34
|
+
* result is SIGNED in `(-180, 180]` (never normalized to `[0, 360)`), matching
|
|
35
|
+
* how the app stores `rotate`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function computeRotate(input: RotateInput): number;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, store-free core for the rotate gesture. Ported from the app's
|
|
3
|
+
* rotate-element gesture, but with no React/store/DOM: the caller feeds the
|
|
4
|
+
* ORIGINAL element's box plus the pointer position already converted to canvas
|
|
5
|
+
* units, and gets back the new signed rotation angle. No `@/` imports — this
|
|
6
|
+
* module only consumes the DSL element shape and plain numbers.
|
|
7
|
+
*/
|
|
8
|
+
/** Snap threshold (degrees) around the 45deg multiples. Mirrors the app. */
|
|
9
|
+
const ROTATE_SNAP_RANGE = 5;
|
|
10
|
+
/**
|
|
11
|
+
* Element kinds that expose a rotate handle (app parity): the app's operate
|
|
12
|
+
* layer renders no rotate handle for charts, video, or audio (and lines have
|
|
13
|
+
* no `rotate` at all; code blocks render no operate handles whatsoever).
|
|
14
|
+
*/
|
|
15
|
+
const ROTATABLE_TYPES = new Set([
|
|
16
|
+
'text',
|
|
17
|
+
'image',
|
|
18
|
+
'shape',
|
|
19
|
+
'table',
|
|
20
|
+
'latex',
|
|
21
|
+
]);
|
|
22
|
+
/** Whether an element kind supports the rotate gesture. */
|
|
23
|
+
function canRotate(element) {
|
|
24
|
+
return ROTATABLE_TYPES.has(element.type);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Angle (degrees) of the ray from the origin to `(x, y)`, measured CLOCKWISE
|
|
28
|
+
* from straight up — matching CSS `rotate()` — via `atan2(x, y)` (note the
|
|
29
|
+
* argument order: x first). Range `(-180, 180]`.
|
|
30
|
+
*/
|
|
31
|
+
function getAngleFromCoordinate(x, y) {
|
|
32
|
+
const radian = Math.atan2(x, y);
|
|
33
|
+
return (180 / Math.PI) * radian;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The new rotation for a box whose rotate handle is dragged to `pointerCanvas`:
|
|
37
|
+
* the CSS-clockwise angle of center->pointer measured from straight up, snapped
|
|
38
|
+
* to the nearest multiple of 45deg when within {@link ROTATE_SNAP_RANGE}. The
|
|
39
|
+
* result is SIGNED in `(-180, 180]` (never normalized to `[0, 360)`), matching
|
|
40
|
+
* how the app stores `rotate`.
|
|
41
|
+
*/
|
|
42
|
+
function computeRotate(input) {
|
|
43
|
+
const { element, pointerCanvas } = input;
|
|
44
|
+
const centerX = element.left + element.width / 2;
|
|
45
|
+
const centerY = element.top + element.height / 2;
|
|
46
|
+
// Screen-y grows downward, so invert the vertical component to measure the
|
|
47
|
+
// angle in the y-up frame `getAngleFromCoordinate` expects.
|
|
48
|
+
const x = pointerCanvas.x - centerX;
|
|
49
|
+
const y = centerY - pointerCanvas.y;
|
|
50
|
+
let angle = getAngleFromCoordinate(x, y);
|
|
51
|
+
// Snap to multiples of 45deg when close (0, +-45, +-90, +-135, +-180).
|
|
52
|
+
if (Math.abs(angle) <= ROTATE_SNAP_RANGE)
|
|
53
|
+
angle = 0;
|
|
54
|
+
else if (angle > 0 && Math.abs(angle - 45) <= ROTATE_SNAP_RANGE)
|
|
55
|
+
angle = 45;
|
|
56
|
+
else if (angle < 0 && Math.abs(angle + 45) <= ROTATE_SNAP_RANGE)
|
|
57
|
+
angle = -45;
|
|
58
|
+
else if (angle > 0 && Math.abs(angle - 90) <= ROTATE_SNAP_RANGE)
|
|
59
|
+
angle = 90;
|
|
60
|
+
else if (angle < 0 && Math.abs(angle + 90) <= ROTATE_SNAP_RANGE)
|
|
61
|
+
angle = -90;
|
|
62
|
+
else if (angle > 0 && Math.abs(angle - 135) <= ROTATE_SNAP_RANGE)
|
|
63
|
+
angle = 135;
|
|
64
|
+
else if (angle < 0 && Math.abs(angle + 135) <= ROTATE_SNAP_RANGE)
|
|
65
|
+
angle = -135;
|
|
66
|
+
else if (angle > 0 && Math.abs(angle - 180) <= ROTATE_SNAP_RANGE)
|
|
67
|
+
angle = 180;
|
|
68
|
+
else if (angle < 0 && Math.abs(angle + 180) <= ROTATE_SNAP_RANGE)
|
|
69
|
+
angle = -180;
|
|
70
|
+
return angle;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { ROTATE_SNAP_RANGE, canRotate, computeRotate };
|
|
74
|
+
//# sourceMappingURL=rotate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rotate.js","sources":["../../../src/editing/core/rotate.ts"],"sourcesContent":["import type { PPTElement } from '@openmaic/dsl';\n\n/**\n * Pure, store-free core for the rotate gesture. Ported from the app's\n * rotate-element gesture, but with no React/store/DOM: the caller feeds the\n * ORIGINAL element's box plus the pointer position already converted to canvas\n * units, and gets back the new signed rotation angle. No `@/` imports — this\n * module only consumes the DSL element shape and plain numbers.\n */\n\n/** Snap threshold (degrees) around the 45deg multiples. Mirrors the app. */\nexport const ROTATE_SNAP_RANGE = 5;\n\n/**\n * Element kinds that expose a rotate handle (app parity): the app's operate\n * layer renders no rotate handle for charts, video, or audio (and lines have\n * no `rotate` at all; code blocks render no operate handles whatsoever).\n */\nconst ROTATABLE_TYPES: ReadonlySet<PPTElement['type']> = new Set([\n 'text',\n 'image',\n 'shape',\n 'table',\n 'latex',\n]);\n\n/** Whether an element kind supports the rotate gesture. */\nexport function canRotate(element: PPTElement): boolean {\n return ROTATABLE_TYPES.has(element.type);\n}\n\n/**\n * Angle (degrees) of the ray from the origin to `(x, y)`, measured CLOCKWISE\n * from straight up — matching CSS `rotate()` — via `atan2(x, y)` (note the\n * argument order: x first). Range `(-180, 180]`.\n */\nfunction getAngleFromCoordinate(x: number, y: number): number {\n const radian = Math.atan2(x, y);\n return (180 / Math.PI) * radian;\n}\n\n/**\n * Rotate input for one gesture tick: the ORIGINAL element's box (the rotation\n * center is its center and never moves during the gesture) and the pointer\n * position in canvas units.\n */\nexport interface RotateInput {\n element: { left: number; top: number; width: number; height: number };\n pointerCanvas: { x: number; y: number };\n}\n\n/**\n * The new rotation for a box whose rotate handle is dragged to `pointerCanvas`:\n * the CSS-clockwise angle of center->pointer measured from straight up, snapped\n * to the nearest multiple of 45deg when within {@link ROTATE_SNAP_RANGE}. The\n * result is SIGNED in `(-180, 180]` (never normalized to `[0, 360)`), matching\n * how the app stores `rotate`.\n */\nexport function computeRotate(input: RotateInput): number {\n const { element, pointerCanvas } = input;\n\n const centerX = element.left + element.width / 2;\n const centerY = element.top + element.height / 2;\n\n // Screen-y grows downward, so invert the vertical component to measure the\n // angle in the y-up frame `getAngleFromCoordinate` expects.\n const x = pointerCanvas.x - centerX;\n const y = centerY - pointerCanvas.y;\n\n let angle = getAngleFromCoordinate(x, y);\n\n // Snap to multiples of 45deg when close (0, +-45, +-90, +-135, +-180).\n if (Math.abs(angle) <= ROTATE_SNAP_RANGE) angle = 0;\n else if (angle > 0 && Math.abs(angle - 45) <= ROTATE_SNAP_RANGE) angle = 45;\n else if (angle < 0 && Math.abs(angle + 45) <= ROTATE_SNAP_RANGE) angle = -45;\n else if (angle > 0 && Math.abs(angle - 90) <= ROTATE_SNAP_RANGE) angle = 90;\n else if (angle < 0 && Math.abs(angle + 90) <= ROTATE_SNAP_RANGE) angle = -90;\n else if (angle > 0 && Math.abs(angle - 135) <= ROTATE_SNAP_RANGE) angle = 135;\n else if (angle < 0 && Math.abs(angle + 135) <= ROTATE_SNAP_RANGE) angle = -135;\n else if (angle > 0 && Math.abs(angle - 180) <= ROTATE_SNAP_RANGE) angle = 180;\n else if (angle < 0 && Math.abs(angle + 180) <= ROTATE_SNAP_RANGE) angle = -180;\n\n return angle;\n}\n"],"names":[],"mappings":"AAEA;;;;;;AAMG;AAEH;AACO,MAAM,iBAAiB,GAAG;AAEjC;;;;AAIG;AACH,MAAM,eAAe,GAAoC,IAAI,GAAG,CAAC;IAC/D,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;AACR,CAAA,CAAC;AAEF;AACM,SAAU,SAAS,CAAC,OAAmB,EAAA;IAC3C,OAAO,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;AAC1C;AAEA;;;;AAIG;AACH,SAAS,sBAAsB,CAAC,CAAS,EAAE,CAAS,EAAA;IAClD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IA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iBAAiB;QAAE,KAAK,GAAG,GAAG;AACxE,SAAA,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,iBAAiB;QAAE,KAAK,GAAG,IAAI;AACzE,SAAA,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,iBAAiB;QAAE,KAAK,GAAG,GAAG;AACxE,SAAA,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,IAAI,iBAAiB;QAAE,KAAK,GAAG,IAAI;AAE9E,IAAA,OAAO,KAAK;AACd;;;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { PPTElement } from '@openmaic/dsl';
|
|
2
|
+
import type { Selection } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Pure click-selection resolution for the editing surface, shared by every
|
|
5
|
+
* pointer-down entry point (box hit targets and line stroke blockers) so all
|
|
6
|
+
* element kinds resolve modifiers and groups identically. No React, no store,
|
|
7
|
+
* no `@/` imports — plain data in, plain data out.
|
|
8
|
+
*/
|
|
9
|
+
/** True when a click/drag selection modifier (Ctrl/Shift/Meta) is held. Meta is
|
|
10
|
+
* included for mac parity with the resize aspect modifier — a deliberate
|
|
11
|
+
* superset of the app's Ctrl/Shift. */
|
|
12
|
+
export declare function isSelectionModifier(e: {
|
|
13
|
+
ctrlKey: boolean;
|
|
14
|
+
shiftKey: boolean;
|
|
15
|
+
metaKey: boolean;
|
|
16
|
+
}): boolean;
|
|
17
|
+
/** Dedup ids preserving first-seen order (no lodash dep in this package). */
|
|
18
|
+
export declare function uniqIds(ids: readonly string[]): string[];
|
|
19
|
+
/**
|
|
20
|
+
* The clicked element's cohesion unit: every member of its group (in element
|
|
21
|
+
* order), or just the element itself when ungrouped. Group cohesion is
|
|
22
|
+
* all-or-nothing at the click entry point too (app parity): selecting,
|
|
23
|
+
* adding, or removing a grouped element always applies to the whole group,
|
|
24
|
+
* so a group can never be half-selected by clicking. Locked members are
|
|
25
|
+
* included — they may sit in the selection for feedback; the drag layer is
|
|
26
|
+
* responsible for never translating them.
|
|
27
|
+
*/
|
|
28
|
+
export declare function groupMemberIds(el: PPTElement, elements: readonly PPTElement[]): string[];
|
|
29
|
+
export interface ClickSelectionInput {
|
|
30
|
+
/** The element under the pointer. */
|
|
31
|
+
element: PPTElement;
|
|
32
|
+
/** The slide's elements (group-membership lookup). */
|
|
33
|
+
elements: readonly PPTElement[];
|
|
34
|
+
/** The current controlled selection. */
|
|
35
|
+
selection: Selection;
|
|
36
|
+
/** Whether a selection modifier (Ctrl/Shift/Meta) was held at pointer-down. */
|
|
37
|
+
modifier: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface ClickSelectionResult {
|
|
40
|
+
/** The selection to publish, or `null` when nothing changes (no emit). */
|
|
41
|
+
next: Selection | null;
|
|
42
|
+
/** Whether this pointer-down arms a move gesture (plain clicks only). */
|
|
43
|
+
armDrag: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The ids an armed drag translates: the clicked element's group unit for a
|
|
46
|
+
* fresh plain click, or the group-closed current selection for a plain click
|
|
47
|
+
* on an already-selected element. Meaningless when `armDrag` is false.
|
|
48
|
+
*/
|
|
49
|
+
dragIds: readonly string[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolve a pointer-down on element `el` against the current `selection` per
|
|
53
|
+
* the modifier table (group-cohesive — `el` expands to its whole group unit):
|
|
54
|
+
* - not selected, no modifier → select only the unit (primary = clicked);
|
|
55
|
+
* arm a drag on it.
|
|
56
|
+
* - not selected, modifier → ADD the unit to the selection (uniq,
|
|
57
|
+
* primary = clicked); no drag.
|
|
58
|
+
* - selected, modifier → REMOVE the unit; no-op if that would empty
|
|
59
|
+
* the selection; the current primary is preserved when it survives the
|
|
60
|
+
* removal, else the last remaining id becomes primary. No drag.
|
|
61
|
+
* - selected, no modifier → KEEP the whole selection, make the clicked
|
|
62
|
+
* element the primary (no emit when it already is), and arm a drag that
|
|
63
|
+
* translates every selected element.
|
|
64
|
+
*
|
|
65
|
+
* Invariant: this resolver never returns a selection or armed drag set that
|
|
66
|
+
* splits a group, even when the incoming controlled selection already does.
|
|
67
|
+
*/
|
|
68
|
+
export declare function resolveClickSelection(input: ClickSelectionInput): ClickSelectionResult;
|