@openmaic/renderer 0.0.5 → 0.1.0
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/README.md +14 -1
- package/dist/SlideCanvas.d.ts +14 -1
- package/dist/SlideCanvas.js +17 -7
- package/dist/SlideCanvas.js.map +1 -1
- package/dist/SlideElement.d.ts +10 -2
- package/dist/SlideElement.js +16 -5
- package/dist/SlideElement.js.map +1 -1
- package/dist/elements/audio/BaseAudioElement.d.ts +10 -0
- package/dist/elements/audio/BaseAudioElement.js +71 -0
- package/dist/elements/audio/BaseAudioElement.js.map +1 -0
- package/dist/elements/image/BaseImageElement.js +1 -1
- package/dist/elements/image/BaseImageElement.js.map +1 -1
- package/dist/elements/index.d.ts +2 -0
- package/dist/elements/index.js +2 -0
- package/dist/elements/index.js.map +1 -1
- package/dist/elements/shape/BaseShapeElement.d.ts +4 -1
- package/dist/elements/shape/BaseShapeElement.js +19 -18
- package/dist/elements/shape/BaseShapeElement.js.map +1 -1
- package/dist/elements/table/BaseTableElement.d.ts +3 -1
- package/dist/elements/table/BaseTableElement.js +3 -2
- package/dist/elements/table/BaseTableElement.js.map +1 -1
- package/dist/elements/table/StaticTable.js +1 -3
- package/dist/elements/table/StaticTable.js.map +1 -1
- package/dist/elements/text/BaseTextElement.d.ts +3 -1
- package/dist/elements/text/BaseTextElement.js +9 -5
- package/dist/elements/text/BaseTextElement.js.map +1 -1
- package/dist/elements/video/BaseVideoElement.js +1 -1
- package/dist/elements/video/BaseVideoElement.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/styles.d.ts +5 -6
- package/dist/styles.js +21 -5
- package/dist/styles.js.map +1 -1
- package/package.json +2 -6
- package/dist/editing/EditableSlideCanvas.d.ts +0 -26
- package/dist/editing/EditableSlideCanvas.js +0 -352
- package/dist/editing/EditableSlideCanvas.js.map +0 -1
- package/dist/editing/core/drag.d.ts +0 -108
- package/dist/editing/core/drag.js +0 -119
- package/dist/editing/core/drag.js.map +0 -1
- package/dist/editing/core/geometry.d.ts +0 -48
- package/dist/editing/core/geometry.js +0 -186
- package/dist/editing/core/geometry.js.map +0 -1
- package/dist/editing/core/intent.d.ts +0 -39
- package/dist/editing/core/intent.js +0 -35
- package/dist/editing/core/intent.js.map +0 -1
- package/dist/editing/core/line-drag.d.ts +0 -19
- package/dist/editing/core/line-drag.js +0 -163
- package/dist/editing/core/line-drag.js.map +0 -1
- package/dist/editing/core/marquee.d.ts +0 -56
- package/dist/editing/core/marquee.js +0 -74
- package/dist/editing/core/marquee.js.map +0 -1
- package/dist/editing/core/resize.d.ts +0 -121
- package/dist/editing/core/resize.js +0 -392
- package/dist/editing/core/resize.js.map +0 -1
- package/dist/editing/core/rotate.d.ts +0 -37
- package/dist/editing/core/rotate.js +0 -74
- package/dist/editing/core/rotate.js.map +0 -1
- package/dist/editing/core/selection.d.ts +0 -68
- package/dist/editing/core/selection.js +0 -108
- package/dist/editing/core/selection.js.map +0 -1
- package/dist/editing/core/snapping.d.ts +0 -54
- package/dist/editing/core/snapping.js +0 -96
- package/dist/editing/core/snapping.js.map +0 -1
- package/dist/editing/handles/BorderLine.d.ts +0 -15
- package/dist/editing/handles/BorderLine.js +0 -17
- package/dist/editing/handles/BorderLine.js.map +0 -1
- package/dist/editing/handles/LineHandles.d.ts +0 -28
- package/dist/editing/handles/LineHandles.js +0 -51
- package/dist/editing/handles/LineHandles.js.map +0 -1
- package/dist/editing/handles/MarqueeBox.d.ts +0 -19
- package/dist/editing/handles/MarqueeBox.js +0 -26
- package/dist/editing/handles/MarqueeBox.js.map +0 -1
- package/dist/editing/handles/ResizeHandles.d.ts +0 -31
- package/dist/editing/handles/ResizeHandles.js +0 -44
- package/dist/editing/handles/ResizeHandles.js.map +0 -1
- package/dist/editing/handles/RotateHandle.d.ts +0 -26
- package/dist/editing/handles/RotateHandle.js +0 -52
- package/dist/editing/handles/RotateHandle.js.map +0 -1
- package/dist/editing/handles/SelectionOverlay.d.ts +0 -18
- package/dist/editing/handles/SelectionOverlay.js +0 -35
- package/dist/editing/handles/SelectionOverlay.js.map +0 -1
- package/dist/editing/index.d.ts +0 -3
- package/dist/editing/index.js +0 -4
- package/dist/editing/index.js.map +0 -1
- package/dist/editing/types.d.ts +0 -107
- package/dist/editing/types.js +0 -7
- package/dist/editing/types.js.map +0 -1
- package/dist/editing/useEditGesture.d.ts +0 -46
- package/dist/editing/useEditGesture.js +0 -217
- package/dist/editing/useEditGesture.js.map +0 -1
- package/dist/editing/useLineHandleGesture.d.ts +0 -35
- package/dist/editing/useLineHandleGesture.js +0 -112
- package/dist/editing/useLineHandleGesture.js.map +0 -1
- package/dist/editing/useMarqueeGesture.d.ts +0 -43
- package/dist/editing/useMarqueeGesture.js +0 -157
- package/dist/editing/useMarqueeGesture.js.map +0 -1
- package/dist/editing/useResizeGesture.d.ts +0 -43
- package/dist/editing/useResizeGesture.js +0 -137
- package/dist/editing/useResizeGesture.js.map +0 -1
- package/dist/editing/useRotateGesture.d.ts +0 -47
- package/dist/editing/useRotateGesture.js +0 -128
- package/dist/editing/useRotateGesture.js.map +0 -1
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import { useRef, Fragment } from 'react';
|
|
4
|
-
import { SlideCanvas } from '../SlideCanvas.js';
|
|
5
|
-
import { getLineElementPath } from '../utils/element.js';
|
|
6
|
-
import { useViewportSize } from '../hooks/useViewportSize.js';
|
|
7
|
-
import { SelectionOverlay } from './handles/SelectionOverlay.js';
|
|
8
|
-
import { LineHandles } from './handles/LineHandles.js';
|
|
9
|
-
import { ResizeHandles } from './handles/ResizeHandles.js';
|
|
10
|
-
import { RotateHandle } from './handles/RotateHandle.js';
|
|
11
|
-
import { MarqueeBox } from './handles/MarqueeBox.js';
|
|
12
|
-
import { resolveClickSelection, isSelectionModifier } from './core/selection.js';
|
|
13
|
-
import { useEditGesture } from './useEditGesture.js';
|
|
14
|
-
import { useLineHandleGesture } from './useLineHandleGesture.js';
|
|
15
|
-
import { useMarqueeGesture } from './useMarqueeGesture.js';
|
|
16
|
-
import { useResizeGesture } from './useResizeGesture.js';
|
|
17
|
-
import { useRotateGesture } from './useRotateGesture.js';
|
|
18
|
-
import { getResizeHandles } from './core/resize.js';
|
|
19
|
-
import { canRotate } from './core/rotate.js';
|
|
20
|
-
import { EMPTY_SELECTION } from './types.js';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* EditableSlideCanvas — the renderer v2 editing surface. It renders the
|
|
24
|
-
* controlled document through the v1 read-only {@link SlideCanvas} (whose
|
|
25
|
-
* render path is left untouched) and layers its own interaction surface on top:
|
|
26
|
-
* a per-element hit layer that arms drag/click gestures, and a
|
|
27
|
-
* {@link SelectionOverlay} driven by the controlled `selection`.
|
|
28
|
-
*
|
|
29
|
-
* Gestures are owned by {@link useEditGesture}: pointer-down + drag produces a
|
|
30
|
-
* live working copy for 60fps feedback and, on pointer-up past a small
|
|
31
|
-
* threshold, emits exactly one `element.update` intent via `onElementsChange`;
|
|
32
|
-
* a click with no movement reports selection via `onSelectionChange` only.
|
|
33
|
-
* Alignment guides are computed but not drawn in this PR.
|
|
34
|
-
*
|
|
35
|
-
* The interaction layer is a sibling overlay (same origin, positions scaled by
|
|
36
|
-
* `canvasScale`) so the v1 fill/render contract is preserved unmodified. When
|
|
37
|
-
* `scale` is omitted the canvas auto-fits: the overlay reads the SAME
|
|
38
|
-
* `fitScale` SlideCanvas uses (both measure the same box — see the inner
|
|
39
|
-
* wrapper below), so overlay and elements stay aligned at auto-fit.
|
|
40
|
-
* `renderImage`/`renderVideo`/`className`/`style` pass through.
|
|
41
|
-
*
|
|
42
|
-
* The interaction hit layer is only mounted when a mutation/selection callback
|
|
43
|
-
* is provided; with neither, the canvas renders read-only (no pointer-capturing
|
|
44
|
-
* hit targets), matching the Stage-0 inert-without-callbacks contract.
|
|
45
|
-
*/
|
|
46
|
-
function EditableSlideCanvas(props) {
|
|
47
|
-
const { slide, renderImage, renderVideo, videoInteractive, className, style, selection, onSelectionChange, onElementsChange, snapping, } = props;
|
|
48
|
-
const activeSelection = selection ?? EMPTY_SELECTION;
|
|
49
|
-
const interactive = Boolean(onElementsChange || onSelectionChange);
|
|
50
|
-
// Overlay wrapper is `inset: 0` of the same padding-free inner box that
|
|
51
|
-
// SlideCanvas fills, so its container size — and therefore the fit-computed
|
|
52
|
-
// `fitScale` and centering offset — is identical to SlideCanvas's own.
|
|
53
|
-
// Computing `viewportStyles`/`fitScale` here lets the interaction layer sit
|
|
54
|
-
// at the same on-screen origin and zoom as the rendered elements, including
|
|
55
|
-
// when `scale` is omitted and both sides auto-fit.
|
|
56
|
-
const overlayRef = useRef(null);
|
|
57
|
-
const { viewportStyles, fitScale } = useViewportSize(overlayRef, {
|
|
58
|
-
viewportSize: slide.viewportSize,
|
|
59
|
-
viewportRatio: slide.viewportRatio,
|
|
60
|
-
});
|
|
61
|
-
const canvasScale = props.scale ?? fitScale;
|
|
62
|
-
const { workingSlide, onElementPointerDown } = useEditGesture({
|
|
63
|
-
slide,
|
|
64
|
-
scale: canvasScale,
|
|
65
|
-
selection: activeSelection,
|
|
66
|
-
snapping,
|
|
67
|
-
onSelectionChange,
|
|
68
|
-
onElementsChange,
|
|
69
|
-
});
|
|
70
|
-
// Line-handle reshape gesture. It owns its own working copy (the dragged
|
|
71
|
-
// line's re-normalized props) so a selected line's endpoint/control handles
|
|
72
|
-
// can be dragged to reshape it. This is independent of the box move gesture
|
|
73
|
-
// above — in practice only one is ever in flight — so we layer its working
|
|
74
|
-
// props on top of the box gesture's `workingSlide` below.
|
|
75
|
-
const { lineDrag, onHandlePointerDown } = useLineHandleGesture({
|
|
76
|
-
scale: canvasScale,
|
|
77
|
-
onElementsChange,
|
|
78
|
-
});
|
|
79
|
-
// Resize gesture (8-point handles on selected box elements). Like the line
|
|
80
|
-
// gesture, it owns its own working copy (the resized box props), layered on
|
|
81
|
-
// the box gesture's `workingSlide` below.
|
|
82
|
-
const { resizeDrag, onResizeHandlePointerDown } = useResizeGesture({
|
|
83
|
-
slide,
|
|
84
|
-
scale: canvasScale,
|
|
85
|
-
snapping,
|
|
86
|
-
onElementsChange,
|
|
87
|
-
});
|
|
88
|
-
// Rotate gesture (the handle floating above a box's top edge). It converts
|
|
89
|
-
// absolute pointer positions to canvas coordinates, so it needs the overlay
|
|
90
|
-
// origin (`overlayRef` + `viewportStyles`) rather than just a scale.
|
|
91
|
-
const { rotateDrag, onRotateHandlePointerDown } = useRotateGesture({
|
|
92
|
-
overlayRef,
|
|
93
|
-
viewportStyles,
|
|
94
|
-
scale: canvasScale,
|
|
95
|
-
onElementsChange,
|
|
96
|
-
});
|
|
97
|
-
// Marquee (rubber-band) gesture. It arms from a blank-canvas pointer-down on
|
|
98
|
-
// the capture surface below the element hit targets, tracks a live rectangle,
|
|
99
|
-
// and on release REPLACES the selection with whatever it covers (or clears it
|
|
100
|
-
// on a sub-threshold blank click). The capture surface mounts for selection
|
|
101
|
-
// hosts (`onSelectionChange` — see the surface comment below); the hook itself
|
|
102
|
-
// also requires `onSelectionChange` to publish.
|
|
103
|
-
const { marqueeRect, onCanvasPointerDown } = useMarqueeGesture({
|
|
104
|
-
slide,
|
|
105
|
-
scale: canvasScale,
|
|
106
|
-
overlayRef,
|
|
107
|
-
viewportStyles,
|
|
108
|
-
selection: activeSelection,
|
|
109
|
-
onSelectionChange,
|
|
110
|
-
});
|
|
111
|
-
// The elements to render/hit-test: the box gesture's working copy, with the
|
|
112
|
-
// active handle drag's props (line reshape / resize box / rotate angle)
|
|
113
|
-
// merged in so the v1 canvas, the hit layers, and the handles all preview
|
|
114
|
-
// off the SAME working element and move together during a gesture. At most
|
|
115
|
-
// one handle gesture is ever in flight (single-pointer hooks), so the merges
|
|
116
|
-
// never compete.
|
|
117
|
-
let displayElements = workingSlide.elements;
|
|
118
|
-
if (lineDrag) {
|
|
119
|
-
displayElements = displayElements.map((el) => el.id === lineDrag.id ? { ...el, ...lineDrag.props } : el);
|
|
120
|
-
}
|
|
121
|
-
if (resizeDrag) {
|
|
122
|
-
displayElements = displayElements.map((el) => el.id === resizeDrag.id ? { ...el, ...resizeDrag.props } : el);
|
|
123
|
-
}
|
|
124
|
-
if (rotateDrag) {
|
|
125
|
-
displayElements = displayElements.map((el) => el.id === rotateDrag.id ? { ...el, rotate: rotateDrag.rotate } : el);
|
|
126
|
-
}
|
|
127
|
-
const displaySlide = displayElements === workingSlide.elements
|
|
128
|
-
? workingSlide
|
|
129
|
-
: { ...workingSlide, elements: displayElements };
|
|
130
|
-
const elements = displayElements;
|
|
131
|
-
// Touch suppression belongs to mutation gestures: select-only hosts keep
|
|
132
|
-
// native touch panning, while tap-select still receives pointer events.
|
|
133
|
-
const editingTouchAction = onElementsChange ? 'none' : undefined;
|
|
134
|
-
return (
|
|
135
|
-
// Outer wrapper carries the documented `className`/`style` pass-through
|
|
136
|
-
// (which may add padding). It fills its container by default (`width`/
|
|
137
|
-
// `height: 100%`, merged BEFORE `...style` so a consumer can still override)
|
|
138
|
-
// — without an explicit height the inner `height: 100%` (and SlideCanvas's
|
|
139
|
-
// own `height: 100%`) would resolve against an auto-height box, so
|
|
140
|
-
// `useViewportSize` reads `clientHeight ≈ 0`, `fitScale ≈ 0`, and the canvas
|
|
141
|
-
// renders blank when `scale` is omitted. The inner wrapper below is
|
|
142
|
-
// padding-free so that SlideCanvas (normal flow) and the overlay (`inset: 0`)
|
|
143
|
-
// always measure the same box — otherwise consumer padding would diverge
|
|
144
|
-
// their box models and misalign the overlay from the rendered elements.
|
|
145
|
-
jsx("div", { className: className, style: { width: '100%', height: '100%', ...style }, children: jsxs("div", { style: { position: 'relative', width: '100%', height: '100%' }, children: [jsx(SlideCanvas, { slide: displaySlide, scale: props.scale, renderImage: renderImage, renderVideo: renderVideo, videoInteractive: videoInteractive }), jsxs("div", { ref: overlayRef, style: { position: 'absolute', inset: 0, pointerEvents: 'none' }, children: [Boolean(onSelectionChange) && (jsx("div", { "data-marquee-surface": "", onPointerDown: onCanvasPointerDown, style: {
|
|
146
|
-
position: 'absolute',
|
|
147
|
-
inset: 0,
|
|
148
|
-
pointerEvents: 'auto',
|
|
149
|
-
touchAction: editingTouchAction,
|
|
150
|
-
} })), elements.map((el) => {
|
|
151
|
-
// Line elements: a line's real hit area is its (often bent) stroke,
|
|
152
|
-
// not its rectangular bounding box. A rectangular bbox blocker
|
|
153
|
-
// would wrongly swallow clicks on other elements around a thin
|
|
154
|
-
// diagonal line, and a straight start->end strip misses the
|
|
155
|
-
// visible stroke of broken/broken2/curve/cubic lines (which bend
|
|
156
|
-
// away from that chord) while blocking empty space where nothing
|
|
157
|
-
// is drawn. Instead render an INERT SVG-path blocker that mirrors
|
|
158
|
-
// the v1 line renderer pixel-for-pixel.
|
|
159
|
-
//
|
|
160
|
-
// v1 (src/elements/line/BaseLineElement.tsx:70-132) draws the line
|
|
161
|
-
// at (el.left, el.top) inside SlideCanvas's `transform:
|
|
162
|
-
// scale(canvasScale)` element container (SlideCanvas.tsx:153-163),
|
|
163
|
-
// as an <svg overflow:visible> whose <path d={getLineElementPath}>
|
|
164
|
-
// is in raw canvas units with stroke-width = el.width canvas units.
|
|
165
|
-
// We reproduce that exactly: the wrapper sits at the same screen
|
|
166
|
-
// origin as the other hit layers (viewportStyles.left/top +
|
|
167
|
-
// coord*canvasScale) and the inner <svg> carries `transform:
|
|
168
|
-
// scale(canvasScale)` (origin 0 0), so its raw-canvas-unit path maps
|
|
169
|
-
// to the same on-screen pixels as the rendered line.
|
|
170
|
-
//
|
|
171
|
-
// `pointer-events: stroke` makes ONLY the fat transparent stroke a
|
|
172
|
-
// hit target: it covers the visible line for EVERY path shape (P2)
|
|
173
|
-
// and leaves the empty bbox click-through. The stroke width is the
|
|
174
|
-
// grab band, at least the rendered stroke and at least a 10px
|
|
175
|
-
// screen minimum (P3). It is INERT: `onPointerDown` only stops
|
|
176
|
-
// propagation — no `data-element-id`, no gesture armed.
|
|
177
|
-
// Known gap: endpoint markers (arrow/dot) can paint beyond the
|
|
178
|
-
// stroke; their extents are NOT part of this hit target. Covering
|
|
179
|
-
// them is deferred with line editing — the only fall-through case
|
|
180
|
-
// is a marked line overlapping other content exactly at an
|
|
181
|
-
// endpoint, on an element type that is not yet editable here.
|
|
182
|
-
// A line is selected when its id is in the controlled selection.
|
|
183
|
-
// Hit geometry and visual chrome are SPLIT into two paths (below):
|
|
184
|
-
// a stable transparent blocker (the hit region, identical whether
|
|
185
|
-
// or not the line is selected — so selecting a line never shrinks
|
|
186
|
-
// its hit band) plus a separate, non-interactive highlight path
|
|
187
|
-
// drawn only when selected. So a selected line has feedback in
|
|
188
|
-
// EVERY state: read-only (no-callback), locked, or editable.
|
|
189
|
-
// Handles (drawn much further below) are only added when the line
|
|
190
|
-
// is EDITABLE (`onElementsChange`) and unlocked.
|
|
191
|
-
const isSelected = activeSelection.elementIds.includes(el.id);
|
|
192
|
-
if (el.type === 'line') {
|
|
193
|
-
// Render the line's blocker/highlight path when it is either a
|
|
194
|
-
// live hit target (interactive) OR selected (to draw the
|
|
195
|
-
// highlight in a read-only mount). A read-only, unselected line
|
|
196
|
-
// needs neither, so skip it.
|
|
197
|
-
if (!interactive && !isSelected)
|
|
198
|
-
return null;
|
|
199
|
-
const path = getLineElementPath(el);
|
|
200
|
-
// Match v1's svg box (min 24) so overflow:visible has a sensible
|
|
201
|
-
// frame; the fat stroke can extend beyond it (not clipped).
|
|
202
|
-
const spanW = Math.abs(el.start[0] - el.end[0]);
|
|
203
|
-
const spanH = Math.abs(el.start[1] - el.end[1]);
|
|
204
|
-
const svgWidth = spanW < 24 ? 24 : spanW;
|
|
205
|
-
const svgHeight = spanH < 24 ? 24 : spanH;
|
|
206
|
-
// Screen grab band, then converted to canvas units for the path
|
|
207
|
-
// drawn inside the scale(canvasScale) svg (divide by scale so the
|
|
208
|
-
// painted screen width is exactly `grabScreenPx`).
|
|
209
|
-
const grabScreenPx = Math.max(10, el.width * canvasScale);
|
|
210
|
-
const grabCanvas = canvasScale > 0 ? grabScreenPx / canvasScale : grabScreenPx;
|
|
211
|
-
// Selection highlight stroke width, in the SAME canvas units the
|
|
212
|
-
// blocker's stroke-width uses (the path is drawn inside a
|
|
213
|
-
// `scale(canvasScale)` svg). At least the rendered stroke, and at
|
|
214
|
-
// least 2 canvas units so a hairline line still shows a visible
|
|
215
|
-
// highlight (~`max(2, el.width) * canvasScale` screen px).
|
|
216
|
-
const highlightCanvas = Math.max(2, el.width);
|
|
217
|
-
return (jsx("div", { style: {
|
|
218
|
-
position: 'absolute',
|
|
219
|
-
left: `${viewportStyles.left + el.left * canvasScale}px`,
|
|
220
|
-
top: `${viewportStyles.top + el.top * canvasScale}px`,
|
|
221
|
-
width: 0,
|
|
222
|
-
height: 0,
|
|
223
|
-
pointerEvents: 'none',
|
|
224
|
-
overflow: 'visible',
|
|
225
|
-
}, children: jsxs("svg", { overflow: "visible", width: svgWidth, height: svgHeight, style: {
|
|
226
|
-
overflow: 'visible',
|
|
227
|
-
transform: `scale(${canvasScale})`,
|
|
228
|
-
transformOrigin: '0 0',
|
|
229
|
-
pointerEvents: 'none',
|
|
230
|
-
}, children: [jsx("path", { "data-hit-kind": "line", d: path, fill: "none", stroke: "transparent", strokeWidth: grabCanvas, pointerEvents: interactive ? 'stroke' : 'none', onPointerDown: (e) => {
|
|
231
|
-
// Deferred limitation: line selection is handled here
|
|
232
|
-
// directly and bypasses `useEditGesture`, so it also
|
|
233
|
-
// bypasses the `activePointerRef` multi-pointer guard.
|
|
234
|
-
// A second pointer-down on a line during an in-flight
|
|
235
|
-
// box drag can therefore change the selection mid-
|
|
236
|
-
// gesture. More generally, the single-pointer guarantee
|
|
237
|
-
// is PER-HOOK: each gesture hook (move/marquee/line-
|
|
238
|
-
// handle/resize/rotate) guards only its own active
|
|
239
|
-
// pointer, so a second pointer can still arm a
|
|
240
|
-
// DIFFERENT hook's gesture concurrently. Cross-hook
|
|
241
|
-
// arbitration is deferred together with multi-touch
|
|
242
|
-
// support; single-pointer/mouse use (only one active
|
|
243
|
-
// pointer at a time) is unaffected.
|
|
244
|
-
//
|
|
245
|
-
// Always consume the pointer to block fall-through to
|
|
246
|
-
// an overlapped box beneath (even with no selection
|
|
247
|
-
// callback, and even when the line is locked). When a
|
|
248
|
-
// selection callback is provided, resolve the click
|
|
249
|
-
// through the SAME modifier/selection table as box
|
|
250
|
-
// elements ({@link resolveClickSelection}) so a
|
|
251
|
-
// modifier click adds/removes a line from a multi-
|
|
252
|
-
// selection too. A line is selectable but NOT draggable
|
|
253
|
-
// here: `armDrag` is ignored, no working copy is armed,
|
|
254
|
-
// and no move intent is ever emitted (line editing
|
|
255
|
-
// deferred).
|
|
256
|
-
e.stopPropagation();
|
|
257
|
-
// A locked line is inert like a locked box: it blocks
|
|
258
|
-
// fall-through (stopPropagation above) but must not be
|
|
259
|
-
// selected.
|
|
260
|
-
if (el.lock)
|
|
261
|
-
return;
|
|
262
|
-
const { next } = resolveClickSelection({
|
|
263
|
-
element: el,
|
|
264
|
-
elements: slide.elements,
|
|
265
|
-
selection: activeSelection,
|
|
266
|
-
modifier: isSelectionModifier(e),
|
|
267
|
-
});
|
|
268
|
-
// `next` is null when nothing changes (e.g. a re-click
|
|
269
|
-
// on the current primary, or a subtractive click that
|
|
270
|
-
// would empty the selection) — no redundant re-emit.
|
|
271
|
-
if (next)
|
|
272
|
-
onSelectionChange?.(next);
|
|
273
|
-
}, style: { cursor: 'default', touchAction: editingTouchAction } }), isSelected && (jsx("path", { "data-hit-kind": "line-highlight", d: path, fill: "none", stroke: "#3b82f6", strokeOpacity: 0.7, strokeWidth: highlightCanvas, pointerEvents: "none", style: { pointerEvents: 'none' } }))] }) }, el.id));
|
|
274
|
-
}
|
|
275
|
-
// Non-line elements never render an overlay node in a read-only
|
|
276
|
-
// mount (no hit targets, no chrome — their selection border comes
|
|
277
|
-
// from SelectionOverlay). Only lines draw a read-only highlight.
|
|
278
|
-
if (!interactive)
|
|
279
|
-
return null;
|
|
280
|
-
// Non-line elements are narrowed here, so `width`/`height`/`rotate`
|
|
281
|
-
// are directly available (no casts).
|
|
282
|
-
return el.lock ? (
|
|
283
|
-
// Locked elements (`el.lock`): the app editor guards locked
|
|
284
|
-
// content from being moved, and — critically — a locked
|
|
285
|
-
// element is the top rendered DOM node in the real app, so
|
|
286
|
-
// it swallows the click rather than falling through to
|
|
287
|
-
// whatever unlocked element sits beneath it. Mirror that
|
|
288
|
-
// here with an INERT blocker at the same stacking position
|
|
289
|
-
// (same map order, so it's on top when it visually
|
|
290
|
-
// overlaps an unlocked element below it in the array):
|
|
291
|
-
// `pointerEvents: 'auto'` consumes the pointer, but
|
|
292
|
-
// `onPointerDown` is a no-op (no `onElementPointerDown`
|
|
293
|
-
// call, no `data-element-id`) so no gesture is ever armed
|
|
294
|
-
// and nothing beneath moves or gets selected. (A locked
|
|
295
|
-
// element's selection border, if selected, is unaffected —
|
|
296
|
-
// SelectionOverlay is untouched.)
|
|
297
|
-
jsx("div", { "data-hit-kind": "blocker", onPointerDown: (e) => {
|
|
298
|
-
e.stopPropagation();
|
|
299
|
-
}, style: {
|
|
300
|
-
position: 'absolute',
|
|
301
|
-
left: `${viewportStyles.left + el.left * canvasScale}px`,
|
|
302
|
-
top: `${viewportStyles.top + el.top * canvasScale}px`,
|
|
303
|
-
width: `${el.width * canvasScale}px`,
|
|
304
|
-
height: `${el.height * canvasScale}px`,
|
|
305
|
-
transform: `rotate(${el.rotate}deg)`,
|
|
306
|
-
transformOrigin: 'center',
|
|
307
|
-
pointerEvents: 'auto',
|
|
308
|
-
cursor: 'default',
|
|
309
|
-
touchAction: editingTouchAction,
|
|
310
|
-
} }, el.id)) : (jsx("div", { "data-element-id": el.id, onPointerDown: (e) => onElementPointerDown(el, e), style: {
|
|
311
|
-
position: 'absolute',
|
|
312
|
-
left: `${viewportStyles.left + el.left * canvasScale}px`,
|
|
313
|
-
top: `${viewportStyles.top + el.top * canvasScale}px`,
|
|
314
|
-
width: `${el.width * canvasScale}px`,
|
|
315
|
-
height: `${el.height * canvasScale}px`,
|
|
316
|
-
transform: `rotate(${el.rotate}deg)`,
|
|
317
|
-
transformOrigin: 'center',
|
|
318
|
-
pointerEvents: 'auto',
|
|
319
|
-
cursor: 'move',
|
|
320
|
-
touchAction: editingTouchAction,
|
|
321
|
-
} }, el.id));
|
|
322
|
-
}), Boolean(onElementsChange) &&
|
|
323
|
-
elements.map((el) => {
|
|
324
|
-
if (el.type !== 'line')
|
|
325
|
-
return null;
|
|
326
|
-
if (!activeSelection.elementIds.includes(el.id) || el.lock)
|
|
327
|
-
return null;
|
|
328
|
-
return (jsx(LineHandles, { element: el, viewportStyles: viewportStyles, canvasScale: canvasScale, onHandlePointerDown: (handle, e) => onHandlePointerDown(el, handle, e) }, `line-handles-${el.id}`));
|
|
329
|
-
}), Boolean(onElementsChange) &&
|
|
330
|
-
activeSelection.elementIds.length === 1 &&
|
|
331
|
-
elements.map((el) => {
|
|
332
|
-
if (el.type === 'line')
|
|
333
|
-
return null;
|
|
334
|
-
if (!activeSelection.elementIds.includes(el.id) || el.lock)
|
|
335
|
-
return null;
|
|
336
|
-
const handles = getResizeHandles(el);
|
|
337
|
-
const rotatable = canRotate(el);
|
|
338
|
-
if (handles.length === 0 && !rotatable)
|
|
339
|
-
return null;
|
|
340
|
-
return (jsxs(Fragment, { children: [handles.length > 0 && (jsx(ResizeHandles, { element: el, handles: handles, viewportStyles: viewportStyles, canvasScale: canvasScale, onHandlePointerDown: (handle, e) => onResizeHandlePointerDown(el, handle, e) })), rotatable && (jsx(RotateHandle, { element: el, viewportStyles: viewportStyles, canvasScale: canvasScale, onPointerDown: (e) => onRotateHandlePointerDown(el, e) }))] }, `operate-${el.id}`));
|
|
341
|
-
}), marqueeRect && (jsx(MarqueeBox, { rect: marqueeRect, viewportStyles: viewportStyles, canvasScale: canvasScale })), jsx("div", { style: {
|
|
342
|
-
position: 'absolute',
|
|
343
|
-
left: `${viewportStyles.left}px`,
|
|
344
|
-
top: `${viewportStyles.top}px`,
|
|
345
|
-
width: `${viewportStyles.width * canvasScale}px`,
|
|
346
|
-
height: `${viewportStyles.height * canvasScale}px`,
|
|
347
|
-
pointerEvents: 'none',
|
|
348
|
-
}, children: jsx(SelectionOverlay, { elements: elements, selection: activeSelection, scale: canvasScale }) })] })] }) }));
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
export { EditableSlideCanvas };
|
|
352
|
-
//# sourceMappingURL=EditableSlideCanvas.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EditableSlideCanvas.js","sources":["../../src/editing/EditableSlideCanvas.tsx"],"sourcesContent":["'use client';\n\nimport { Fragment, useRef } from 'react';\nimport type { PPTElement } from '@openmaic/dsl';\n\nimport { SlideCanvas } from '../SlideCanvas';\nimport { getLineElementPath } from '../utils/element';\nimport { useViewportSize } from '../hooks/useViewportSize';\nimport { SelectionOverlay } from './handles/SelectionOverlay';\nimport { LineHandles } from './handles/LineHandles';\nimport { ResizeHandles } from './handles/ResizeHandles';\nimport { RotateHandle } from './handles/RotateHandle';\nimport { MarqueeBox } from './handles/MarqueeBox';\nimport { isSelectionModifier, resolveClickSelection } from './core/selection';\nimport { useEditGesture } from './useEditGesture';\nimport { useLineHandleGesture } from './useLineHandleGesture';\nimport { useMarqueeGesture } from './useMarqueeGesture';\nimport { useResizeGesture } from './useResizeGesture';\nimport { useRotateGesture } from './useRotateGesture';\nimport { getResizeHandles } from './core/resize';\nimport { canRotate } from './core/rotate';\nimport { EMPTY_SELECTION, type EditableSlideCanvasProps } from './types';\n\n/**\n * EditableSlideCanvas — the renderer v2 editing surface. It renders the\n * controlled document through the v1 read-only {@link SlideCanvas} (whose\n * render path is left untouched) and layers its own interaction surface on top:\n * a per-element hit layer that arms drag/click gestures, and a\n * {@link SelectionOverlay} driven by the controlled `selection`.\n *\n * Gestures are owned by {@link useEditGesture}: pointer-down + drag produces a\n * live working copy for 60fps feedback and, on pointer-up past a small\n * threshold, emits exactly one `element.update` intent via `onElementsChange`;\n * a click with no movement reports selection via `onSelectionChange` only.\n * Alignment guides are computed but not drawn in this PR.\n *\n * The interaction layer is a sibling overlay (same origin, positions scaled by\n * `canvasScale`) so the v1 fill/render contract is preserved unmodified. When\n * `scale` is omitted the canvas auto-fits: the overlay reads the SAME\n * `fitScale` SlideCanvas uses (both measure the same box — see the inner\n * wrapper below), so overlay and elements stay aligned at auto-fit.\n * `renderImage`/`renderVideo`/`className`/`style` pass through.\n *\n * The interaction hit layer is only mounted when a mutation/selection callback\n * is provided; with neither, the canvas renders read-only (no pointer-capturing\n * hit targets), matching the Stage-0 inert-without-callbacks contract.\n */\nexport function EditableSlideCanvas(props: EditableSlideCanvasProps) {\n const {\n slide,\n renderImage,\n renderVideo,\n videoInteractive,\n className,\n style,\n selection,\n onSelectionChange,\n onElementsChange,\n snapping,\n } = props;\n\n const activeSelection = selection ?? EMPTY_SELECTION;\n const interactive = Boolean(onElementsChange || onSelectionChange);\n\n // Overlay wrapper is `inset: 0` of the same padding-free inner box that\n // SlideCanvas fills, so its container size — and therefore the fit-computed\n // `fitScale` and centering offset — is identical to SlideCanvas's own.\n // Computing `viewportStyles`/`fitScale` here lets the interaction layer sit\n // at the same on-screen origin and zoom as the rendered elements, including\n // when `scale` is omitted and both sides auto-fit.\n const overlayRef = useRef<HTMLDivElement>(null);\n const { viewportStyles, fitScale } = useViewportSize(overlayRef, {\n viewportSize: slide.viewportSize,\n viewportRatio: slide.viewportRatio,\n });\n const canvasScale = props.scale ?? fitScale;\n\n const { workingSlide, onElementPointerDown } = useEditGesture({\n slide,\n scale: canvasScale,\n selection: activeSelection,\n snapping,\n onSelectionChange,\n onElementsChange,\n });\n\n // Line-handle reshape gesture. It owns its own working copy (the dragged\n // line's re-normalized props) so a selected line's endpoint/control handles\n // can be dragged to reshape it. This is independent of the box move gesture\n // above — in practice only one is ever in flight — so we layer its working\n // props on top of the box gesture's `workingSlide` below.\n const { lineDrag, onHandlePointerDown } = useLineHandleGesture({\n scale: canvasScale,\n onElementsChange,\n });\n\n // Resize gesture (8-point handles on selected box elements). Like the line\n // gesture, it owns its own working copy (the resized box props), layered on\n // the box gesture's `workingSlide` below.\n const { resizeDrag, onResizeHandlePointerDown } = useResizeGesture({\n slide,\n scale: canvasScale,\n snapping,\n onElementsChange,\n });\n\n // Rotate gesture (the handle floating above a box's top edge). It converts\n // absolute pointer positions to canvas coordinates, so it needs the overlay\n // origin (`overlayRef` + `viewportStyles`) rather than just a scale.\n const { rotateDrag, onRotateHandlePointerDown } = useRotateGesture({\n overlayRef,\n viewportStyles,\n scale: canvasScale,\n onElementsChange,\n });\n\n // Marquee (rubber-band) gesture. It arms from a blank-canvas pointer-down on\n // the capture surface below the element hit targets, tracks a live rectangle,\n // and on release REPLACES the selection with whatever it covers (or clears it\n // on a sub-threshold blank click). The capture surface mounts for selection\n // hosts (`onSelectionChange` — see the surface comment below); the hook itself\n // also requires `onSelectionChange` to publish.\n const { marqueeRect, onCanvasPointerDown } = useMarqueeGesture({\n slide,\n scale: canvasScale,\n overlayRef,\n viewportStyles,\n selection: activeSelection,\n onSelectionChange,\n });\n\n // The elements to render/hit-test: the box gesture's working copy, with the\n // active handle drag's props (line reshape / resize box / rotate angle)\n // merged in so the v1 canvas, the hit layers, and the handles all preview\n // off the SAME working element and move together during a gesture. At most\n // one handle gesture is ever in flight (single-pointer hooks), so the merges\n // never compete.\n let displayElements = workingSlide.elements;\n if (lineDrag) {\n displayElements = displayElements.map((el) =>\n el.id === lineDrag.id ? ({ ...el, ...lineDrag.props } as PPTElement) : el,\n );\n }\n if (resizeDrag) {\n displayElements = displayElements.map((el) =>\n el.id === resizeDrag.id ? ({ ...el, ...resizeDrag.props } as PPTElement) : el,\n );\n }\n if (rotateDrag) {\n displayElements = displayElements.map((el) =>\n el.id === rotateDrag.id ? ({ ...el, rotate: rotateDrag.rotate } as PPTElement) : el,\n );\n }\n const displaySlide =\n displayElements === workingSlide.elements\n ? workingSlide\n : { ...workingSlide, elements: displayElements };\n\n const elements = displayElements;\n // Touch suppression belongs to mutation gestures: select-only hosts keep\n // native touch panning, while tap-select still receives pointer events.\n const editingTouchAction = onElementsChange ? 'none' : undefined;\n\n return (\n // Outer wrapper carries the documented `className`/`style` pass-through\n // (which may add padding). It fills its container by default (`width`/\n // `height: 100%`, merged BEFORE `...style` so a consumer can still override)\n // — without an explicit height the inner `height: 100%` (and SlideCanvas's\n // own `height: 100%`) would resolve against an auto-height box, so\n // `useViewportSize` reads `clientHeight ≈ 0`, `fitScale ≈ 0`, and the canvas\n // renders blank when `scale` is omitted. The inner wrapper below is\n // padding-free so that SlideCanvas (normal flow) and the overlay (`inset: 0`)\n // always measure the same box — otherwise consumer padding would diverge\n // their box models and misalign the overlay from the rendered elements.\n <div className={className} style={{ width: '100%', height: '100%', ...style }}>\n <div style={{ position: 'relative', width: '100%', height: '100%' }}>\n {/* Pass `props.scale` (possibly undefined) THROUGH so SlideCanvas\n auto-fits with the same `fitScale` the overlay reads above. */}\n <SlideCanvas\n slide={displaySlide}\n scale={props.scale}\n renderImage={renderImage}\n renderVideo={renderVideo}\n videoInteractive={videoInteractive}\n />\n\n {/* Interaction overlay: hit targets below, selection chrome above.\n Every child is offset by the same `viewportStyles.left/top` that\n SlideCanvas applies to its element container, so overlay coordinates\n line up with the rendered elements even when the container is\n letterboxed (aspect ratio != slide's). */}\n <div ref={overlayRef} style={{ position: 'absolute', inset: 0, pointerEvents: 'none' }}>\n {/* Blank-canvas marquee capture surface. Rendered FIRST so it sits\n beneath the per-element hit targets in stacking order: a pointer-\n down on an element hits that element's div (painted later, on top),\n while a pointer-down on empty canvas falls to this full-bleed layer\n and arms a rubber-band select. It is a sibling of the element hit\n divs (not an ancestor), so an element pointer-down never bubbles\n into it. Gated on SELECTION (`onSelectionChange`) so select-only\n mounts still get mouse/pen marquee and sub-threshold blank-clear.\n Touch suppression is gated separately on EDITABILITY\n (`onElementsChange`): select-only mounts preserve native touch\n panning, while touch-driven marquee requires an editable mount. */}\n {Boolean(onSelectionChange) && (\n <div\n data-marquee-surface=\"\"\n onPointerDown={onCanvasPointerDown}\n style={{\n position: 'absolute',\n inset: 0,\n pointerEvents: 'auto',\n touchAction: editingTouchAction,\n }}\n />\n )}\n {elements.map((el) => {\n // Line elements: a line's real hit area is its (often bent) stroke,\n // not its rectangular bounding box. A rectangular bbox blocker\n // would wrongly swallow clicks on other elements around a thin\n // diagonal line, and a straight start->end strip misses the\n // visible stroke of broken/broken2/curve/cubic lines (which bend\n // away from that chord) while blocking empty space where nothing\n // is drawn. Instead render an INERT SVG-path blocker that mirrors\n // the v1 line renderer pixel-for-pixel.\n //\n // v1 (src/elements/line/BaseLineElement.tsx:70-132) draws the line\n // at (el.left, el.top) inside SlideCanvas's `transform:\n // scale(canvasScale)` element container (SlideCanvas.tsx:153-163),\n // as an <svg overflow:visible> whose <path d={getLineElementPath}>\n // is in raw canvas units with stroke-width = el.width canvas units.\n // We reproduce that exactly: the wrapper sits at the same screen\n // origin as the other hit layers (viewportStyles.left/top +\n // coord*canvasScale) and the inner <svg> carries `transform:\n // scale(canvasScale)` (origin 0 0), so its raw-canvas-unit path maps\n // to the same on-screen pixels as the rendered line.\n //\n // `pointer-events: stroke` makes ONLY the fat transparent stroke a\n // hit target: it covers the visible line for EVERY path shape (P2)\n // and leaves the empty bbox click-through. The stroke width is the\n // grab band, at least the rendered stroke and at least a 10px\n // screen minimum (P3). It is INERT: `onPointerDown` only stops\n // propagation — no `data-element-id`, no gesture armed.\n // Known gap: endpoint markers (arrow/dot) can paint beyond the\n // stroke; their extents are NOT part of this hit target. Covering\n // them is deferred with line editing — the only fall-through case\n // is a marked line overlapping other content exactly at an\n // endpoint, on an element type that is not yet editable here.\n // A line is selected when its id is in the controlled selection.\n // Hit geometry and visual chrome are SPLIT into two paths (below):\n // a stable transparent blocker (the hit region, identical whether\n // or not the line is selected — so selecting a line never shrinks\n // its hit band) plus a separate, non-interactive highlight path\n // drawn only when selected. So a selected line has feedback in\n // EVERY state: read-only (no-callback), locked, or editable.\n // Handles (drawn much further below) are only added when the line\n // is EDITABLE (`onElementsChange`) and unlocked.\n const isSelected = activeSelection.elementIds.includes(el.id);\n if (el.type === 'line') {\n // Render the line's blocker/highlight path when it is either a\n // live hit target (interactive) OR selected (to draw the\n // highlight in a read-only mount). A read-only, unselected line\n // needs neither, so skip it.\n if (!interactive && !isSelected) return null;\n const path = getLineElementPath(el);\n // Match v1's svg box (min 24) so overflow:visible has a sensible\n // frame; the fat stroke can extend beyond it (not clipped).\n const spanW = Math.abs(el.start[0] - el.end[0]);\n const spanH = Math.abs(el.start[1] - el.end[1]);\n const svgWidth = spanW < 24 ? 24 : spanW;\n const svgHeight = spanH < 24 ? 24 : spanH;\n // Screen grab band, then converted to canvas units for the path\n // drawn inside the scale(canvasScale) svg (divide by scale so the\n // painted screen width is exactly `grabScreenPx`).\n const grabScreenPx = Math.max(10, el.width * canvasScale);\n const grabCanvas = canvasScale > 0 ? grabScreenPx / canvasScale : grabScreenPx;\n // Selection highlight stroke width, in the SAME canvas units the\n // blocker's stroke-width uses (the path is drawn inside a\n // `scale(canvasScale)` svg). At least the rendered stroke, and at\n // least 2 canvas units so a hairline line still shows a visible\n // highlight (~`max(2, el.width) * canvasScale` screen px).\n const highlightCanvas = Math.max(2, el.width);\n return (\n <div\n key={el.id}\n style={{\n position: 'absolute',\n left: `${viewportStyles.left + el.left * canvasScale}px`,\n top: `${viewportStyles.top + el.top * canvasScale}px`,\n width: 0,\n height: 0,\n pointerEvents: 'none',\n overflow: 'visible',\n }}\n >\n <svg\n overflow=\"visible\"\n width={svgWidth}\n height={svgHeight}\n style={{\n overflow: 'visible',\n transform: `scale(${canvasScale})`,\n transformOrigin: '0 0',\n pointerEvents: 'none',\n }}\n >\n {/* Blocker path — the interaction hit region. It is\n ALWAYS the same regardless of selection: a fat\n transparent stroke (`grabCanvas`) whose `pointer-events:\n stroke` band never changes when the line is selected.\n This guarantees a selected thin line never lets clicks\n fall through to a box beneath (selecting a line does NOT\n shrink its hit band). It is INERT: `onPointerDown` only\n stops propagation + selects-unless-locked; no drag is\n armed. pointer-events is disabled entirely in a\n read-only mount so a selected-but-read-only line never\n captures the pointer. The visual selection chrome is a\n SEPARATE, non-interactive highlight path below. */}\n <path\n data-hit-kind=\"line\"\n d={path}\n fill=\"none\"\n stroke=\"transparent\"\n strokeWidth={grabCanvas}\n pointerEvents={interactive ? 'stroke' : 'none'}\n onPointerDown={(e) => {\n // Deferred limitation: line selection is handled here\n // directly and bypasses `useEditGesture`, so it also\n // bypasses the `activePointerRef` multi-pointer guard.\n // A second pointer-down on a line during an in-flight\n // box drag can therefore change the selection mid-\n // gesture. More generally, the single-pointer guarantee\n // is PER-HOOK: each gesture hook (move/marquee/line-\n // handle/resize/rotate) guards only its own active\n // pointer, so a second pointer can still arm a\n // DIFFERENT hook's gesture concurrently. Cross-hook\n // arbitration is deferred together with multi-touch\n // support; single-pointer/mouse use (only one active\n // pointer at a time) is unaffected.\n //\n // Always consume the pointer to block fall-through to\n // an overlapped box beneath (even with no selection\n // callback, and even when the line is locked). When a\n // selection callback is provided, resolve the click\n // through the SAME modifier/selection table as box\n // elements ({@link resolveClickSelection}) so a\n // modifier click adds/removes a line from a multi-\n // selection too. A line is selectable but NOT draggable\n // here: `armDrag` is ignored, no working copy is armed,\n // and no move intent is ever emitted (line editing\n // deferred).\n e.stopPropagation();\n // A locked line is inert like a locked box: it blocks\n // fall-through (stopPropagation above) but must not be\n // selected.\n if (el.lock) return;\n const { next } = resolveClickSelection({\n element: el,\n elements: slide.elements,\n selection: activeSelection,\n modifier: isSelectionModifier(e),\n });\n // `next` is null when nothing changes (e.g. a re-click\n // on the current primary, or a subtractive click that\n // would empty the selection) — no redundant re-emit.\n if (next) onSelectionChange?.(next);\n }}\n style={{ cursor: 'default', touchAction: editingTouchAction }}\n />\n {/* Highlight path — selection chrome only, rendered when the\n line is selected. Purely visual (`pointer-events: none`),\n so it NEVER affects hit-testing — the blocker above owns\n the entire hit region. Same `d`/position/scale as the\n blocker; a thinner accent stroke (`highlightCanvas`).\n Layered above the blocker, below the handles. Feedback in\n read-only/locked/editable alike. */}\n {isSelected && (\n <path\n data-hit-kind=\"line-highlight\"\n d={path}\n fill=\"none\"\n stroke=\"#3b82f6\"\n strokeOpacity={0.7}\n strokeWidth={highlightCanvas}\n pointerEvents=\"none\"\n style={{ pointerEvents: 'none' }}\n />\n )}\n </svg>\n </div>\n );\n }\n // Non-line elements never render an overlay node in a read-only\n // mount (no hit targets, no chrome — their selection border comes\n // from SelectionOverlay). Only lines draw a read-only highlight.\n if (!interactive) return null;\n // Non-line elements are narrowed here, so `width`/`height`/`rotate`\n // are directly available (no casts).\n return el.lock ? (\n // Locked elements (`el.lock`): the app editor guards locked\n // content from being moved, and — critically — a locked\n // element is the top rendered DOM node in the real app, so\n // it swallows the click rather than falling through to\n // whatever unlocked element sits beneath it. Mirror that\n // here with an INERT blocker at the same stacking position\n // (same map order, so it's on top when it visually\n // overlaps an unlocked element below it in the array):\n // `pointerEvents: 'auto'` consumes the pointer, but\n // `onPointerDown` is a no-op (no `onElementPointerDown`\n // call, no `data-element-id`) so no gesture is ever armed\n // and nothing beneath moves or gets selected. (A locked\n // element's selection border, if selected, is unaffected —\n // SelectionOverlay is untouched.)\n <div\n key={el.id}\n data-hit-kind=\"blocker\"\n onPointerDown={(e) => {\n e.stopPropagation();\n }}\n style={{\n position: 'absolute',\n left: `${viewportStyles.left + el.left * canvasScale}px`,\n top: `${viewportStyles.top + el.top * canvasScale}px`,\n width: `${el.width * canvasScale}px`,\n height: `${el.height * canvasScale}px`,\n transform: `rotate(${el.rotate}deg)`,\n transformOrigin: 'center',\n pointerEvents: 'auto',\n cursor: 'default',\n touchAction: editingTouchAction,\n }}\n />\n ) : (\n <div\n key={el.id}\n data-element-id={el.id}\n onPointerDown={(e) => onElementPointerDown(el, e)}\n style={{\n position: 'absolute',\n left: `${viewportStyles.left + el.left * canvasScale}px`,\n top: `${viewportStyles.top + el.top * canvasScale}px`,\n width: `${el.width * canvasScale}px`,\n height: `${el.height * canvasScale}px`,\n transform: `rotate(${el.rotate}deg)`,\n transformOrigin: 'center',\n pointerEvents: 'auto',\n cursor: 'move',\n touchAction: editingTouchAction,\n }}\n />\n );\n })}\n\n {/* Line handles: a selected, unlocked line's endpoint/control handles\n are its selection chrome (SelectionOverlay no longer draws a line\n border). Rendered above the stroke blocker so a handle pointer-\n down hits the handle, not the blocker beneath. Each handle reads\n the WORKING line (via `displayElements`), so during a reshape drag\n the handles track the previewed geometry. Handles use absolute\n SCREEN coordinates (they bake in `viewportStyles`), so they sit as\n direct children of the overlay, NOT inside the offset container.\n\n Gated on EDITABILITY (`onElementsChange`), not generic\n `interactive`: the reshape gesture no-ops without a mutation\n channel, so a select-only mount (only `onSelectionChange`) would\n otherwise show draggable handles that can never commit. In that\n case show NO handles — only the stroke highlight (feedback). */}\n {Boolean(onElementsChange) &&\n elements.map((el) => {\n if (el.type !== 'line') return null;\n if (!activeSelection.elementIds.includes(el.id) || el.lock) return null;\n return (\n <LineHandles\n key={`line-handles-${el.id}`}\n element={el}\n viewportStyles={viewportStyles}\n canvasScale={canvasScale}\n onHandlePointerDown={(handle, e) => onHandlePointerDown(el, handle, e)}\n />\n );\n })}\n\n {/* Box operate handles: a selected, unlocked box element gets its\n 8-point resize handles and, where the kind supports it, a rotate\n handle above the top edge. Per-kind gates live in the cores:\n `getResizeHandles` (text → width axis only, by `vertical`; code →\n none) and `canRotate` (chart/video/audio excluded). Lines are\n excluded entirely — their chrome is `LineHandles` above. Handles\n read the WORKING element (`elements`), so they track the live\n preview during a resize/rotate. Like the line handles they use\n absolute SCREEN coordinates (baking in `viewportStyles`) and are\n gated on EDITABILITY (`onElementsChange`), not generic\n `interactive`: without a mutation channel the gestures no-op, so\n a select-only mount shows no draggable handles. Shown only for a\n SINGLE-element selection: these gestures transform one element,\n and per-element handles on a multi-selection would misread as\n group scaling (which is a later slice). */}\n {Boolean(onElementsChange) &&\n activeSelection.elementIds.length === 1 &&\n elements.map((el) => {\n if (el.type === 'line') return null;\n if (!activeSelection.elementIds.includes(el.id) || el.lock) return null;\n const handles = getResizeHandles(el);\n const rotatable = canRotate(el);\n if (handles.length === 0 && !rotatable) return null;\n return (\n <Fragment key={`operate-${el.id}`}>\n {handles.length > 0 && (\n <ResizeHandles\n element={el}\n handles={handles}\n viewportStyles={viewportStyles}\n canvasScale={canvasScale}\n onHandlePointerDown={(handle, e) => onResizeHandlePointerDown(el, handle, e)}\n />\n )}\n {rotatable && (\n <RotateHandle\n element={el}\n viewportStyles={viewportStyles}\n canvasScale={canvasScale}\n onPointerDown={(e) => onRotateHandlePointerDown(el, e)}\n />\n )}\n </Fragment>\n );\n })}\n\n {/* Live marquee rectangle, drawn while a blank-canvas rubber-band\n select is in flight. Purely visual (`pointerEvents: none`); it\n shares the element container's origin via `viewportStyles`. */}\n {marqueeRect && (\n <MarqueeBox\n rect={marqueeRect}\n viewportStyles={viewportStyles}\n canvasScale={canvasScale}\n />\n )}\n\n {/* SelectionOverlay is left untouched; wrap it in a positioning\n container matching SlideCanvas's element container so its\n per-element borders inherit the centering offset. */}\n <div\n style={{\n position: 'absolute',\n left: `${viewportStyles.left}px`,\n top: `${viewportStyles.top}px`,\n width: `${viewportStyles.width * canvasScale}px`,\n height: `${viewportStyles.height * canvasScale}px`,\n pointerEvents: 'none',\n }}\n >\n <SelectionOverlay elements={elements} selection={activeSelection} scale={canvasScale} />\n </div>\n </div>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACG;;AAcJ;;;;;;;;AASA;;;;AAIC;AACD;AAEA;;AAEE;AACA;;;;AAID;;;;;;AAOD;AACE;;AAED;;;;AAKD;;AAEE;;;AAGD;;;;AAKD;;;AAGE;;AAED;;;;;;;AAQD;;AAEE;;;AAGA;;AAED;;;;;;;AAQD;;AAEE;;;AAKA;;;AAKA;;AAIF;AAEI;;;;;;;;;;;;;;;;;;AAqDU;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CJ;AACA;;;;;AAKE;AAAiC;AACjC;;;;;AAKA;AACA;;;;AAIA;AACA;;;;;;AAMA;;AAKM;;;AAGA;AACA;AACA;AACA;AACD;AAOG;;AAEA;AACA;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDG;AACE;;AAEA;AACA;AACD;;;;AAID;AAAU;AACZ;;;;;AA6BV;AAAkB;;;AAGlB;;;;;;;;;;;;;;;AAeE;;;AAOI;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACD;AAQC;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACD;AAGP;AAiBE;AACE;AAAwB;AACxB;AAA4D;AAC5D;AASF;AAkBA;AACA;AACE;AAAwB;AACxB;AAA4D;AAC5D;AACA;AACA;AAAwC;AACxC;;AAuCA;AACA;AACA;AACA;AACA;AACA;;AASd;;"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { PPTElement } from '@openmaic/dsl';
|
|
2
|
-
import type { SnappingOptions } from '../types';
|
|
3
|
-
import { type Guide } from './snapping';
|
|
4
|
-
/**
|
|
5
|
-
* Single-element drag input for one gesture-commit tick: the element being
|
|
6
|
-
* dragged, its siblings (`others`, snap candidates), the viewport (canvas
|
|
7
|
-
* bounds for `toCanvas` snapping), the pointer delta already converted to
|
|
8
|
-
* canvas units, an optional single-axis lock, and the snapping config.
|
|
9
|
-
*/
|
|
10
|
-
export interface DragInput {
|
|
11
|
-
element: PPTElement;
|
|
12
|
-
others: PPTElement[];
|
|
13
|
-
viewport: {
|
|
14
|
-
width: number;
|
|
15
|
-
height: number;
|
|
16
|
-
};
|
|
17
|
-
deltaCanvas: {
|
|
18
|
-
x: number;
|
|
19
|
-
y: number;
|
|
20
|
-
};
|
|
21
|
-
axisLock?: 'x' | 'y';
|
|
22
|
-
snapping?: boolean | SnappingOptions;
|
|
23
|
-
}
|
|
24
|
-
/** The dragged element's new position plus the guides to render, if any. */
|
|
25
|
-
export interface DragResult {
|
|
26
|
-
props: {
|
|
27
|
-
left: number;
|
|
28
|
-
top: number;
|
|
29
|
-
};
|
|
30
|
-
guides: Guide[];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Resolve the `snapping` prop into concrete `buildAlignLines` options plus the
|
|
34
|
-
* snap `range`: `true` enables both element- and canvas-snapping at the
|
|
35
|
-
* default range; `false`/absent disables snapping entirely (`null`); an
|
|
36
|
-
* explicit `SnappingOptions` object is used as-is, with `range` defaulted.
|
|
37
|
-
* Shared by the drag and resize cores so both gestures interpret the
|
|
38
|
-
* `snapping` prop identically.
|
|
39
|
-
*/
|
|
40
|
-
export declare function resolveSnapping(snapping: boolean | SnappingOptions | undefined): {
|
|
41
|
-
opts: SnappingOptions;
|
|
42
|
-
range: number;
|
|
43
|
-
} | null;
|
|
44
|
-
/**
|
|
45
|
-
* Apply a drag delta to a single element (respecting an optional axis lock),
|
|
46
|
-
* then snap the moved position against `others`/the canvas per `snapping`.
|
|
47
|
-
* Composition: shift the element's `left/top` by `deltaCanvas` → derive the
|
|
48
|
-
* shifted element's `ElementRange` via `getElementRange` → build candidate
|
|
49
|
-
* align lines via `buildAlignLines` → correct the shift via `snapRange`
|
|
50
|
-
* (`dx`/`dy`) → return the corrected `left/top` plus the guides to render.
|
|
51
|
-
* No React, no store, no `@/` imports.
|
|
52
|
-
*/
|
|
53
|
-
export declare function computeDragMove(input: DragInput): DragResult;
|
|
54
|
-
/**
|
|
55
|
-
* Multi-element drag input for one gesture-commit tick: the pointer's grab
|
|
56
|
-
* element (`handleElement`, always a member of `selected`), the whole selected
|
|
57
|
-
* set to translate rigidly (`selected`, INCLUDING the handle), the snap
|
|
58
|
-
* candidates (`others` — the caller has already excluded every selected
|
|
59
|
-
* element), the viewport, the pointer delta already converted to canvas units,
|
|
60
|
-
* an optional single-axis lock, and the snapping config.
|
|
61
|
-
*/
|
|
62
|
-
export interface MultiDragInput {
|
|
63
|
-
handleElement: PPTElement;
|
|
64
|
-
selected: PPTElement[];
|
|
65
|
-
others: PPTElement[];
|
|
66
|
-
viewport: {
|
|
67
|
-
width: number;
|
|
68
|
-
height: number;
|
|
69
|
-
};
|
|
70
|
-
deltaCanvas: {
|
|
71
|
-
x: number;
|
|
72
|
-
y: number;
|
|
73
|
-
};
|
|
74
|
-
axisLock?: 'x' | 'y';
|
|
75
|
-
snapping?: boolean | SnappingOptions;
|
|
76
|
-
}
|
|
77
|
-
/** Every selected element's new position plus the guides to render, if any. */
|
|
78
|
-
export interface MultiDragResult {
|
|
79
|
-
updates: Array<{
|
|
80
|
-
id: string;
|
|
81
|
-
props: {
|
|
82
|
-
left: number;
|
|
83
|
-
top: number;
|
|
84
|
-
};
|
|
85
|
-
}>;
|
|
86
|
-
guides: Guide[];
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Apply a drag delta to a MULTI-element selection as one rigid translation.
|
|
90
|
-
* Composition mirrors {@link computeDragMove} but snaps the whole set together:
|
|
91
|
-
* shift every selected element by `deltaCanvas` → take the editing UNION
|
|
92
|
-
* bounding box of the shifted set (`getEditingElementListRange`) → snap that union against
|
|
93
|
-
* `others`/the canvas → apply the SAME corrected delta to every selected
|
|
94
|
-
* element's origin. The snap is computed once on the union (not per element), so
|
|
95
|
-
* the set never deforms — spacing between selected elements is preserved.
|
|
96
|
-
*
|
|
97
|
-
* `handleElement` is declared for the caller's clarity (it identifies the
|
|
98
|
-
* pointer's grab element within `selected`); the correction is identical for
|
|
99
|
-
* every member, so it is applied uniformly rather than relative to the handle.
|
|
100
|
-
* Lines carried inside the selection are translated too (they own `left`/`top`),
|
|
101
|
-
* unlike the single-element {@link computeDragMove} which leaves a lone line put.
|
|
102
|
-
*
|
|
103
|
-
* With a single selected element this reduces EXACTLY to {@link computeDragMove}'s
|
|
104
|
-
* position math (same union == that element's range, same snap correction), so
|
|
105
|
-
* the hook can route N == 1 through either and get identical results.
|
|
106
|
-
* No React, no store, no `@/` imports.
|
|
107
|
-
*/
|
|
108
|
-
export declare function computeMultiDragMove(input: MultiDragInput): MultiDragResult;
|