@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,52 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { getRotateElementPoints } from '../core/resize.js';
|
|
3
|
+
|
|
4
|
+
/** Half the handle box size, so `translate(-HALF, -HALF)` centers it on its point. */
|
|
5
|
+
const HANDLE_HALF = 5;
|
|
6
|
+
/**
|
|
7
|
+
* Screen-pixel gap between the element's rotated top edge and the rotate
|
|
8
|
+
* handle, along the element's rotated "up" direction (app parity: the app
|
|
9
|
+
* offsets the handle 25 un-scaled px above the frame inside its rotated
|
|
10
|
+
* operate layer, so the gap is constant on screen at any zoom).
|
|
11
|
+
*/
|
|
12
|
+
const ROTATE_HANDLE_OFFSET_PX = 25;
|
|
13
|
+
/**
|
|
14
|
+
* Presentational rotate handle for a selected box element: a small grab-cursor
|
|
15
|
+
* box floating above the element's rotated top-center point.
|
|
16
|
+
*
|
|
17
|
+
* Position is computed ANALYTICALLY (like `ResizeHandles`): the rotated
|
|
18
|
+
* top-center point comes from {@link getRotateElementPoints}, then the handle
|
|
19
|
+
* is pushed {@link ROTATE_HANDLE_OFFSET_PX} screen px further along the rotated
|
|
20
|
+
* up vector `(sin θ, -cos θ)` — the un-rotated `(0, -1)` turned by the
|
|
21
|
+
* element's angle — so the handle orbits the element as it rotates. The box
|
|
22
|
+
* carries `data-rotate-handle` and arms the rotate gesture via
|
|
23
|
+
* `onPointerDown`. No `@/` imports.
|
|
24
|
+
*/
|
|
25
|
+
function RotateHandle({ element, viewportStyles, canvasScale, onPointerDown, }) {
|
|
26
|
+
const rotate = element.rotate || 0;
|
|
27
|
+
const rotateRadian = (Math.PI * rotate) / 180;
|
|
28
|
+
const topPoint = getRotateElementPoints({ left: element.left, top: element.top, width: element.width, height: element.height }, rotate).top;
|
|
29
|
+
const left = viewportStyles.left +
|
|
30
|
+
topPoint.left * canvasScale +
|
|
31
|
+
ROTATE_HANDLE_OFFSET_PX * Math.sin(rotateRadian);
|
|
32
|
+
const top = viewportStyles.top +
|
|
33
|
+
topPoint.top * canvasScale -
|
|
34
|
+
ROTATE_HANDLE_OFFSET_PX * Math.cos(rotateRadian);
|
|
35
|
+
return (jsx("div", { "data-rotate-handle": "", onPointerDown: onPointerDown, style: {
|
|
36
|
+
position: 'absolute',
|
|
37
|
+
left: `${left}px`,
|
|
38
|
+
top: `${top}px`,
|
|
39
|
+
width: '10px',
|
|
40
|
+
height: '10px',
|
|
41
|
+
transform: `translate(-${HANDLE_HALF}px, -${HANDLE_HALF}px)`,
|
|
42
|
+
border: '1px solid #3b82f6',
|
|
43
|
+
backgroundColor: '#fff',
|
|
44
|
+
boxSizing: 'border-box',
|
|
45
|
+
pointerEvents: 'auto',
|
|
46
|
+
cursor: 'grab',
|
|
47
|
+
touchAction: 'none',
|
|
48
|
+
} }));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { RotateHandle };
|
|
52
|
+
//# sourceMappingURL=RotateHandle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RotateHandle.js","sources":["../../../src/editing/handles/RotateHandle.tsx"],"sourcesContent":["import type { PointerEvent as ReactPointerEvent } from 'react';\n\nimport type { ViewportStyles } from '../../hooks/useViewportSize';\nimport { getRotateElementPoints, type PPTBoxElement } from '../core/resize';\n\nexport interface RotateHandleProps {\n /** The box element whose rotate handle is drawn. */\n element: PPTBoxElement;\n /** SlideCanvas centering offset — the handle shares the element container's origin. */\n viewportStyles: ViewportStyles;\n /** Canvas → screen scale (`props.scale ?? fitScale`). */\n canvasScale: number;\n /** Arm a rotate gesture from a pointer-down on the handle box. */\n onPointerDown: (e: ReactPointerEvent) => void;\n}\n\n/** Half the handle box size, so `translate(-HALF, -HALF)` centers it on its point. */\nconst HANDLE_HALF = 5;\n\n/**\n * Screen-pixel gap between the element's rotated top edge and the rotate\n * handle, along the element's rotated \"up\" direction (app parity: the app\n * offsets the handle 25 un-scaled px above the frame inside its rotated\n * operate layer, so the gap is constant on screen at any zoom).\n */\nconst ROTATE_HANDLE_OFFSET_PX = 25;\n\n/**\n * Presentational rotate handle for a selected box element: a small grab-cursor\n * box floating above the element's rotated top-center point.\n *\n * Position is computed ANALYTICALLY (like `ResizeHandles`): the rotated\n * top-center point comes from {@link getRotateElementPoints}, then the handle\n * is pushed {@link ROTATE_HANDLE_OFFSET_PX} screen px further along the rotated\n * up vector `(sin θ, -cos θ)` — the un-rotated `(0, -1)` turned by the\n * element's angle — so the handle orbits the element as it rotates. The box\n * carries `data-rotate-handle` and arms the rotate gesture via\n * `onPointerDown`. No `@/` imports.\n */\nexport function RotateHandle({\n element,\n viewportStyles,\n canvasScale,\n onPointerDown,\n}: RotateHandleProps) {\n const rotate = element.rotate || 0;\n const rotateRadian = (Math.PI * rotate) / 180;\n\n const topPoint = getRotateElementPoints(\n { left: element.left, top: element.top, width: element.width, height: element.height },\n rotate,\n ).top;\n\n const left =\n viewportStyles.left +\n topPoint.left * canvasScale +\n ROTATE_HANDLE_OFFSET_PX * Math.sin(rotateRadian);\n const top =\n viewportStyles.top +\n topPoint.top * canvasScale -\n ROTATE_HANDLE_OFFSET_PX * Math.cos(rotateRadian);\n\n return (\n <div\n data-rotate-handle=\"\"\n onPointerDown={onPointerDown}\n style={{\n position: 'absolute',\n left: `${left}px`,\n top: `${top}px`,\n width: '10px',\n height: '10px',\n transform: `translate(-${HANDLE_HALF}px, -${HANDLE_HALF}px)`,\n border: '1px solid #3b82f6',\n backgroundColor: '#fff',\n boxSizing: 'border-box',\n pointerEvents: 'auto',\n cursor: 'grab',\n touchAction: 'none',\n }}\n />\n );\n}\n"],"names":["_jsx"],"mappings":";;;AAgBA;AACA,MAAM,WAAW,GAAG,CAAC;AAErB;;;;;AAKG;AACH,MAAM,uBAAuB,GAAG,EAAE;AAElC;;;;;;;;;;;AAWG;AACG,SAAU,YAAY,CAAC,EAC3B,OAAO,EACP,cAAc,EACd,WAAW,EACX,aAAa,GACK,EAAA;AAClB,IAAA,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC;IAClC,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,IAAI,GAAG;AAE7C,IAAA,MAAM,QAAQ,GAAG,sBAAsB,CACrC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,EACtF,MAAM,CACP,CAAC,GAAG;AAEL,IAAA,MAAM,IAAI,GACR,cAAc,CAAC,IAAI;QACnB,QAAQ,CAAC,IAAI,GAAG,WAAW;AAC3B,QAAA,uBAAuB,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC;AAClD,IAAA,MAAM,GAAG,GACP,cAAc,CAAC,GAAG;QAClB,QAAQ,CAAC,GAAG,GAAG,WAAW;AAC1B,QAAA,uBAAuB,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC;IAElD,QACEA,mCACqB,EAAE,EACrB,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE;AACL,YAAA,QAAQ,EAAE,UAAU;YACpB,IAAI,EAAE,CAAA,EAAG,IAAI,CAAA,EAAA,CAAI;YACjB,GAAG,EAAE,CAAA,EAAG,GAAG,CAAA,EAAA,CAAI;AACf,YAAA,KAAK,EAAE,MAAM;AACb,YAAA,MAAM,EAAE,MAAM;AACd,YAAA,SAAS,EAAE,CAAA,WAAA,EAAc,WAAW,CAAA,KAAA,EAAQ,WAAW,CAAA,GAAA,CAAK;AAC5D,YAAA,MAAM,EAAE,mBAAmB;AAC3B,YAAA,eAAe,EAAE,MAAM;AACvB,YAAA,SAAS,EAAE,YAAY;AACvB,YAAA,aAAa,EAAE,MAAM;AACrB,YAAA,MAAM,EAAE,MAAM;AACd,YAAA,WAAW,EAAE,MAAM;AACpB,SAAA,EAAA,CACD;AAEN;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PPTElement } from '@openmaic/dsl';
|
|
2
|
+
import type { Selection } from '../types';
|
|
3
|
+
export interface SelectionOverlayProps {
|
|
4
|
+
elements: PPTElement[];
|
|
5
|
+
selection: Selection;
|
|
6
|
+
scale: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Presentational selection overlay. Props-driven only: resolves
|
|
10
|
+
* `selection.elementIds` against `elements` and renders a scaled,
|
|
11
|
+
* rotated `BorderLine` for each match. Renders `null` when the selection
|
|
12
|
+
* resolves to no elements (nothing selected, or ids not found).
|
|
13
|
+
*
|
|
14
|
+
* Line elements are intentionally skipped here: a selected line's chrome is its
|
|
15
|
+
* draggable endpoint/control handles (see `LineHandles`), which replace the
|
|
16
|
+
* approximate bbox border a line would otherwise get.
|
|
17
|
+
*/
|
|
18
|
+
export declare function SelectionOverlay({ elements, selection, scale }: SelectionOverlayProps): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { BorderLine } from './BorderLine.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Presentational selection overlay. Props-driven only: resolves
|
|
6
|
+
* `selection.elementIds` against `elements` and renders a scaled,
|
|
7
|
+
* rotated `BorderLine` for each match. Renders `null` when the selection
|
|
8
|
+
* resolves to no elements (nothing selected, or ids not found).
|
|
9
|
+
*
|
|
10
|
+
* Line elements are intentionally skipped here: a selected line's chrome is its
|
|
11
|
+
* draggable endpoint/control handles (see `LineHandles`), which replace the
|
|
12
|
+
* approximate bbox border a line would otherwise get.
|
|
13
|
+
*/
|
|
14
|
+
function SelectionOverlay({ elements, selection, scale }) {
|
|
15
|
+
const selected = selection.elementIds
|
|
16
|
+
.map((id) => elements.find((el) => el.id === id))
|
|
17
|
+
.filter((el) => el != null)
|
|
18
|
+
.filter((el) => el.type !== 'line');
|
|
19
|
+
if (selected.length === 0)
|
|
20
|
+
return null;
|
|
21
|
+
return (jsx(Fragment, { children: selected.map((el) => {
|
|
22
|
+
// Only non-line elements reach here (lines filtered out above), so
|
|
23
|
+
// `width`/`height`/`rotate` are directly available (no casts).
|
|
24
|
+
return (jsx(BorderLine, { width: el.width * scale, height: el.height * scale, style: {
|
|
25
|
+
left: `${el.left * scale}px`,
|
|
26
|
+
top: `${el.top * scale}px`,
|
|
27
|
+
transform: `rotate(${el.rotate}deg)`,
|
|
28
|
+
transformOrigin: 'center',
|
|
29
|
+
pointerEvents: 'none',
|
|
30
|
+
} }, el.id));
|
|
31
|
+
}) }));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { SelectionOverlay };
|
|
35
|
+
//# sourceMappingURL=SelectionOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionOverlay.js","sources":["../../../src/editing/handles/SelectionOverlay.tsx"],"sourcesContent":["import type { PPTElement, PPTLineElement } from '@openmaic/dsl';\nimport type { Selection } from '../types';\nimport { BorderLine } from './BorderLine';\n\n/** A selectable element that carries a box model (`width`/`height`/`rotate`). */\ntype PPTBoxElement = Exclude<PPTElement, PPTLineElement>;\n\nexport interface SelectionOverlayProps {\n elements: PPTElement[];\n selection: Selection;\n scale: number;\n}\n\n/**\n * Presentational selection overlay. Props-driven only: resolves\n * `selection.elementIds` against `elements` and renders a scaled,\n * rotated `BorderLine` for each match. Renders `null` when the selection\n * resolves to no elements (nothing selected, or ids not found).\n *\n * Line elements are intentionally skipped here: a selected line's chrome is its\n * draggable endpoint/control handles (see `LineHandles`), which replace the\n * approximate bbox border a line would otherwise get.\n */\nexport function SelectionOverlay({ elements, selection, scale }: SelectionOverlayProps) {\n const selected = selection.elementIds\n .map((id) => elements.find((el) => el.id === id))\n .filter((el): el is PPTElement => el != null)\n .filter((el): el is PPTBoxElement => el.type !== 'line');\n\n if (selected.length === 0) return null;\n\n return (\n <>\n {selected.map((el) => {\n // Only non-line elements reach here (lines filtered out above), so\n // `width`/`height`/`rotate` are directly available (no casts).\n return (\n <BorderLine\n key={el.id}\n width={el.width * scale}\n height={el.height * scale}\n style={{\n left: `${el.left * scale}px`,\n top: `${el.top * scale}px`,\n transform: `rotate(${el.rotate}deg)`,\n transformOrigin: 'center',\n pointerEvents: 'none',\n }}\n />\n );\n })}\n </>\n );\n}\n"],"names":["_jsx"],"mappings":";;;AAaA;;;;;;;;;AASG;AACG,SAAU,gBAAgB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAyB,EAAA;AACpF,IAAA,MAAM,QAAQ,GAAG,SAAS,CAAC;SACxB,GAAG,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;SAC/C,MAAM,CAAC,CAAC,EAAE,KAAuB,EAAE,IAAI,IAAI;AAC3C,SAAA,MAAM,CAAC,CAAC,EAAE,KAA0B,EAAE,CAAC,IAAI,KAAK,MAAM,CAAC;AAE1D,IAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;AAAE,QAAA,OAAO,IAAI;IAEtC,QACEA,0BACG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,KAAI;;;YAGnB,QACEA,IAAC,UAAU,EAAA,EAET,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,EACvB,MAAM,EAAE,EAAE,CAAC,MAAM,GAAG,KAAK,EACzB,KAAK,EAAE;AACL,oBAAA,IAAI,EAAE,CAAA,EAAG,EAAE,CAAC,IAAI,GAAG,KAAK,CAAA,EAAA,CAAI;AAC5B,oBAAA,GAAG,EAAE,CAAA,EAAG,EAAE,CAAC,GAAG,GAAG,KAAK,CAAA,EAAA,CAAI;AAC1B,oBAAA,SAAS,EAAE,CAAA,OAAA,EAAU,EAAE,CAAC,MAAM,CAAA,IAAA,CAAM;AACpC,oBAAA,eAAe,EAAE,QAAQ;AACzB,oBAAA,aAAa,EAAE,MAAM;AACtB,iBAAA,EAAA,EATI,EAAE,CAAC,EAAE,CAUV;QAEN,CAAC,CAAC,EAAA,CACD;AAEP;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import type { Slide, PPTElement, PPTImageElement, PPTVideoElement } from '@openmaic/dsl';
|
|
3
|
+
/**
|
|
4
|
+
* Editing surface types (renderer v2). These are the **L1** contract from the
|
|
5
|
+
* editing-surface RFC: the bounded, UI-driven vocabulary the canvas emits for
|
|
6
|
+
* human gestures. They are intentionally *not* the agent tool surface (L2, which
|
|
7
|
+
* is expected to churn and lives outside this package) nor the canonical change
|
|
8
|
+
* representation (L0, which belongs in @openmaic/dsl). L1 normalizes down to L0.
|
|
9
|
+
*/
|
|
10
|
+
export type ReorderCommand = 'front' | 'back' | 'forward' | 'backward';
|
|
11
|
+
export type AlignCommand = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom';
|
|
12
|
+
/**
|
|
13
|
+
* The draggable handles on a line element. `start`/`end` are the two endpoints;
|
|
14
|
+
* `ctrl` is the single quadratic/broken control point (`broken`/`broken2`/`curve`);
|
|
15
|
+
* `ctrl1`/`ctrl2` are the two cubic control points (`cubic`).
|
|
16
|
+
*/
|
|
17
|
+
export type LineHandle = 'start' | 'end' | 'ctrl' | 'ctrl1' | 'ctrl2';
|
|
18
|
+
/**
|
|
19
|
+
* A single canvas edit intent. The canvas emits these on gesture commit; the host
|
|
20
|
+
* owns the document and undo and applies them. One intent (or batch) per completed
|
|
21
|
+
* gesture — never per animation frame — so it maps 1:1 onto one host undo entry.
|
|
22
|
+
*/
|
|
23
|
+
export type EditIntent = {
|
|
24
|
+
type: 'element.update';
|
|
25
|
+
id: string;
|
|
26
|
+
props: Partial<PPTElement>;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'element.updateMany';
|
|
29
|
+
updates: Array<{
|
|
30
|
+
id: string;
|
|
31
|
+
props: Partial<PPTElement>;
|
|
32
|
+
}>;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'element.add';
|
|
35
|
+
element: PPTElement;
|
|
36
|
+
index?: number;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'element.delete';
|
|
39
|
+
ids: string[];
|
|
40
|
+
} | {
|
|
41
|
+
type: 'element.reorder';
|
|
42
|
+
id: string;
|
|
43
|
+
command: ReorderCommand;
|
|
44
|
+
} | {
|
|
45
|
+
type: 'element.align';
|
|
46
|
+
ids: string[];
|
|
47
|
+
command: AlignCommand;
|
|
48
|
+
} | {
|
|
49
|
+
type: 'element.removeProps';
|
|
50
|
+
id: string;
|
|
51
|
+
props: string[];
|
|
52
|
+
} | {
|
|
53
|
+
type: 'text.updateContent';
|
|
54
|
+
id: string;
|
|
55
|
+
content: string;
|
|
56
|
+
target: 'text' | 'shape';
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Controlled selection. The host owns it; the canvas reports changes via
|
|
60
|
+
* onSelectionChange. Id-based (not position-based) so it survives document edits.
|
|
61
|
+
*/
|
|
62
|
+
export interface Selection {
|
|
63
|
+
/** readonly: the host owns selection and treats it immutably */
|
|
64
|
+
elementIds: readonly string[];
|
|
65
|
+
primaryId?: string;
|
|
66
|
+
groupId?: string;
|
|
67
|
+
editingId?: string;
|
|
68
|
+
}
|
|
69
|
+
/** Immutable empty-selection sentinel. Frozen so a shared reference can't be mutated. */
|
|
70
|
+
export declare const EMPTY_SELECTION: Selection;
|
|
71
|
+
export interface SnappingOptions {
|
|
72
|
+
toElements?: boolean;
|
|
73
|
+
toCanvas?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Snap threshold in canvas units (viewportSize space), not screen px — it is
|
|
76
|
+
* compared against un-scaled element bounds for app parity.
|
|
77
|
+
*/
|
|
78
|
+
range?: number;
|
|
79
|
+
}
|
|
80
|
+
export interface EditableSlideCanvasProps {
|
|
81
|
+
/** Controlled document — the host owns it (and undo). */
|
|
82
|
+
slide: Slide;
|
|
83
|
+
scale?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Controlled selection. Optional in this scaffold: the Stage 0 shell renders
|
|
86
|
+
* read-only and supports click-to-select only. It becomes the primary
|
|
87
|
+
* interaction contract once Part A lands operate handles.
|
|
88
|
+
*/
|
|
89
|
+
selection?: Selection;
|
|
90
|
+
onSelectionChange?: (next: Selection) => void;
|
|
91
|
+
/**
|
|
92
|
+
* The document-mutation channel. The canvas emits L1 intents here; the host
|
|
93
|
+
* applies them and owns undo. Not yet emitted by the Stage 0 shell — wired up
|
|
94
|
+
* as Part A moves the gesture machinery into the package.
|
|
95
|
+
*/
|
|
96
|
+
onElementsChange?: (intents: EditIntent[]) => void;
|
|
97
|
+
/** Host-injected media render slots (v1 behaviour preserved). */
|
|
98
|
+
renderImage?: (element: PPTImageElement, resolvedSrc: string, defaultContent: ReactNode) => ReactNode;
|
|
99
|
+
renderVideo?: (element: PPTVideoElement) => ReactNode;
|
|
100
|
+
videoInteractive?: boolean;
|
|
101
|
+
/** Editor affordances (no-ops until Part A). */
|
|
102
|
+
snapping?: boolean | SnappingOptions;
|
|
103
|
+
grid?: 0 | 25 | 50 | 100;
|
|
104
|
+
ruler?: boolean;
|
|
105
|
+
className?: string;
|
|
106
|
+
style?: CSSProperties;
|
|
107
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../src/editing/types.ts"],"sourcesContent":["import type { CSSProperties, ReactNode } from 'react';\nimport type { Slide, PPTElement, PPTImageElement, PPTVideoElement } from '@openmaic/dsl';\n\n/**\n * Editing surface types (renderer v2). These are the **L1** contract from the\n * editing-surface RFC: the bounded, UI-driven vocabulary the canvas emits for\n * human gestures. They are intentionally *not* the agent tool surface (L2, which\n * is expected to churn and lives outside this package) nor the canonical change\n * representation (L0, which belongs in @openmaic/dsl). L1 normalizes down to L0.\n */\n\nexport type ReorderCommand = 'front' | 'back' | 'forward' | 'backward';\nexport type AlignCommand = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom';\n\n/**\n * The draggable handles on a line element. `start`/`end` are the two endpoints;\n * `ctrl` is the single quadratic/broken control point (`broken`/`broken2`/`curve`);\n * `ctrl1`/`ctrl2` are the two cubic control points (`cubic`).\n */\nexport type LineHandle = 'start' | 'end' | 'ctrl' | 'ctrl1' | 'ctrl2';\n\n/**\n * A single canvas edit intent. The canvas emits these on gesture commit; the host\n * owns the document and undo and applies them. One intent (or batch) per completed\n * gesture — never per animation frame — so it maps 1:1 onto one host undo entry.\n */\nexport type EditIntent =\n | { type: 'element.update'; id: string; props: Partial<PPTElement> }\n | { type: 'element.updateMany'; updates: Array<{ id: string; props: Partial<PPTElement> }> }\n | { type: 'element.add'; element: PPTElement; index?: number }\n | { type: 'element.delete'; ids: string[] }\n | { type: 'element.reorder'; id: string; command: ReorderCommand }\n | { type: 'element.align'; ids: string[]; command: AlignCommand }\n | { type: 'element.removeProps'; id: string; props: string[] }\n | { type: 'text.updateContent'; id: string; content: string; target: 'text' | 'shape' };\n\n/**\n * Controlled selection. The host owns it; the canvas reports changes via\n * onSelectionChange. Id-based (not position-based) so it survives document edits.\n */\nexport interface Selection {\n /** readonly: the host owns selection and treats it immutably */\n elementIds: readonly string[];\n primaryId?: string;\n groupId?: string;\n editingId?: string;\n}\n\n/** Immutable empty-selection sentinel. Frozen so a shared reference can't be mutated. */\nexport const EMPTY_SELECTION: Selection = Object.freeze({\n elementIds: Object.freeze([] as string[]),\n});\n\nexport interface SnappingOptions {\n toElements?: boolean;\n toCanvas?: boolean;\n /**\n * Snap threshold in canvas units (viewportSize space), not screen px — it is\n * compared against un-scaled element bounds for app parity.\n */\n range?: number;\n}\n\nexport interface EditableSlideCanvasProps {\n /** Controlled document — the host owns it (and undo). */\n slide: Slide;\n scale?: number;\n\n /**\n * Controlled selection. Optional in this scaffold: the Stage 0 shell renders\n * read-only and supports click-to-select only. It becomes the primary\n * interaction contract once Part A lands operate handles.\n */\n selection?: Selection;\n onSelectionChange?: (next: Selection) => void;\n\n /**\n * The document-mutation channel. The canvas emits L1 intents here; the host\n * applies them and owns undo. Not yet emitted by the Stage 0 shell — wired up\n * as Part A moves the gesture machinery into the package.\n */\n onElementsChange?: (intents: EditIntent[]) => void;\n\n /** Host-injected media render slots (v1 behaviour preserved). */\n renderImage?: (\n element: PPTImageElement,\n resolvedSrc: string,\n defaultContent: ReactNode,\n ) => ReactNode;\n renderVideo?: (element: PPTVideoElement) => ReactNode;\n videoInteractive?: boolean;\n\n /** Editor affordances (no-ops until Part A). */\n snapping?: boolean | SnappingOptions;\n grid?: 0 | 25 | 50 | 100;\n ruler?: boolean;\n\n className?: string;\n style?: CSSProperties;\n}\n"],"names":[],"mappings":"AAgDA;AACO,MAAM,eAAe,GAAc,MAAM,CAAC,MAAM,CAAC;AACtD,IAAA,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAc,CAAC;AAC1C,CAAA;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type PointerEvent as ReactPointerEvent } from 'react';
|
|
2
|
+
import type { PPTElement, Slide } from '@openmaic/dsl';
|
|
3
|
+
import type { Guide } from './core/snapping';
|
|
4
|
+
import type { EditIntent, Selection, SnappingOptions } from './types';
|
|
5
|
+
export interface UseEditGestureArgs {
|
|
6
|
+
slide: Slide;
|
|
7
|
+
scale: number;
|
|
8
|
+
selection: Selection;
|
|
9
|
+
snapping?: boolean | SnappingOptions;
|
|
10
|
+
onSelectionChange?: (next: Selection) => void;
|
|
11
|
+
onElementsChange?: (intents: EditIntent[]) => void;
|
|
12
|
+
}
|
|
13
|
+
export interface UseEditGestureResult {
|
|
14
|
+
/** The slide to render: the in-gesture working copy while dragging, else `slide`. */
|
|
15
|
+
workingSlide: Slide;
|
|
16
|
+
/** Alignment guides for the active drag (computed; drawn by a later PR). */
|
|
17
|
+
guides: Guide[];
|
|
18
|
+
/** Arm a move/click gesture for `el` from a pointer-down on its hit target. */
|
|
19
|
+
onElementPointerDown: (el: PPTElement, e: ReactPointerEvent) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Owns one drag/click gesture. Pointer-down resolves the selection per the
|
|
23
|
+
* modifier table in {@link resolveClickSelection} (group-cohesive: a click on a
|
|
24
|
+
* grouped element applies to its whole group), then — for the cases that start
|
|
25
|
+
* a move — arms a drag and records the pointer start + the base slide; window
|
|
26
|
+
* pointer-move (converted screen→canvas via `scale`) republishes a working copy
|
|
27
|
+
* for live feedback; pointer-up commits the move as ONE intent when the pointer
|
|
28
|
+
* moved past `DRAG_THRESHOLD_PX`, otherwise reports a selection click. Emits one
|
|
29
|
+
* intent per completed gesture — never per frame — and clears the working copy
|
|
30
|
+
* so the host's controlled `slide` takes over again.
|
|
31
|
+
*
|
|
32
|
+
* Locked elements in a multi-selection are never translated: they may stay in
|
|
33
|
+
* the controlled selection for feedback, but the drag set excludes them and they
|
|
34
|
+
* remain snap candidates. Holding Shift while the drag is in flight locks the
|
|
35
|
+
* translation to the dominant axis (Shift at pointer-down is a selection
|
|
36
|
+
* modifier and never arms a drag).
|
|
37
|
+
*
|
|
38
|
+
* A single-element move commits `element.update` (backward compat with hosts);
|
|
39
|
+
* a multi-element move commits ONE `element.updateMany` = one host undo entry.
|
|
40
|
+
*
|
|
41
|
+
* `onElementPointerDown` closes over the current render's props, so each gesture
|
|
42
|
+
* captures a consistent snapshot of the controlled slide at pointer-down.
|
|
43
|
+
*
|
|
44
|
+
* Pure gesture glue: no store, no `@/` imports.
|
|
45
|
+
*/
|
|
46
|
+
export declare function useEditGesture(args: UseEditGestureArgs): UseEditGestureResult;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useRef, useEffect } from 'react';
|
|
3
|
+
import { computeMultiDragMove, computeDragMove } from './core/drag.js';
|
|
4
|
+
import { moveManyIntent, moveIntent } from './core/intent.js';
|
|
5
|
+
import { resolveClickSelection, isSelectionModifier } from './core/selection.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Distance (in screen pixels) the pointer must travel between pointer-down and
|
|
9
|
+
* pointer-up before a gesture counts as a drag rather than a click. Below this,
|
|
10
|
+
* the gesture is treated as a selection click and emits no `element.update`.
|
|
11
|
+
*/
|
|
12
|
+
const DRAG_THRESHOLD_PX = 2;
|
|
13
|
+
/**
|
|
14
|
+
* Owns one drag/click gesture. Pointer-down resolves the selection per the
|
|
15
|
+
* modifier table in {@link resolveClickSelection} (group-cohesive: a click on a
|
|
16
|
+
* grouped element applies to its whole group), then — for the cases that start
|
|
17
|
+
* a move — arms a drag and records the pointer start + the base slide; window
|
|
18
|
+
* pointer-move (converted screen→canvas via `scale`) republishes a working copy
|
|
19
|
+
* for live feedback; pointer-up commits the move as ONE intent when the pointer
|
|
20
|
+
* moved past `DRAG_THRESHOLD_PX`, otherwise reports a selection click. Emits one
|
|
21
|
+
* intent per completed gesture — never per frame — and clears the working copy
|
|
22
|
+
* so the host's controlled `slide` takes over again.
|
|
23
|
+
*
|
|
24
|
+
* Locked elements in a multi-selection are never translated: they may stay in
|
|
25
|
+
* the controlled selection for feedback, but the drag set excludes them and they
|
|
26
|
+
* remain snap candidates. Holding Shift while the drag is in flight locks the
|
|
27
|
+
* translation to the dominant axis (Shift at pointer-down is a selection
|
|
28
|
+
* modifier and never arms a drag).
|
|
29
|
+
*
|
|
30
|
+
* A single-element move commits `element.update` (backward compat with hosts);
|
|
31
|
+
* a multi-element move commits ONE `element.updateMany` = one host undo entry.
|
|
32
|
+
*
|
|
33
|
+
* `onElementPointerDown` closes over the current render's props, so each gesture
|
|
34
|
+
* captures a consistent snapshot of the controlled slide at pointer-down.
|
|
35
|
+
*
|
|
36
|
+
* Pure gesture glue: no store, no `@/` imports.
|
|
37
|
+
*/
|
|
38
|
+
function useEditGesture(args) {
|
|
39
|
+
const { slide, scale, selection, snapping, onSelectionChange, onElementsChange } = args;
|
|
40
|
+
const [working, setWorking] = useState(null);
|
|
41
|
+
// Teardown for the currently-armed gesture's window listeners. Single-pointer:
|
|
42
|
+
// each pointer-down re-arms and overwrites this with its own teardown, and
|
|
43
|
+
// pointer-up clears it. Held here (not in the closure) so the unmount effect
|
|
44
|
+
// can remove any listeners still live when the component unmounts mid-drag —
|
|
45
|
+
// otherwise a later pointer-move/up would `setWorking` on an unmounted host.
|
|
46
|
+
const teardownRef = useRef(null);
|
|
47
|
+
// The pointerId owning the in-flight gesture. Single-pointer by design: while
|
|
48
|
+
// one gesture is active, further pointer-downs are ignored and window
|
|
49
|
+
// move/up events from any *other* pointerId are dropped, so a second finger
|
|
50
|
+
// can't overwrite the teardown ref or drag the first element.
|
|
51
|
+
const activePointerRef = useRef(null);
|
|
52
|
+
useEffect(() => () => {
|
|
53
|
+
teardownRef.current?.();
|
|
54
|
+
teardownRef.current = null;
|
|
55
|
+
activePointerRef.current = null;
|
|
56
|
+
}, []);
|
|
57
|
+
const onElementPointerDown = (el, e) => {
|
|
58
|
+
// Defense-in-depth: never arm a gesture for a locked element, even if a
|
|
59
|
+
// move hit target somehow reached it (the primary guard lives in
|
|
60
|
+
// EditableSlideCanvas, which skips rendering a hit target for `el.lock`).
|
|
61
|
+
if (el.lock)
|
|
62
|
+
return;
|
|
63
|
+
// Ignore additional pointer-downs while a gesture is already in flight.
|
|
64
|
+
if (activePointerRef.current !== null)
|
|
65
|
+
return;
|
|
66
|
+
// Resolve selection on pointer-down per the shared modifier table
|
|
67
|
+
// ({@link resolveClickSelection} — group-cohesive). `armDrag` decides
|
|
68
|
+
// whether this gesture becomes a move; `dragIds` is the set the move
|
|
69
|
+
// translates (the whole selection for a multi-drag).
|
|
70
|
+
const { next, armDrag, dragIds } = resolveClickSelection({
|
|
71
|
+
element: el,
|
|
72
|
+
elements: slide.elements,
|
|
73
|
+
selection,
|
|
74
|
+
modifier: isSelectionModifier(e),
|
|
75
|
+
});
|
|
76
|
+
if (next)
|
|
77
|
+
onSelectionChange?.(next);
|
|
78
|
+
// A pure selection action (modifier add/remove): no move gesture is armed,
|
|
79
|
+
// so DON'T claim the active pointer — leave the hook ready for the next one.
|
|
80
|
+
if (!armDrag)
|
|
81
|
+
return;
|
|
82
|
+
activePointerRef.current = e.pointerId;
|
|
83
|
+
const startX = e.clientX;
|
|
84
|
+
const startY = e.clientY;
|
|
85
|
+
// Base snapshots captured at pointer-down. `selectedElements` is the rigid
|
|
86
|
+
// set the drag translates; `others` are the snap candidates (everything
|
|
87
|
+
// NOT being dragged). Locked elements never move: even when selected they
|
|
88
|
+
// are excluded from the translated set (selection keeps them for feedback)
|
|
89
|
+
// and stay in `others` as snap candidates. A 1-mover drag routes through
|
|
90
|
+
// `computeDragMove` for exact backward compatibility; N > 1 routes through
|
|
91
|
+
// the multi core.
|
|
92
|
+
const selectedSet = new Set(dragIds);
|
|
93
|
+
const isMover = (o) => selectedSet.has(o.id) && !o.lock;
|
|
94
|
+
const selectedElements = slide.elements.filter(isMover);
|
|
95
|
+
const others = slide.elements.filter((o) => !isMover(o));
|
|
96
|
+
const isMulti = selectedElements.length > 1;
|
|
97
|
+
const viewport = {
|
|
98
|
+
width: slide.viewportSize,
|
|
99
|
+
height: slide.viewportSize * slide.viewportRatio,
|
|
100
|
+
};
|
|
101
|
+
const effectiveScale = scale || 1;
|
|
102
|
+
try {
|
|
103
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
// jsdom / unsupported: pointer capture is a best-effort nicety.
|
|
107
|
+
}
|
|
108
|
+
// Normalize both cores to a list of per-element `{id, props}` updates so the
|
|
109
|
+
// working-copy and commit paths are identical regardless of selection size.
|
|
110
|
+
// `shiftKey` is read off the LIVE pointermove/pointerup event: holding Shift
|
|
111
|
+
// while the drag is in flight locks the translation to the dominant axis
|
|
112
|
+
// (the axis with the larger absolute delta) — Shift at pointer-down is a
|
|
113
|
+
// selection modifier and never arms a drag in the first place.
|
|
114
|
+
const compute = (clientX, clientY, shiftKey) => {
|
|
115
|
+
const deltaCanvas = {
|
|
116
|
+
x: (clientX - startX) / effectiveScale,
|
|
117
|
+
y: (clientY - startY) / effectiveScale,
|
|
118
|
+
};
|
|
119
|
+
const axisLock = shiftKey
|
|
120
|
+
? Math.abs(deltaCanvas.x) >= Math.abs(deltaCanvas.y)
|
|
121
|
+
? 'x'
|
|
122
|
+
: 'y'
|
|
123
|
+
: undefined;
|
|
124
|
+
if (isMulti) {
|
|
125
|
+
return computeMultiDragMove({
|
|
126
|
+
selected: selectedElements,
|
|
127
|
+
others,
|
|
128
|
+
viewport,
|
|
129
|
+
deltaCanvas,
|
|
130
|
+
axisLock,
|
|
131
|
+
snapping,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const { props, guides } = computeDragMove({
|
|
135
|
+
element: el,
|
|
136
|
+
others,
|
|
137
|
+
viewport,
|
|
138
|
+
deltaCanvas,
|
|
139
|
+
axisLock,
|
|
140
|
+
snapping,
|
|
141
|
+
});
|
|
142
|
+
return { updates: [{ id: el.id, props }], guides };
|
|
143
|
+
};
|
|
144
|
+
const handleMove = (ev) => {
|
|
145
|
+
if (ev.pointerId !== activePointerRef.current)
|
|
146
|
+
return;
|
|
147
|
+
// Select-only / read-only-ish hosts (no `onElementsChange`) can't commit a
|
|
148
|
+
// move, so a live working copy would just visibly follow the pointer and
|
|
149
|
+
// snap back on pointer-up. Skip live movement entirely when there's no
|
|
150
|
+
// mutation channel — the gesture only ends up selecting (see handleUp).
|
|
151
|
+
if (!onElementsChange)
|
|
152
|
+
return;
|
|
153
|
+
const { updates, guides } = compute(ev.clientX, ev.clientY, ev.shiftKey);
|
|
154
|
+
const patch = new Map(updates.map((u) => [u.id, u.props]));
|
|
155
|
+
const live = {
|
|
156
|
+
...slide,
|
|
157
|
+
elements: slide.elements.map((o) => {
|
|
158
|
+
const props = patch.get(o.id);
|
|
159
|
+
return props ? { ...o, ...props } : o;
|
|
160
|
+
}),
|
|
161
|
+
};
|
|
162
|
+
setWorking({ id: el.id, live, guides });
|
|
163
|
+
};
|
|
164
|
+
const removeListeners = () => {
|
|
165
|
+
window.removeEventListener('pointermove', handleMove);
|
|
166
|
+
window.removeEventListener('pointerup', handleUp);
|
|
167
|
+
window.removeEventListener('pointercancel', handleCancel);
|
|
168
|
+
};
|
|
169
|
+
const handleUp = (ev) => {
|
|
170
|
+
if (ev.pointerId !== activePointerRef.current)
|
|
171
|
+
return;
|
|
172
|
+
removeListeners();
|
|
173
|
+
teardownRef.current = null;
|
|
174
|
+
activePointerRef.current = null;
|
|
175
|
+
// Combined (Euclidean) distance: a diagonal move past the threshold on
|
|
176
|
+
// both axes must classify as a drag even if neither axis alone exceeds it.
|
|
177
|
+
const movedPast = Math.hypot(ev.clientX - startX, ev.clientY - startY) > DRAG_THRESHOLD_PX;
|
|
178
|
+
// A move intent is only meaningful when the host can mutate. When it moved
|
|
179
|
+
// past the threshold and there's a mutation channel, emit exactly one move
|
|
180
|
+
// intent — `element.update` for a lone element (backward compat), a single
|
|
181
|
+
// `element.updateMany` for a multi-drag (one host undo entry). Otherwise (a
|
|
182
|
+
// click, or a drag on a select-only host) there is nothing extra to emit:
|
|
183
|
+
// the element was already selected on pointer-down.
|
|
184
|
+
if (movedPast && onElementsChange) {
|
|
185
|
+
const { updates } = compute(ev.clientX, ev.clientY, ev.shiftKey);
|
|
186
|
+
const intent = isMulti
|
|
187
|
+
? moveManyIntent(updates)
|
|
188
|
+
: moveIntent(updates[0].id, updates[0].props);
|
|
189
|
+
onElementsChange([intent]);
|
|
190
|
+
}
|
|
191
|
+
setWorking(null);
|
|
192
|
+
};
|
|
193
|
+
// Browser-initiated cancel (touch interruption, OS gesture takeover): tear
|
|
194
|
+
// down and revert the working copy WITHOUT emitting any intent or selection
|
|
195
|
+
// change, then leave the hook ready for a fresh gesture.
|
|
196
|
+
const handleCancel = (ev) => {
|
|
197
|
+
if (ev.pointerId !== activePointerRef.current)
|
|
198
|
+
return;
|
|
199
|
+
removeListeners();
|
|
200
|
+
teardownRef.current = null;
|
|
201
|
+
activePointerRef.current = null;
|
|
202
|
+
setWorking(null);
|
|
203
|
+
};
|
|
204
|
+
window.addEventListener('pointermove', handleMove);
|
|
205
|
+
window.addEventListener('pointerup', handleUp);
|
|
206
|
+
window.addEventListener('pointercancel', handleCancel);
|
|
207
|
+
teardownRef.current = removeListeners;
|
|
208
|
+
};
|
|
209
|
+
return {
|
|
210
|
+
workingSlide: working?.live ?? slide,
|
|
211
|
+
guides: working?.guides ?? [],
|
|
212
|
+
onElementPointerDown,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export { useEditGesture };
|
|
217
|
+
//# sourceMappingURL=useEditGesture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditGesture.js","sources":["../../src/editing/useEditGesture.ts"],"sourcesContent":["'use client';\n\nimport { useState, useEffect, useRef, type PointerEvent as ReactPointerEvent } from 'react';\nimport type { PPTElement, Slide } from '@openmaic/dsl';\n\nimport { computeDragMove, computeMultiDragMove } from './core/drag';\nimport { moveIntent, moveManyIntent } from './core/intent';\nimport { isSelectionModifier, resolveClickSelection } from './core/selection';\nimport type { Guide } from './core/snapping';\nimport type { EditIntent, Selection, SnappingOptions } from './types';\n\n/**\n * Distance (in screen pixels) the pointer must travel between pointer-down and\n * pointer-up before a gesture counts as a drag rather than a click. Below this,\n * the gesture is treated as a selection click and emits no `element.update`.\n */\nconst DRAG_THRESHOLD_PX = 2;\n\nexport interface UseEditGestureArgs {\n slide: Slide;\n scale: number;\n selection: Selection;\n snapping?: boolean | SnappingOptions;\n onSelectionChange?: (next: Selection) => void;\n onElementsChange?: (intents: EditIntent[]) => void;\n}\n\nexport interface UseEditGestureResult {\n /** The slide to render: the in-gesture working copy while dragging, else `slide`. */\n workingSlide: Slide;\n /** Alignment guides for the active drag (computed; drawn by a later PR). */\n guides: Guide[];\n /** Arm a move/click gesture for `el` from a pointer-down on its hit target. */\n onElementPointerDown: (el: PPTElement, e: ReactPointerEvent) => void;\n}\n\ninterface Working {\n id: string;\n /** Live slide with the dragged element's `left`/`top` updated for 60fps feedback. */\n live: Slide;\n guides: Guide[];\n}\n\n/**\n * Owns one drag/click gesture. Pointer-down resolves the selection per the\n * modifier table in {@link resolveClickSelection} (group-cohesive: a click on a\n * grouped element applies to its whole group), then — for the cases that start\n * a move — arms a drag and records the pointer start + the base slide; window\n * pointer-move (converted screen→canvas via `scale`) republishes a working copy\n * for live feedback; pointer-up commits the move as ONE intent when the pointer\n * moved past `DRAG_THRESHOLD_PX`, otherwise reports a selection click. Emits one\n * intent per completed gesture — never per frame — and clears the working copy\n * so the host's controlled `slide` takes over again.\n *\n * Locked elements in a multi-selection are never translated: they may stay in\n * the controlled selection for feedback, but the drag set excludes them and they\n * remain snap candidates. Holding Shift while the drag is in flight locks the\n * translation to the dominant axis (Shift at pointer-down is a selection\n * modifier and never arms a drag).\n *\n * A single-element move commits `element.update` (backward compat with hosts);\n * a multi-element move commits ONE `element.updateMany` = one host undo entry.\n *\n * `onElementPointerDown` closes over the current render's props, so each gesture\n * captures a consistent snapshot of the controlled slide at pointer-down.\n *\n * Pure gesture glue: no store, no `@/` imports.\n */\nexport function useEditGesture(args: UseEditGestureArgs): UseEditGestureResult {\n const { slide, scale, selection, snapping, onSelectionChange, onElementsChange } = args;\n\n const [working, setWorking] = useState<Working | null>(null);\n\n // Teardown for the currently-armed gesture's window listeners. Single-pointer:\n // each pointer-down re-arms and overwrites this with its own teardown, and\n // pointer-up clears it. Held here (not in the closure) so the unmount effect\n // can remove any listeners still live when the component unmounts mid-drag —\n // otherwise a later pointer-move/up would `setWorking` on an unmounted host.\n const teardownRef = useRef<(() => void) | null>(null);\n\n // The pointerId owning the in-flight gesture. Single-pointer by design: while\n // one gesture is active, further pointer-downs are ignored and window\n // move/up events from any *other* pointerId are dropped, so a second finger\n // can't overwrite the teardown ref or drag the first element.\n const activePointerRef = useRef<number | null>(null);\n\n useEffect(\n () => () => {\n teardownRef.current?.();\n teardownRef.current = null;\n activePointerRef.current = null;\n },\n [],\n );\n\n const onElementPointerDown = (el: PPTElement, e: ReactPointerEvent) => {\n // Defense-in-depth: never arm a gesture for a locked element, even if a\n // move hit target somehow reached it (the primary guard lives in\n // EditableSlideCanvas, which skips rendering a hit target for `el.lock`).\n if (el.lock) return;\n // Ignore additional pointer-downs while a gesture is already in flight.\n if (activePointerRef.current !== null) return;\n\n // Resolve selection on pointer-down per the shared modifier table\n // ({@link resolveClickSelection} — group-cohesive). `armDrag` decides\n // whether this gesture becomes a move; `dragIds` is the set the move\n // translates (the whole selection for a multi-drag).\n const { next, armDrag, dragIds } = resolveClickSelection({\n element: el,\n elements: slide.elements,\n selection,\n modifier: isSelectionModifier(e),\n });\n if (next) onSelectionChange?.(next);\n\n // A pure selection action (modifier add/remove): no move gesture is armed,\n // so DON'T claim the active pointer — leave the hook ready for the next one.\n if (!armDrag) return;\n activePointerRef.current = e.pointerId;\n\n const startX = e.clientX;\n const startY = e.clientY;\n // Base snapshots captured at pointer-down. `selectedElements` is the rigid\n // set the drag translates; `others` are the snap candidates (everything\n // NOT being dragged). Locked elements never move: even when selected they\n // are excluded from the translated set (selection keeps them for feedback)\n // and stay in `others` as snap candidates. A 1-mover drag routes through\n // `computeDragMove` for exact backward compatibility; N > 1 routes through\n // the multi core.\n const selectedSet = new Set(dragIds);\n const isMover = (o: PPTElement) => selectedSet.has(o.id) && !o.lock;\n const selectedElements = slide.elements.filter(isMover);\n const others = slide.elements.filter((o) => !isMover(o));\n const isMulti = selectedElements.length > 1;\n const viewport = {\n width: slide.viewportSize,\n height: slide.viewportSize * slide.viewportRatio,\n };\n const effectiveScale = scale || 1;\n\n try {\n (e.currentTarget as Element).setPointerCapture?.(e.pointerId);\n } catch {\n // jsdom / unsupported: pointer capture is a best-effort nicety.\n }\n\n // Normalize both cores to a list of per-element `{id, props}` updates so the\n // working-copy and commit paths are identical regardless of selection size.\n // `shiftKey` is read off the LIVE pointermove/pointerup event: holding Shift\n // while the drag is in flight locks the translation to the dominant axis\n // (the axis with the larger absolute delta) — Shift at pointer-down is a\n // selection modifier and never arms a drag in the first place.\n const compute = (\n clientX: number,\n clientY: number,\n shiftKey: boolean,\n ): {\n updates: Array<{ id: string; props: { left: number; top: number } }>;\n guides: Guide[];\n } => {\n const deltaCanvas = {\n x: (clientX - startX) / effectiveScale,\n y: (clientY - startY) / effectiveScale,\n };\n const axisLock: 'x' | 'y' | undefined = shiftKey\n ? Math.abs(deltaCanvas.x) >= Math.abs(deltaCanvas.y)\n ? 'x'\n : 'y'\n : undefined;\n if (isMulti) {\n return computeMultiDragMove({\n handleElement: el,\n selected: selectedElements,\n others,\n viewport,\n deltaCanvas,\n axisLock,\n snapping,\n });\n }\n const { props, guides } = computeDragMove({\n element: el,\n others,\n viewport,\n deltaCanvas,\n axisLock,\n snapping,\n });\n return { updates: [{ id: el.id, props }], guides };\n };\n\n const handleMove = (ev: PointerEvent) => {\n if (ev.pointerId !== activePointerRef.current) return;\n // Select-only / read-only-ish hosts (no `onElementsChange`) can't commit a\n // move, so a live working copy would just visibly follow the pointer and\n // snap back on pointer-up. Skip live movement entirely when there's no\n // mutation channel — the gesture only ends up selecting (see handleUp).\n if (!onElementsChange) return;\n const { updates, guides } = compute(ev.clientX, ev.clientY, ev.shiftKey);\n const patch = new Map(updates.map((u) => [u.id, u.props]));\n const live: Slide = {\n ...slide,\n elements: slide.elements.map((o) => {\n const props = patch.get(o.id);\n return props ? ({ ...o, ...props } as PPTElement) : o;\n }),\n };\n setWorking({ id: el.id, live, guides });\n };\n\n const removeListeners = () => {\n window.removeEventListener('pointermove', handleMove);\n window.removeEventListener('pointerup', handleUp);\n window.removeEventListener('pointercancel', handleCancel);\n };\n\n const handleUp = (ev: PointerEvent) => {\n if (ev.pointerId !== activePointerRef.current) return;\n removeListeners();\n teardownRef.current = null;\n activePointerRef.current = null;\n\n // Combined (Euclidean) distance: a diagonal move past the threshold on\n // both axes must classify as a drag even if neither axis alone exceeds it.\n const movedPast = Math.hypot(ev.clientX - startX, ev.clientY - startY) > DRAG_THRESHOLD_PX;\n\n // A move intent is only meaningful when the host can mutate. When it moved\n // past the threshold and there's a mutation channel, emit exactly one move\n // intent — `element.update` for a lone element (backward compat), a single\n // `element.updateMany` for a multi-drag (one host undo entry). Otherwise (a\n // click, or a drag on a select-only host) there is nothing extra to emit:\n // the element was already selected on pointer-down.\n if (movedPast && onElementsChange) {\n const { updates } = compute(ev.clientX, ev.clientY, ev.shiftKey);\n const intent = isMulti\n ? moveManyIntent(updates)\n : moveIntent(updates[0].id, updates[0].props);\n onElementsChange([intent]);\n }\n\n setWorking(null);\n };\n\n // Browser-initiated cancel (touch interruption, OS gesture takeover): tear\n // down and revert the working copy WITHOUT emitting any intent or selection\n // change, then leave the hook ready for a fresh gesture.\n const handleCancel = (ev: PointerEvent) => {\n if (ev.pointerId !== activePointerRef.current) return;\n removeListeners();\n teardownRef.current = null;\n activePointerRef.current = null;\n setWorking(null);\n };\n\n window.addEventListener('pointermove', handleMove);\n window.addEventListener('pointerup', handleUp);\n window.addEventListener('pointercancel', handleCancel);\n teardownRef.current = removeListeners;\n };\n\n return {\n workingSlide: working?.live ?? slide,\n guides: working?.guides ?? [],\n onElementPointerDown,\n };\n}\n"],"names":[],"mappings":";;;;;;AAWA;;;;AAIG;AACH;AA2BA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACG;AACJ;;;;;;;AASA;;;;;AAMA;AAEA;AAEI;AACA;AACA;;AAKJ;;;;;;;AAME;;;;;;;AAOE;;;AAGA;AACD;AACD;AAAU;;;AAIV;;AACA;AAEA;AACA;;;;;;;;AAQA;;;AAGA;AACA;AACA;;AAEE;;AAEF;AAEA;;;AAEE;;;;;;;;;;AAkBA;AACE;AACA;;;AAGA;AACE;AACA;;;AAGF;AACE;;;;;;AAOD;;AAEH;AACE;;;;;;AAMD;AACD;AACF;AAEA;AACE;;;;;;AAKA;;;;AAGA;AACE;;;AAGE;AACF;;AAEF;AACF;;AAGE;AACA;AACA;AACF;AAEA;AACE;;AACA;AACA;AACA;;;;;;;;;;AAYA;AACE;;AAEE;AACA;AACF;;;AAIJ;;;;AAKA;AACE;;AACA;AACA;AACA;;AAEF;AAEA;AACA;AACA;AACA;AACF;;AAGE;AACA;;;AAGJ;;"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type PointerEvent as ReactPointerEvent } from 'react';
|
|
2
|
+
import type { PPTLineElement } from '@openmaic/dsl';
|
|
3
|
+
import { type LineDragResult } from './core/line-drag';
|
|
4
|
+
import type { EditIntent, LineHandle } from './types';
|
|
5
|
+
export interface UseLineHandleGestureArgs {
|
|
6
|
+
/** Canvas → screen scale; the inverse converts the pointer delta to canvas units. */
|
|
7
|
+
scale: number;
|
|
8
|
+
onElementsChange?: (intents: EditIntent[]) => void;
|
|
9
|
+
}
|
|
10
|
+
/** The in-flight handle drag: which line, and the working props to preview. */
|
|
11
|
+
export interface LineHandleDrag {
|
|
12
|
+
id: string;
|
|
13
|
+
props: LineDragResult['props'];
|
|
14
|
+
}
|
|
15
|
+
export interface UseLineHandleGestureResult {
|
|
16
|
+
/** The active handle drag's working props (for live preview), else `null`. */
|
|
17
|
+
lineDrag: LineHandleDrag | null;
|
|
18
|
+
/** Arm a reshape gesture from a pointer-down on `element`'s `handle`. */
|
|
19
|
+
onHandlePointerDown: (element: PPTLineElement, handle: LineHandle, e: ReactPointerEvent) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Owns one line-handle reshape gesture, mirroring {@link useEditGesture} but for
|
|
23
|
+
* a single dragged endpoint/control point. Pointer-down records the pointer
|
|
24
|
+
* start + the ORIGINAL line + the handle; window pointer-move converts the
|
|
25
|
+
* screen delta to canvas units (`/scale`), runs the store-free
|
|
26
|
+
* {@link computeLineDrag}, and republishes the resulting props as a working copy
|
|
27
|
+
* for 60fps preview; pointer-up commits exactly one `element.update` intent when
|
|
28
|
+
* the pointer moved past {@link DRAG_THRESHOLD_PX} and a mutation channel exists,
|
|
29
|
+
* then clears the working copy. `pointercancel` reverts without emitting.
|
|
30
|
+
*
|
|
31
|
+
* Single-pointer by design: a second pointer-down while a gesture is in flight
|
|
32
|
+
* is ignored, and window move/up from any other pointerId is dropped. Pure
|
|
33
|
+
* gesture glue: no store, no `@/` imports.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useLineHandleGesture(args: UseLineHandleGestureArgs): UseLineHandleGestureResult;
|