@openmaic/renderer 0.0.4 → 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/line/BaseLineElement.js +5 -4
- package/dist/elements/line/BaseLineElement.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,128 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useState, useRef, useEffect } from 'react';
|
|
3
|
-
import { computeRotate } from './core/rotate.js';
|
|
4
|
-
import { rotateIntent } from './core/intent.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Distance (screen px) the pointer must travel between pointer-down and
|
|
8
|
-
* pointer-up before the gesture commits a rotation. Below this a handle click
|
|
9
|
-
* is inert (no `element.update`), mirroring the other gesture hooks.
|
|
10
|
-
*/
|
|
11
|
-
const DRAG_THRESHOLD_PX = 2;
|
|
12
|
-
/**
|
|
13
|
-
* Owns one rotate-handle gesture, mirroring {@link useEditGesture} but for the
|
|
14
|
-
* rotate handle above a box's top edge. Pointer-down records the ORIGINAL
|
|
15
|
-
* element (whose center is the rotation pivot for the whole gesture) and the
|
|
16
|
-
* canvas origin's screen position; window pointer-move converts the pointer's
|
|
17
|
-
* absolute position to canvas coordinates, runs the store-free
|
|
18
|
-
* {@link computeRotate} (signed angle, 45° snap), and republishes the angle as
|
|
19
|
-
* a working copy for 60fps preview; pointer-up commits exactly one
|
|
20
|
-
* `element.update` intent when the pointer moved past {@link DRAG_THRESHOLD_PX},
|
|
21
|
-
* a mutation channel exists, and the angle actually changed, then clears the
|
|
22
|
-
* working copy. `pointercancel` reverts without emitting.
|
|
23
|
-
*
|
|
24
|
-
* Single-pointer by design: a second pointer-down while a gesture is in flight
|
|
25
|
-
* is ignored, and window move/up from any other pointerId is dropped. Pure
|
|
26
|
-
* gesture glue: no store, no `@/` imports.
|
|
27
|
-
*/
|
|
28
|
-
function useRotateGesture(args) {
|
|
29
|
-
const { overlayRef, viewportStyles, scale, onElementsChange } = args;
|
|
30
|
-
const [rotateDrag, setRotateDrag] = useState(null);
|
|
31
|
-
// Teardown for the currently-armed gesture's window listeners; the unmount
|
|
32
|
-
// effect removes any listeners still live so a late move/up can't setState on
|
|
33
|
-
// an unmounted host.
|
|
34
|
-
const teardownRef = useRef(null);
|
|
35
|
-
// The pointerId owning the in-flight gesture (single-pointer guard).
|
|
36
|
-
const activePointerRef = useRef(null);
|
|
37
|
-
useEffect(() => () => {
|
|
38
|
-
teardownRef.current?.();
|
|
39
|
-
teardownRef.current = null;
|
|
40
|
-
activePointerRef.current = null;
|
|
41
|
-
}, []);
|
|
42
|
-
const onRotateHandlePointerDown = (element, e) => {
|
|
43
|
-
// Defense-in-depth: never arm on a locked element (the primary guard skips
|
|
44
|
-
// rendering handles for a locked element in EditableSlideCanvas).
|
|
45
|
-
if (element.lock)
|
|
46
|
-
return;
|
|
47
|
-
if (activePointerRef.current !== null)
|
|
48
|
-
return;
|
|
49
|
-
// Rotation needs the canvas origin; without a mounted overlay the pointer
|
|
50
|
-
// position cannot be mapped to canvas coordinates, so don't arm at all.
|
|
51
|
-
const overlay = overlayRef.current;
|
|
52
|
-
if (!overlay)
|
|
53
|
-
return;
|
|
54
|
-
activePointerRef.current = e.pointerId;
|
|
55
|
-
// A handle drag rotates the element — it must never fall through to the
|
|
56
|
-
// box hit layer beneath (which would start a move or change selection).
|
|
57
|
-
e.stopPropagation();
|
|
58
|
-
const startX = e.clientX;
|
|
59
|
-
const startY = e.clientY;
|
|
60
|
-
const effectiveScale = scale || 1;
|
|
61
|
-
// Canvas origin in client coordinates, captured once per gesture (the
|
|
62
|
-
// canvas doesn't scroll/zoom mid-gesture; app parity).
|
|
63
|
-
const overlayRect = overlay.getBoundingClientRect();
|
|
64
|
-
const originX = overlayRect.left + viewportStyles.left;
|
|
65
|
-
const originY = overlayRect.top + viewportStyles.top;
|
|
66
|
-
const originRotate = element.rotate || 0;
|
|
67
|
-
try {
|
|
68
|
-
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
// jsdom / unsupported: pointer capture is a best-effort nicety.
|
|
72
|
-
}
|
|
73
|
-
const compute = (clientX, clientY) => computeRotate({
|
|
74
|
-
element,
|
|
75
|
-
pointerCanvas: {
|
|
76
|
-
x: (clientX - originX) / effectiveScale,
|
|
77
|
-
y: (clientY - originY) / effectiveScale,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
const handleMove = (ev) => {
|
|
81
|
-
if (ev.pointerId !== activePointerRef.current)
|
|
82
|
-
return;
|
|
83
|
-
// No mutation channel: a live preview would just follow the pointer and
|
|
84
|
-
// snap back on pointer-up. Skip live movement when nothing can commit.
|
|
85
|
-
if (!onElementsChange)
|
|
86
|
-
return;
|
|
87
|
-
setRotateDrag({ id: element.id, rotate: compute(ev.clientX, ev.clientY) });
|
|
88
|
-
};
|
|
89
|
-
const removeListeners = () => {
|
|
90
|
-
window.removeEventListener('pointermove', handleMove);
|
|
91
|
-
window.removeEventListener('pointerup', handleUp);
|
|
92
|
-
window.removeEventListener('pointercancel', handleCancel);
|
|
93
|
-
};
|
|
94
|
-
const handleUp = (ev) => {
|
|
95
|
-
if (ev.pointerId !== activePointerRef.current)
|
|
96
|
-
return;
|
|
97
|
-
removeListeners();
|
|
98
|
-
teardownRef.current = null;
|
|
99
|
-
activePointerRef.current = null;
|
|
100
|
-
const movedPast = Math.hypot(ev.clientX - startX, ev.clientY - startY) > DRAG_THRESHOLD_PX;
|
|
101
|
-
if (movedPast && onElementsChange) {
|
|
102
|
-
const rotate = compute(ev.clientX, ev.clientY);
|
|
103
|
-
// Snapping can land the pointer back on the original angle; a no-op
|
|
104
|
-
// update would still cost the host an undo entry, so skip it.
|
|
105
|
-
if (rotate !== originRotate) {
|
|
106
|
-
onElementsChange([rotateIntent(element.id, rotate)]);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
setRotateDrag(null);
|
|
110
|
-
};
|
|
111
|
-
const handleCancel = (ev) => {
|
|
112
|
-
if (ev.pointerId !== activePointerRef.current)
|
|
113
|
-
return;
|
|
114
|
-
removeListeners();
|
|
115
|
-
teardownRef.current = null;
|
|
116
|
-
activePointerRef.current = null;
|
|
117
|
-
setRotateDrag(null);
|
|
118
|
-
};
|
|
119
|
-
window.addEventListener('pointermove', handleMove);
|
|
120
|
-
window.addEventListener('pointerup', handleUp);
|
|
121
|
-
window.addEventListener('pointercancel', handleCancel);
|
|
122
|
-
teardownRef.current = removeListeners;
|
|
123
|
-
};
|
|
124
|
-
return { rotateDrag, onRotateHandlePointerDown };
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export { useRotateGesture };
|
|
128
|
-
//# sourceMappingURL=useRotateGesture.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useRotateGesture.js","sources":["../../src/editing/useRotateGesture.ts"],"sourcesContent":["'use client';\n\nimport {\n useState,\n useEffect,\n useRef,\n type PointerEvent as ReactPointerEvent,\n type RefObject,\n} from 'react';\n\nimport { computeRotate } from './core/rotate';\nimport { rotateIntent } from './core/intent';\nimport type { PPTBoxElement } from './core/resize';\nimport type { ViewportStyles } from '../hooks/useViewportSize';\nimport type { EditIntent } from './types';\n\n/**\n * Distance (screen px) the pointer must travel between pointer-down and\n * pointer-up before the gesture commits a rotation. Below this a handle click\n * is inert (no `element.update`), mirroring the other gesture hooks.\n */\nconst DRAG_THRESHOLD_PX = 2;\n\nexport interface UseRotateGestureArgs {\n /**\n * The interaction overlay element. Its bounding rect (captured once per\n * gesture, at pointer-down) plus `viewportStyles.left/top` locate the canvas\n * origin on screen, which is what converts absolute pointer positions to\n * canvas coordinates — rotation is computed from the ABSOLUTE pointer\n * position relative to the element center, not from a pointer delta.\n */\n overlayRef: RefObject<HTMLElement | null>;\n /** SlideCanvas centering offset (screen px) inside the overlay. */\n viewportStyles: ViewportStyles;\n /** Canvas → screen scale; the inverse converts pointer positions to canvas units. */\n scale: number;\n onElementsChange?: (intents: EditIntent[]) => void;\n}\n\n/** The in-flight rotate drag: which element and the working angle to preview. */\nexport interface RotateDrag {\n id: string;\n rotate: number;\n}\n\nexport interface UseRotateGestureResult {\n /** The active rotate drag's working angle (for live preview), else `null`. */\n rotateDrag: RotateDrag | null;\n /** Arm a rotate gesture from a pointer-down on `element`'s rotate handle. */\n onRotateHandlePointerDown: (element: PPTBoxElement, e: ReactPointerEvent) => void;\n}\n\n/**\n * Owns one rotate-handle gesture, mirroring {@link useEditGesture} but for the\n * rotate handle above a box's top edge. Pointer-down records the ORIGINAL\n * element (whose center is the rotation pivot for the whole gesture) and the\n * canvas origin's screen position; window pointer-move converts the pointer's\n * absolute position to canvas coordinates, runs the store-free\n * {@link computeRotate} (signed angle, 45° snap), and republishes the angle as\n * a working copy for 60fps preview; pointer-up commits exactly one\n * `element.update` intent when the pointer moved past {@link DRAG_THRESHOLD_PX},\n * a mutation channel exists, and the angle actually changed, then clears the\n * working copy. `pointercancel` reverts without emitting.\n *\n * Single-pointer by design: a second pointer-down while a gesture is in flight\n * is ignored, and window move/up from any other pointerId is dropped. Pure\n * gesture glue: no store, no `@/` imports.\n */\nexport function useRotateGesture(args: UseRotateGestureArgs): UseRotateGestureResult {\n const { overlayRef, viewportStyles, scale, onElementsChange } = args;\n\n const [rotateDrag, setRotateDrag] = useState<RotateDrag | null>(null);\n\n // Teardown for the currently-armed gesture's window listeners; the unmount\n // effect removes any listeners still live so a late move/up can't setState on\n // an unmounted host.\n const teardownRef = useRef<(() => void) | null>(null);\n // The pointerId owning the in-flight gesture (single-pointer guard).\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 onRotateHandlePointerDown = (element: PPTBoxElement, e: ReactPointerEvent) => {\n // Defense-in-depth: never arm on a locked element (the primary guard skips\n // rendering handles for a locked element in EditableSlideCanvas).\n if (element.lock) return;\n if (activePointerRef.current !== null) return;\n // Rotation needs the canvas origin; without a mounted overlay the pointer\n // position cannot be mapped to canvas coordinates, so don't arm at all.\n const overlay = overlayRef.current;\n if (!overlay) return;\n activePointerRef.current = e.pointerId;\n\n // A handle drag rotates the element — it must never fall through to the\n // box hit layer beneath (which would start a move or change selection).\n e.stopPropagation();\n\n const startX = e.clientX;\n const startY = e.clientY;\n const effectiveScale = scale || 1;\n\n // Canvas origin in client coordinates, captured once per gesture (the\n // canvas doesn't scroll/zoom mid-gesture; app parity).\n const overlayRect = overlay.getBoundingClientRect();\n const originX = overlayRect.left + viewportStyles.left;\n const originY = overlayRect.top + viewportStyles.top;\n\n const originRotate = element.rotate || 0;\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 const compute = (clientX: number, clientY: number) =>\n computeRotate({\n element,\n pointerCanvas: {\n x: (clientX - originX) / effectiveScale,\n y: (clientY - originY) / effectiveScale,\n },\n });\n\n const handleMove = (ev: PointerEvent) => {\n if (ev.pointerId !== activePointerRef.current) return;\n // No mutation channel: a live preview would just follow the pointer and\n // snap back on pointer-up. Skip live movement when nothing can commit.\n if (!onElementsChange) return;\n setRotateDrag({ id: element.id, rotate: compute(ev.clientX, ev.clientY) });\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 const movedPast = Math.hypot(ev.clientX - startX, ev.clientY - startY) > DRAG_THRESHOLD_PX;\n if (movedPast && onElementsChange) {\n const rotate = compute(ev.clientX, ev.clientY);\n // Snapping can land the pointer back on the original angle; a no-op\n // update would still cost the host an undo entry, so skip it.\n if (rotate !== originRotate) {\n onElementsChange([rotateIntent(element.id, rotate)]);\n }\n }\n\n setRotateDrag(null);\n };\n\n const handleCancel = (ev: PointerEvent) => {\n if (ev.pointerId !== activePointerRef.current) return;\n removeListeners();\n teardownRef.current = null;\n activePointerRef.current = null;\n setRotateDrag(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 { rotateDrag, onRotateHandlePointerDown };\n}\n"],"names":[],"mappings":";;;;;AAgBA;;;;AAIG;AACH;AA+BA;;;;;;;;;;;;;;;AAeG;AACG;;;;;;AAQJ;;AAEA;AAEA;AAEI;AACA;AACA;;AAKJ;;;;;AAIE;;;;AAGA;AACA;;AACA;;;;AAMA;AACA;AACA;;;AAIA;;;AAIA;AAEA;;;AAEE;;;;;AAOE;AACE;AACA;AACD;AACF;AAEH;AACE;;;;AAGA;;;AAEF;;AAGE;AACA;AACA;AACF;AAEA;AACE;;AACA;AACA;AACA;;AAGA;AACE;;;AAGA;AACE;;;;AAKN;AAEA;AACE;;AACA;AACA;AACA;;AAEF;AAEA;AACA;AACA;AACA;AACF;AAEA;AACF;;"}
|