-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add webcam mask shape support #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import { | |
| type StyledRenderRect, | ||
| type WebcamLayoutPreset, | ||
| } from "@/lib/compositeLayout"; | ||
| import { getCssClipPath } from "@/lib/webcamMaskShapes"; | ||
| import { | ||
| type AspectRatio, | ||
| formatAspectRatioForCSS, | ||
|
|
@@ -63,6 +64,7 @@ interface VideoPlaybackProps { | |
| videoPath: string; | ||
| webcamVideoPath?: string; | ||
| webcamLayoutPreset: WebcamLayoutPreset; | ||
| webcamMaskShape?: import("./types").WebcamMaskShape; | ||
| webcamPosition?: { cx: number; cy: number } | null; | ||
| onWebcamPositionChange?: (position: { cx: number; cy: number }) => void; | ||
| onWebcamPositionDragEnd?: () => void; | ||
|
|
@@ -111,6 +113,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>( | |
| videoPath, | ||
| webcamVideoPath, | ||
| webcamLayoutPreset, | ||
| webcamMaskShape, | ||
| webcamPosition, | ||
| onWebcamPositionChange, | ||
| onWebcamPositionDragEnd, | ||
|
|
@@ -272,6 +275,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>( | |
| webcamDimensions, | ||
| webcamLayoutPreset, | ||
| webcamPosition, | ||
| webcamMaskShape, | ||
| }); | ||
|
|
||
| if (result) { | ||
|
|
@@ -302,6 +306,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>( | |
| webcamDimensions, | ||
| webcamLayoutPreset, | ||
| webcamPosition, | ||
| webcamMaskShape, | ||
| ]); | ||
|
|
||
| useEffect(() => { | ||
|
|
@@ -1154,31 +1159,47 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>( | |
| : "none", | ||
| }} | ||
| /> | ||
| {webcamVideoPath && ( | ||
| <video | ||
| ref={webcamVideoRef} | ||
| src={webcamVideoPath} | ||
| className={`absolute object-cover ${webcamLayoutPreset === "picture-in-picture" ? "cursor-grab active:cursor-grabbing" : "pointer-events-none"}`} | ||
| style={{ | ||
| left: webcamLayout?.x ?? 0, | ||
| top: webcamLayout?.y ?? 0, | ||
| width: webcamLayout?.width ?? 0, | ||
| height: webcamLayout?.height ?? 0, | ||
| borderRadius: webcamLayout?.borderRadius ?? 0, | ||
| boxShadow: webcamCssBoxShadow, | ||
| zIndex: 20, | ||
| opacity: webcamLayout ? 1 : 0, | ||
| backgroundColor: "#000", | ||
| }} | ||
| onPointerDown={handleWebcamPointerDown} | ||
| onPointerMove={handleWebcamPointerMove} | ||
| onPointerUp={handleWebcamPointerUp} | ||
| onPointerLeave={handleWebcamPointerUp} | ||
| muted | ||
| preload="metadata" | ||
| playsInline | ||
| /> | ||
| )} | ||
| {webcamVideoPath && | ||
| (() => { | ||
| const clipPath = getCssClipPath(webcamLayout?.maskShape ?? "rectangle"); | ||
| const useClipPath = !!clipPath; | ||
| return ( | ||
| <div | ||
| className="absolute" | ||
| style={{ | ||
|
Comment on lines
+1167
to
+1169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new wrapper Useful? React with 👍 / 👎. |
||
| left: webcamLayout?.x ?? 0, | ||
| top: webcamLayout?.y ?? 0, | ||
| width: webcamLayout?.width ?? 0, | ||
| height: webcamLayout?.height ?? 0, | ||
| zIndex: 20, | ||
| opacity: webcamLayout ? 1 : 0, | ||
| filter: | ||
| useClipPath && webcamCssBoxShadow !== "none" | ||
| ? `drop-shadow(${webcamCssBoxShadow})` | ||
| : undefined, | ||
| }} | ||
| > | ||
| <video | ||
| ref={webcamVideoRef} | ||
| src={webcamVideoPath} | ||
| className={`w-full h-full object-cover ${webcamLayoutPreset === "picture-in-picture" ? "cursor-grab active:cursor-grabbing" : "pointer-events-none"}`} | ||
| style={{ | ||
| borderRadius: useClipPath ? 0 : (webcamLayout?.borderRadius ?? 0), | ||
| clipPath: clipPath ?? undefined, | ||
| boxShadow: useClipPath ? "none" : webcamCssBoxShadow, | ||
| backgroundColor: "#000", | ||
| }} | ||
| onPointerDown={handleWebcamPointerDown} | ||
| onPointerMove={handleWebcamPointerMove} | ||
| onPointerUp={handleWebcamPointerUp} | ||
| onPointerLeave={handleWebcamPointerUp} | ||
| muted | ||
| preload="metadata" | ||
| playsInline | ||
| /> | ||
| </div> | ||
| ); | ||
| })()} | ||
| {/* Only render overlay after PIXI and video are fully initialized */} | ||
| {pixiReady && videoReady && ( | ||
| <div | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Localize shape labels and expose selected state to assistive tech.
The option labels are hardcoded in English, so they won’t translate in
es/zh-CN. Also, this single-select button group should expose pressed state (aria-pressed) for better accessibility.💡 Suggested patch
📝 Committable suggestion
🤖 Prompt for AI Agents