@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,128 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
function HighlightOverlay({ element, options }) {
|
|
5
|
+
if (element.type === 'line')
|
|
6
|
+
return null;
|
|
7
|
+
const color = options?.color ?? '#ff6b6b';
|
|
8
|
+
const opacity = options?.opacity ?? 0.3;
|
|
9
|
+
const borderWidth = options?.borderWidth ?? 3;
|
|
10
|
+
const animated = options?.animated ?? true;
|
|
11
|
+
const height = 'height' in element ? element.height : 0;
|
|
12
|
+
const rotate = 'rotate' in element ? element.rotate : 0;
|
|
13
|
+
return (jsxs("div", { className: "highlight-overlay", style: {
|
|
14
|
+
position: 'absolute',
|
|
15
|
+
pointerEvents: 'none',
|
|
16
|
+
left: `${element.left}px`,
|
|
17
|
+
top: `${element.top}px`,
|
|
18
|
+
width: `${element.width}px`,
|
|
19
|
+
height: `${height}px`,
|
|
20
|
+
transform: `rotate(${rotate || 0}deg)`,
|
|
21
|
+
transformOrigin: 'center',
|
|
22
|
+
zIndex: 999,
|
|
23
|
+
transition: 'all 0.3s ease-in-out',
|
|
24
|
+
}, children: [jsx("div", { className: animated ? 'slide-renderer-pulse' : undefined, style: {
|
|
25
|
+
position: 'absolute',
|
|
26
|
+
inset: 0,
|
|
27
|
+
borderRadius: '4px',
|
|
28
|
+
border: `${borderWidth}px solid ${color}`,
|
|
29
|
+
boxShadow: `0 0 ${borderWidth * 3}px ${color}, inset 0 0 ${borderWidth * 2}px rgba(255,255,255,${opacity * 0.5})`,
|
|
30
|
+
backgroundColor: `${color}${Math.round(opacity * 255)
|
|
31
|
+
.toString(16)
|
|
32
|
+
.padStart(2, '0')}`,
|
|
33
|
+
} }), animated && (jsx("div", { className: "slide-renderer-ping", style: {
|
|
34
|
+
position: 'absolute',
|
|
35
|
+
inset: 0,
|
|
36
|
+
borderRadius: '4px',
|
|
37
|
+
border: `${borderWidth}px solid ${color}`,
|
|
38
|
+
opacity: 0.5,
|
|
39
|
+
animationDuration: '2s',
|
|
40
|
+
} }))] }));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { HighlightOverlay };
|
|
44
|
+
//# sourceMappingURL=HighlightOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HighlightOverlay.js","sources":["../../src/effects/HighlightOverlay.tsx"],"sourcesContent":["'use client';\n\nimport type { PPTElement } from '@openmaic/dsl';\nimport type { HighlightEffectOptions } from '../types/effects';\n\nexport interface HighlightOverlayProps {\n element: PPTElement;\n options?: HighlightEffectOptions;\n}\n\nexport function HighlightOverlay({ element, options }: HighlightOverlayProps) {\n if (element.type === 'line') return null;\n\n const color = options?.color ?? '#ff6b6b';\n const opacity = options?.opacity ?? 0.3;\n const borderWidth = options?.borderWidth ?? 3;\n const animated = options?.animated ?? true;\n\n const height = 'height' in element ? element.height : 0;\n const rotate = 'rotate' in element ? element.rotate : 0;\n\n return (\n <div\n className=\"highlight-overlay\"\n style={{\n position: 'absolute',\n pointerEvents: 'none',\n left: `${element.left}px`,\n top: `${element.top}px`,\n width: `${element.width}px`,\n height: `${height}px`,\n transform: `rotate(${rotate || 0}deg)`,\n transformOrigin: 'center',\n zIndex: 999,\n transition: 'all 0.3s ease-in-out',\n }}\n >\n <div\n className={animated ? 'slide-renderer-pulse' : undefined}\n style={{\n position: 'absolute',\n inset: 0,\n borderRadius: '4px',\n border: `${borderWidth}px solid ${color}`,\n boxShadow: `0 0 ${borderWidth * 3}px ${color}, inset 0 0 ${borderWidth * 2}px rgba(255,255,255,${opacity * 0.5})`,\n backgroundColor: `${color}${Math.round(opacity * 255)\n .toString(16)\n .padStart(2, '0')}`,\n }}\n />\n {animated && (\n <div\n className=\"slide-renderer-ping\"\n style={{\n position: 'absolute',\n inset: 0,\n borderRadius: '4px',\n border: `${borderWidth}px solid ${color}`,\n opacity: 0.5,\n animationDuration: '2s',\n }}\n />\n )}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;AAWE;AAA6B;AAE7B;AACA;AACA;AACA;AAEA;AACA;AAEA;AAIM;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACD;AAKG;AACA;AACA;AACA;AACA;;;AAGG;;AAOD;AACA;AACA;AACA;AACA;AACA;;AAMZ;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { motion } from 'motion/react';
|
|
4
|
+
|
|
5
|
+
function LaserOverlay({ geometry, color = '#ff3b30', duration: _duration = 3000, }) {
|
|
6
|
+
const { centerX, centerY } = geometry;
|
|
7
|
+
const startPos = {
|
|
8
|
+
x: centerX > 50 ? 105 : -5,
|
|
9
|
+
y: centerY > 50 ? 105 : -5,
|
|
10
|
+
};
|
|
11
|
+
return (jsx(motion.div, { initial: { opacity: 0, left: `${startPos.x}%`, top: `${startPos.y}%` }, animate: { opacity: 1, left: `${centerX}%`, top: `${centerY}%` }, exit: {
|
|
12
|
+
opacity: 0,
|
|
13
|
+
left: `${startPos.x}%`,
|
|
14
|
+
top: `${startPos.y}%`,
|
|
15
|
+
transition: { duration: 0.25, ease: [0.4, 0, 1, 1] },
|
|
16
|
+
}, transition: {
|
|
17
|
+
left: { duration: 0.5, ease: [0.22, 1, 0.36, 1] },
|
|
18
|
+
top: { duration: 0.5, ease: [0.22, 1, 0.36, 1] },
|
|
19
|
+
opacity: { duration: 0.15 },
|
|
20
|
+
}, style: { position: 'absolute', zIndex: 101, pointerEvents: 'none' }, children: jsxs("div", { style: { position: 'relative', transform: 'translate(-50%, -50%)' }, children: [jsx(motion.div, { animate: { scale: [1, 2.8], opacity: [0.6, 0] }, transition: {
|
|
21
|
+
repeat: Infinity,
|
|
22
|
+
duration: 1.5,
|
|
23
|
+
ease: 'easeOut',
|
|
24
|
+
repeatDelay: 0.3,
|
|
25
|
+
}, style: {
|
|
26
|
+
position: 'absolute',
|
|
27
|
+
inset: 0,
|
|
28
|
+
borderRadius: '9999px',
|
|
29
|
+
border: `1.5px solid ${color}`,
|
|
30
|
+
} }), jsx("div", { style: {
|
|
31
|
+
width: '10px',
|
|
32
|
+
height: '10px',
|
|
33
|
+
borderRadius: '9999px',
|
|
34
|
+
backgroundColor: color,
|
|
35
|
+
boxShadow: `0 0 8px 2px ${color}60`,
|
|
36
|
+
} })] }) }, `laser-${centerX}-${centerY}`));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { LaserOverlay };
|
|
40
|
+
//# sourceMappingURL=LaserOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LaserOverlay.js","sources":["../../src/effects/LaserOverlay.tsx"],"sourcesContent":["'use client';\n\nimport { motion } from 'motion/react';\nimport type { PercentageGeometry } from '../utils/geometry';\n\nexport interface LaserOverlayProps {\n geometry: PercentageGeometry;\n color?: string;\n duration?: number;\n}\n\nexport function LaserOverlay({\n geometry,\n color = '#ff3b30',\n duration: _duration = 3000,\n}: LaserOverlayProps) {\n const { centerX, centerY } = geometry;\n\n const startPos = {\n x: centerX > 50 ? 105 : -5,\n y: centerY > 50 ? 105 : -5,\n };\n\n return (\n <motion.div\n key={`laser-${centerX}-${centerY}`}\n initial={{ opacity: 0, left: `${startPos.x}%`, top: `${startPos.y}%` }}\n animate={{ opacity: 1, left: `${centerX}%`, top: `${centerY}%` }}\n exit={{\n opacity: 0,\n left: `${startPos.x}%`,\n top: `${startPos.y}%`,\n transition: { duration: 0.25, ease: [0.4, 0, 1, 1] },\n }}\n transition={{\n left: { duration: 0.5, ease: [0.22, 1, 0.36, 1] },\n top: { duration: 0.5, ease: [0.22, 1, 0.36, 1] },\n opacity: { duration: 0.15 },\n }}\n style={{ position: 'absolute', zIndex: 101, pointerEvents: 'none' }}\n >\n <div style={{ position: 'relative', transform: 'translate(-50%, -50%)' }}>\n <motion.div\n animate={{ scale: [1, 2.8], opacity: [0.6, 0] }}\n transition={{\n repeat: Infinity,\n duration: 1.5,\n ease: 'easeOut',\n repeatDelay: 0.3,\n }}\n style={{\n position: 'absolute',\n inset: 0,\n borderRadius: '9999px',\n border: `1.5px solid ${color}`,\n }}\n />\n <div\n style={{\n width: '10px',\n height: '10px',\n borderRadius: '9999px',\n backgroundColor: color,\n boxShadow: `0 0 8px 2px ${color}60`,\n }}\n />\n </div>\n </motion.div>\n );\n}\n"],"names":[],"mappings":";;;;AAWM;AAKJ;AAEA;AACE;AACA;;;AASI;AACA;AACA;AACA;AACD;AAEC;AACA;AACA;;AAQI;AACA;AACA;AACA;AACD;AAEC;AACA;AACA;;;AAMA;AACA;AACA;AACA;;;AAOZ;;"}
|
|
@@ -3,5 +3,7 @@ export interface SpotlightOverlayProps {
|
|
|
3
3
|
options?: SpotlightEffectOptions;
|
|
4
4
|
/** ID prefix the SlideElement uses on its root div. Default `slide-element-`. */
|
|
5
5
|
elementIdPrefix?: string;
|
|
6
|
+
/** Remeasure when host element data changes without changing the target ID. */
|
|
7
|
+
measurementKey?: unknown;
|
|
6
8
|
}
|
|
7
|
-
export declare function SpotlightOverlay({ options, elementIdPrefix, }: SpotlightOverlayProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare function SpotlightOverlay({ options, elementIdPrefix, measurementKey, }: SpotlightOverlayProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { useRef, useState, useCallback, useLayoutEffect } from 'react';
|
|
4
|
+
import { AnimatePresence, motion } from 'motion/react';
|
|
5
|
+
|
|
6
|
+
function SpotlightOverlay({ options, elementIdPrefix = 'slide-element-', measurementKey, }) {
|
|
7
|
+
const containerRef = useRef(null);
|
|
8
|
+
const [rect, setRect] = useState(null);
|
|
9
|
+
const spotlightElementId = options?.elementId;
|
|
10
|
+
const measure = useCallback(() => {
|
|
11
|
+
if (!spotlightElementId || !containerRef.current) {
|
|
12
|
+
setRect(null);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const domElement = document.getElementById(`${elementIdPrefix}${spotlightElementId}`);
|
|
16
|
+
if (!domElement) {
|
|
17
|
+
setRect(null);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const contentEl = domElement.querySelector('.element-content');
|
|
21
|
+
const targetEl = contentEl ?? domElement;
|
|
22
|
+
const containerRect = containerRef.current.getBoundingClientRect();
|
|
23
|
+
const targetRect = targetEl.getBoundingClientRect();
|
|
24
|
+
if (containerRect.width === 0 || containerRect.height === 0) {
|
|
25
|
+
setRect(null);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
setRect({
|
|
29
|
+
x: ((targetRect.left - containerRect.left) / containerRect.width) * 100,
|
|
30
|
+
y: ((targetRect.top - containerRect.top) / containerRect.height) * 100,
|
|
31
|
+
w: (targetRect.width / containerRect.width) * 100,
|
|
32
|
+
h: (targetRect.height / containerRect.height) * 100,
|
|
33
|
+
});
|
|
34
|
+
}, [spotlightElementId, elementIdPrefix]);
|
|
35
|
+
useLayoutEffect(() => {
|
|
36
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect -- DOM measurement requires effect
|
|
37
|
+
measure();
|
|
38
|
+
const container = containerRef.current;
|
|
39
|
+
if (!container || !spotlightElementId)
|
|
40
|
+
return;
|
|
41
|
+
const root = document.getElementById(`${elementIdPrefix}${spotlightElementId}`);
|
|
42
|
+
const target = root?.querySelector('.element-content') ?? root;
|
|
43
|
+
if (!target)
|
|
44
|
+
return;
|
|
45
|
+
const observer = new ResizeObserver(measure);
|
|
46
|
+
observer.observe(container);
|
|
47
|
+
observer.observe(target);
|
|
48
|
+
const media = target.querySelectorAll('img, video');
|
|
49
|
+
media.forEach((element) => {
|
|
50
|
+
element.addEventListener('load', measure);
|
|
51
|
+
element.addEventListener('loadedmetadata', measure);
|
|
52
|
+
});
|
|
53
|
+
return () => {
|
|
54
|
+
observer.disconnect();
|
|
55
|
+
media.forEach((element) => {
|
|
56
|
+
element.removeEventListener('load', measure);
|
|
57
|
+
element.removeEventListener('loadedmetadata', measure);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
}, [measure, measurementKey, spotlightElementId, elementIdPrefix]);
|
|
61
|
+
const active = !!spotlightElementId && !!rect;
|
|
62
|
+
const dimness = options?.dimness ?? 0.7;
|
|
63
|
+
return (jsx("div", { ref: containerRef, style: {
|
|
64
|
+
position: 'absolute',
|
|
65
|
+
inset: 0,
|
|
66
|
+
zIndex: 100,
|
|
67
|
+
pointerEvents: 'none',
|
|
68
|
+
overflow: 'hidden',
|
|
69
|
+
}, children: jsx(AnimatePresence, { mode: "wait", children: active && rect && (jsx(motion.div, { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 }, style: { position: 'absolute', inset: 0 }, children: jsxs("svg", { width: "100%", height: "100%", viewBox: "0 0 100 100", preserveAspectRatio: "none", style: { position: 'absolute', inset: 0 }, children: [jsx("defs", { children: jsxs("mask", { id: `mask-${spotlightElementId}`, children: [jsx("rect", { x: "0", y: "0", width: "100", height: "100", fill: "white" }), jsx(motion.rect, { fill: "black", initial: {
|
|
70
|
+
x: rect.x - 8,
|
|
71
|
+
y: rect.y - 8,
|
|
72
|
+
width: rect.w + 16,
|
|
73
|
+
height: rect.h + 16,
|
|
74
|
+
rx: 4,
|
|
75
|
+
}, animate: {
|
|
76
|
+
x: rect.x - 0.4,
|
|
77
|
+
y: rect.y - 0.6,
|
|
78
|
+
width: rect.w + 0.8,
|
|
79
|
+
height: rect.h + 1.2,
|
|
80
|
+
rx: 1,
|
|
81
|
+
}, transition: { duration: 0.6, ease: [0.16, 1, 0.3, 1] } })] }) }), jsx("rect", { width: "100", height: "100", fill: `rgba(0,0,0,${dimness})`, mask: `url(#mask-${spotlightElementId})` }), jsx(motion.rect, { initial: {
|
|
82
|
+
x: rect.x - 4,
|
|
83
|
+
y: rect.y - 4,
|
|
84
|
+
width: rect.w + 8,
|
|
85
|
+
height: rect.h + 8,
|
|
86
|
+
opacity: 0,
|
|
87
|
+
rx: 2,
|
|
88
|
+
}, animate: {
|
|
89
|
+
x: rect.x - 0.4,
|
|
90
|
+
y: rect.y - 0.6,
|
|
91
|
+
width: rect.w + 0.8,
|
|
92
|
+
height: rect.h + 1.2,
|
|
93
|
+
opacity: 1,
|
|
94
|
+
rx: 1,
|
|
95
|
+
}, fill: "none", stroke: "rgba(255,255,255,0.7)", strokeWidth: "1.2", style: { vectorEffect: 'non-scaling-stroke' }, transition: { duration: 0.5, delay: 0.05, ease: [0.16, 1, 0.3, 1] } })] }) }, `spotlight-${spotlightElementId}`)) }) }));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { SpotlightOverlay };
|
|
99
|
+
//# sourceMappingURL=SpotlightOverlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpotlightOverlay.js","sources":["../../src/effects/SpotlightOverlay.tsx"],"sourcesContent":["'use client';\n\nimport { useRef, useState, useLayoutEffect, useCallback } from 'react';\nimport { motion, AnimatePresence } from 'motion/react';\nimport type { SpotlightEffectOptions } from '../types/effects';\n\ninterface SpotlightRect {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\nexport interface SpotlightOverlayProps {\n options?: SpotlightEffectOptions;\n /** ID prefix the SlideElement uses on its root div. Default `slide-element-`. */\n elementIdPrefix?: string;\n /** Remeasure when host element data changes without changing the target ID. */\n measurementKey?: unknown;\n}\n\nexport function SpotlightOverlay({\n options,\n elementIdPrefix = 'slide-element-',\n measurementKey,\n}: SpotlightOverlayProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [rect, setRect] = useState<SpotlightRect | null>(null);\n\n const spotlightElementId = options?.elementId;\n\n const measure = useCallback(() => {\n if (!spotlightElementId || !containerRef.current) {\n setRect(null);\n return;\n }\n\n const domElement = document.getElementById(`${elementIdPrefix}${spotlightElementId}`);\n if (!domElement) {\n setRect(null);\n return;\n }\n\n const contentEl = domElement.querySelector('.element-content');\n const targetEl = contentEl ?? domElement;\n\n const containerRect = containerRef.current.getBoundingClientRect();\n const targetRect = targetEl.getBoundingClientRect();\n\n if (containerRect.width === 0 || containerRect.height === 0) {\n setRect(null);\n return;\n }\n\n setRect({\n x: ((targetRect.left - containerRect.left) / containerRect.width) * 100,\n y: ((targetRect.top - containerRect.top) / containerRect.height) * 100,\n w: (targetRect.width / containerRect.width) * 100,\n h: (targetRect.height / containerRect.height) * 100,\n });\n }, [spotlightElementId, elementIdPrefix]);\n\n useLayoutEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect -- DOM measurement requires effect\n measure();\n\n const container = containerRef.current;\n if (!container || !spotlightElementId) return;\n\n const root = document.getElementById(`${elementIdPrefix}${spotlightElementId}`);\n const target = root?.querySelector('.element-content') ?? root;\n if (!target) return;\n\n const observer = new ResizeObserver(measure);\n observer.observe(container);\n observer.observe(target);\n\n const media = target.querySelectorAll('img, video');\n media.forEach((element) => {\n element.addEventListener('load', measure);\n element.addEventListener('loadedmetadata', measure);\n });\n\n return () => {\n observer.disconnect();\n media.forEach((element) => {\n element.removeEventListener('load', measure);\n element.removeEventListener('loadedmetadata', measure);\n });\n };\n }, [measure, measurementKey, spotlightElementId, elementIdPrefix]);\n\n const active = !!spotlightElementId && !!rect;\n const dimness = options?.dimness ?? 0.7;\n\n return (\n <div\n ref={containerRef}\n style={{\n position: 'absolute',\n inset: 0,\n zIndex: 100,\n pointerEvents: 'none',\n overflow: 'hidden',\n }}\n >\n <AnimatePresence mode=\"wait\">\n {active && rect && (\n <motion.div\n key={`spotlight-${spotlightElementId}`}\n initial={{ opacity: 0 }}\n animate={{ opacity: 1 }}\n exit={{ opacity: 0 }}\n style={{ position: 'absolute', inset: 0 }}\n >\n <svg\n width=\"100%\"\n height=\"100%\"\n viewBox=\"0 0 100 100\"\n preserveAspectRatio=\"none\"\n style={{ position: 'absolute', inset: 0 }}\n >\n <defs>\n <mask id={`mask-${spotlightElementId}`}>\n <rect x=\"0\" y=\"0\" width=\"100\" height=\"100\" fill=\"white\" />\n <motion.rect\n fill=\"black\"\n initial={{\n x: rect.x - 8,\n y: rect.y - 8,\n width: rect.w + 16,\n height: rect.h + 16,\n rx: 4,\n }}\n animate={{\n x: rect.x - 0.4,\n y: rect.y - 0.6,\n width: rect.w + 0.8,\n height: rect.h + 1.2,\n rx: 1,\n }}\n transition={{ duration: 0.6, ease: [0.16, 1, 0.3, 1] }}\n />\n </mask>\n </defs>\n\n <rect\n width=\"100\"\n height=\"100\"\n fill={`rgba(0,0,0,${dimness})`}\n mask={`url(#mask-${spotlightElementId})`}\n />\n\n <motion.rect\n initial={{\n x: rect.x - 4,\n y: rect.y - 4,\n width: rect.w + 8,\n height: rect.h + 8,\n opacity: 0,\n rx: 2,\n }}\n animate={{\n x: rect.x - 0.4,\n y: rect.y - 0.6,\n width: rect.w + 0.8,\n height: rect.h + 1.2,\n opacity: 1,\n rx: 1,\n }}\n fill=\"none\"\n stroke=\"rgba(255,255,255,0.7)\"\n strokeWidth=\"1.2\"\n style={{ vectorEffect: 'non-scaling-stroke' } as React.CSSProperties}\n transition={{ duration: 0.5, delay: 0.05, ease: [0.16, 1, 0.3, 1] }}\n />\n </svg>\n </motion.div>\n )}\n </AnimatePresence>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;AAqBM;AAKJ;;AAGA;AAEA;;;;;AAME;;;;;;AAOA;;AAGA;AAEA;;;;AAKA;AACE;AACA;;;AAGD;AACH;;;AAIE;AAEA;AACA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAGA;AACE;AACA;AACF;AAEA;;AAEE;AACE;AACA;AACF;AACF;;;AAIF;AAEA;AAIM;AACA;AACA;AACA;AACA;;AAyBc;AACA;AACA;AACA;AACA;AACD;AAEC;AACA;AACA;AACA;AACA;;AAgBJ;AACA;AACA;AACA;AACA;AACA;AACD;AAEC;AACA;AACA;AACA;AACA;AACA;;AAclB;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { motion } from 'motion/react';
|
|
4
|
+
|
|
5
|
+
function ZoomWrapper({ children, zoom, geometry }) {
|
|
6
|
+
if (!zoom || !geometry) {
|
|
7
|
+
return jsx(Fragment, { children: children });
|
|
8
|
+
}
|
|
9
|
+
const { scale } = zoom;
|
|
10
|
+
const { centerX, centerY } = geometry;
|
|
11
|
+
return (jsx(motion.div, { initial: { scale: 1 }, animate: { scale }, exit: { scale: 1 }, transition: { type: 'spring', stiffness: 200, damping: 25 }, style: {
|
|
12
|
+
width: '100%',
|
|
13
|
+
height: '100%',
|
|
14
|
+
transformOrigin: `${centerX}% ${centerY}%`,
|
|
15
|
+
}, children: children }));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { ZoomWrapper };
|
|
19
|
+
//# sourceMappingURL=ZoomWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoomWrapper.js","sources":["../../src/effects/ZoomWrapper.tsx"],"sourcesContent":["'use client';\n\nimport { motion } from 'motion/react';\nimport type { ReactNode } from 'react';\nimport type { PercentageGeometry } from '../utils/geometry';\nimport type { ZoomEffectOptions } from '../types/effects';\n\nexport interface ZoomWrapperProps {\n children: ReactNode;\n zoom?: ZoomEffectOptions;\n geometry: PercentageGeometry | null;\n}\n\nexport function ZoomWrapper({ children, zoom, geometry }: ZoomWrapperProps) {\n if (!zoom || !geometry) {\n return <>{children}</>;\n }\n\n const { scale } = zoom;\n const { centerX, centerY } = geometry;\n\n return (\n <motion.div\n initial={{ scale: 1 }}\n animate={{ scale }}\n exit={{ scale: 1 }}\n transition={{ type: 'spring', stiffness: 200, damping: 25 }}\n style={{\n width: '100%',\n height: '100%',\n transformOrigin: `${centerX}% ${centerY}%`,\n }}\n >\n {children}\n </motion.div>\n );\n}\n"],"names":[],"mappings":";;;;AAaM;AACJ;;;AAIA;AACA;;AASM;AACA;AACA;;AAMR;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { ElementOutline } from '../shared/ElementOutline.js';
|
|
4
|
+
import { Chart } from './Chart.js';
|
|
5
|
+
|
|
6
|
+
function BaseChartElement({ elementInfo, target }) {
|
|
7
|
+
return (jsx("div", { className: "base-element-chart", style: {
|
|
8
|
+
position: 'absolute',
|
|
9
|
+
top: `${elementInfo.top}px`,
|
|
10
|
+
left: `${elementInfo.left}px`,
|
|
11
|
+
width: `${elementInfo.width}px`,
|
|
12
|
+
height: `${elementInfo.height}px`,
|
|
13
|
+
pointerEvents: target === 'thumbnail' ? 'none' : undefined,
|
|
14
|
+
}, children: jsx("div", { className: "rotate-wrapper", style: {
|
|
15
|
+
width: '100%',
|
|
16
|
+
height: '100%',
|
|
17
|
+
transform: `rotate(${elementInfo.rotate}deg)`,
|
|
18
|
+
}, children: jsxs("div", { className: "element-content", style: { width: '100%', height: '100%', backgroundColor: elementInfo.fill }, children: [jsx(ElementOutline, { width: elementInfo.width, height: elementInfo.height, outline: elementInfo.outline }), jsx(Chart, { width: elementInfo.width, height: elementInfo.height, type: elementInfo.chartType, data: elementInfo.data, themeColors: elementInfo.themeColors, textColor: elementInfo.textColor, lineColor: elementInfo.lineColor, options: elementInfo.options })] }) }) }));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { BaseChartElement };
|
|
22
|
+
//# sourceMappingURL=BaseChartElement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseChartElement.js","sources":["../../../src/elements/chart/BaseChartElement.tsx"],"sourcesContent":["'use client';\n\nimport type { PPTChartElement } from '@openmaic/dsl';\nimport { ElementOutline } from '../shared/ElementOutline';\nimport { Chart } from './Chart';\n\nexport interface BaseChartElementProps {\n elementInfo: PPTChartElement;\n target?: string;\n}\n\nexport function BaseChartElement({ elementInfo, target }: BaseChartElementProps) {\n return (\n <div\n className=\"base-element-chart\"\n style={{\n position: 'absolute',\n top: `${elementInfo.top}px`,\n left: `${elementInfo.left}px`,\n width: `${elementInfo.width}px`,\n height: `${elementInfo.height}px`,\n pointerEvents: target === 'thumbnail' ? 'none' : undefined,\n }}\n >\n <div\n className=\"rotate-wrapper\"\n style={{\n width: '100%',\n height: '100%',\n transform: `rotate(${elementInfo.rotate}deg)`,\n }}\n >\n <div\n className=\"element-content\"\n style={{ width: '100%', height: '100%', backgroundColor: elementInfo.fill }}\n >\n <ElementOutline\n width={elementInfo.width}\n height={elementInfo.height}\n outline={elementInfo.outline}\n />\n <Chart\n width={elementInfo.width}\n height={elementInfo.height}\n type={elementInfo.chartType}\n data={elementInfo.data}\n themeColors={elementInfo.themeColors}\n textColor={elementInfo.textColor}\n lineColor={elementInfo.lineColor}\n options={elementInfo.options}\n />\n </div>\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;AAYE;AAIM;AACA;AACA;AACA;AACA;;AAED;AAKG;AACA;AACA;;AA0BV;;"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useRef, useMemo, useEffect } from 'react';
|
|
4
|
+
import tinycolor from 'tinycolor2';
|
|
5
|
+
import { getChartOption } from './chartOption.js';
|
|
6
|
+
import * as echarts from 'echarts/core';
|
|
7
|
+
import { BarChart, LineChart, PieChart, ScatterChart, RadarChart } from 'echarts/charts';
|
|
8
|
+
import { LegendComponent } from 'echarts/components';
|
|
9
|
+
import { SVGRenderer } from 'echarts/renderers';
|
|
10
|
+
|
|
11
|
+
echarts.use([
|
|
12
|
+
BarChart,
|
|
13
|
+
LineChart,
|
|
14
|
+
PieChart,
|
|
15
|
+
ScatterChart,
|
|
16
|
+
RadarChart,
|
|
17
|
+
LegendComponent,
|
|
18
|
+
SVGRenderer,
|
|
19
|
+
]);
|
|
20
|
+
function Chart({ width: _width, height: _height, type, data, themeColors: rawThemeColors, textColor, lineColor, options, }) {
|
|
21
|
+
const chartRef = useRef(null);
|
|
22
|
+
const chartInstance = useRef(null);
|
|
23
|
+
const themeColors = useMemo(() => {
|
|
24
|
+
let colors = [];
|
|
25
|
+
if (rawThemeColors.length >= 10) {
|
|
26
|
+
colors = rawThemeColors;
|
|
27
|
+
}
|
|
28
|
+
else if (rawThemeColors.length === 1) {
|
|
29
|
+
colors = tinycolor(rawThemeColors[0])
|
|
30
|
+
.analogous(10)
|
|
31
|
+
.map((color) => color.toRgbString());
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const len = rawThemeColors.length;
|
|
35
|
+
const supplement = tinycolor(rawThemeColors[len - 1])
|
|
36
|
+
.analogous(10 + 1 - len)
|
|
37
|
+
.map((color) => color.toRgbString());
|
|
38
|
+
colors = [...rawThemeColors.slice(0, len - 1), ...supplement];
|
|
39
|
+
}
|
|
40
|
+
return colors;
|
|
41
|
+
}, [rawThemeColors]);
|
|
42
|
+
const updateOption = useMemo(() => {
|
|
43
|
+
return () => {
|
|
44
|
+
if (!chartInstance.current)
|
|
45
|
+
return;
|
|
46
|
+
const option = getChartOption({
|
|
47
|
+
type,
|
|
48
|
+
data,
|
|
49
|
+
themeColors,
|
|
50
|
+
textColor,
|
|
51
|
+
lineColor,
|
|
52
|
+
lineSmooth: options?.lineSmooth || false,
|
|
53
|
+
stack: options?.stack || false,
|
|
54
|
+
});
|
|
55
|
+
if (option) {
|
|
56
|
+
chartInstance.current.setOption(option, true);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}, [type, data, themeColors, textColor, lineColor, options]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!chartRef.current)
|
|
62
|
+
return;
|
|
63
|
+
chartInstance.current = echarts.init(chartRef.current, null, { renderer: 'svg' });
|
|
64
|
+
updateOption();
|
|
65
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
66
|
+
chartInstance.current?.resize();
|
|
67
|
+
});
|
|
68
|
+
resizeObserver.observe(chartRef.current);
|
|
69
|
+
return () => {
|
|
70
|
+
resizeObserver.disconnect();
|
|
71
|
+
chartInstance.current?.dispose();
|
|
72
|
+
chartInstance.current = null;
|
|
73
|
+
};
|
|
74
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- Init-only effect
|
|
75
|
+
}, []);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
updateOption();
|
|
78
|
+
}, [updateOption]);
|
|
79
|
+
return jsx("div", { ref: chartRef, className: "chart", style: { width: '100%', height: '100%' } });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { Chart };
|
|
83
|
+
//# sourceMappingURL=Chart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Chart.js","sources":["../../../src/elements/chart/Chart.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef, useMemo } from 'react';\nimport tinycolor from 'tinycolor2';\nimport type { ChartData, ChartOptions, ChartType } from '@openmaic/dsl';\nimport { getChartOption } from './chartOption';\n\nimport * as echarts from 'echarts/core';\nimport { BarChart, LineChart, PieChart, ScatterChart, RadarChart } from 'echarts/charts';\nimport { LegendComponent } from 'echarts/components';\nimport { SVGRenderer } from 'echarts/renderers';\n\necharts.use([\n BarChart,\n LineChart,\n PieChart,\n ScatterChart,\n RadarChart,\n LegendComponent,\n SVGRenderer,\n]);\n\ninterface ChartProps {\n width: number;\n height: number;\n type: ChartType;\n data: ChartData;\n themeColors: string[];\n textColor?: string;\n lineColor?: string;\n options?: ChartOptions;\n}\n\nexport function Chart({\n width: _width,\n height: _height,\n type,\n data,\n themeColors: rawThemeColors,\n textColor,\n lineColor,\n options,\n}: ChartProps) {\n const chartRef = useRef<HTMLDivElement>(null);\n const chartInstance = useRef<echarts.ECharts | null>(null);\n\n const themeColors = useMemo(() => {\n let colors: string[] = [];\n if (rawThemeColors.length >= 10) {\n colors = rawThemeColors;\n } else if (rawThemeColors.length === 1) {\n colors = tinycolor(rawThemeColors[0])\n .analogous(10)\n .map((color) => color.toRgbString());\n } else {\n const len = rawThemeColors.length;\n const supplement = tinycolor(rawThemeColors[len - 1])\n .analogous(10 + 1 - len)\n .map((color) => color.toRgbString());\n colors = [...rawThemeColors.slice(0, len - 1), ...supplement];\n }\n return colors;\n }, [rawThemeColors]);\n\n const updateOption = useMemo(() => {\n return () => {\n if (!chartInstance.current) return;\n\n const option = getChartOption({\n type,\n data,\n themeColors,\n textColor,\n lineColor,\n lineSmooth: options?.lineSmooth || false,\n stack: options?.stack || false,\n });\n\n if (option) {\n chartInstance.current.setOption(option, true);\n }\n };\n }, [type, data, themeColors, textColor, lineColor, options]);\n\n useEffect(() => {\n if (!chartRef.current) return;\n\n chartInstance.current = echarts.init(chartRef.current, null, { renderer: 'svg' });\n updateOption();\n\n const resizeObserver = new ResizeObserver(() => {\n chartInstance.current?.resize();\n });\n resizeObserver.observe(chartRef.current);\n\n return () => {\n resizeObserver.disconnect();\n chartInstance.current?.dispose();\n chartInstance.current = null;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- Init-only effect\n }, []);\n\n useEffect(() => {\n updateOption();\n }, [updateOption]);\n\n return <div ref={chartRef} className=\"chart\" style={{ width: '100%', height: '100%' }} />;\n}\n"],"names":[],"mappings":";;;;;;;;;;AAYA;;;;;;;;AAQC;AAaK;AAUJ;AACA;AAEA;;AAEE;;;AAEO;AACL;;;;;AAIA;;AAEG;;AAEH;;AAEF;AACF;AAEA;AACE;;;;;;;;;AASI;AACA;AACD;;;;AAKH;AACF;;;;AAKE;AACA;AAEA;AACE;AACF;AACA;AAEA;;AAEE;AACA;AACF;;;;AAKA;AACF;;AAGF;;"}
|