import { useEffect } from "react"; import { DropHalf } from "@phosphor-icons/react"; import { commandIds } from "@commands/ids"; import type { ImageDocument } from "@core/document"; import type { AppStore } from "@editor/store"; import type { ChromaKeySettings } from "@editor/tools"; import type { SelectionState } from "@editor/state"; import { applyChromaKeyMask, previewChromaKey, resolveChromaKeyTarget } from "@operations/masks/chromaKey"; import { BottomControlColorPicker } from "./ColorPicker"; import { BottomControlDivider } from "./Divider"; import { BottomControlSlider } from "./Slider"; import { bottomControlFieldClass, bottomControlIconSlotClass, bottomControlLabelClass, bottomControlMenuClass } from "./styles"; export type ChromaKeyControlsProps = { document: ImageDocument; selection: SelectionState; settings: ChromaKeySettings; dispatch: AppStore["dispatch"]; }; export function ChromaKeyControls({ document, selection, settings, dispatch }: ChromaKeyControlsProps) { const target = resolveChromaKeyTarget(document, selection); useEffect(() => { return () => { dispatch(commandIds.toolSetBrushStrokePreview, undefined); }; }, [dispatch]); useEffect(() => { let cancelled = false; if (!target) { dispatch(commandIds.toolSetBrushStrokePreview, undefined); return; } void previewChromaKey(target.asset.source, target.asset.intrinsicSize.w, target.asset.intrinsicSize.h, settings).then((source) => { if (cancelled) return; dispatch(commandIds.toolSetBrushStrokePreview, { layerId: target.layer.id, assetId: target.asset.id, source }); }); return () => { cancelled = true; }; }, [dispatch, settings.choke, settings.color, settings.despeckle, settings.feather, settings.softness, settings.spill, settings.tolerance, target?.asset.id, target?.asset.source, target?.asset.intrinsicSize.w, target?.asset.intrinsicSize.h, target?.layer.id]); return (
); }