import * as React from "react"; import { AnchorGrid, Checkbox, CodeTextarea, RangeInput, RangeSlider, Segmented, Select, Slider, Switch, TabsControl, TextInput, Vector, type ControlChangeMeta, } from "@repo/ui"; import { toolcraftCanvasAspectRatioPresets } from "../../../schema/canvas-aspect-ratio-presets"; import type { ToolcraftControlSchema } from "../../../schema/types"; import { getControlMarkerCount, shouldCommitTextControlOnBlur, } from "../layout/controls-panel-layout"; import { asBoolean, asCanvasAspectRatioValue, asNumber, asNumberArray, asRangeInputValue, asString, asVectorPadCoordinateMode, asVectorPadVariant, asVectorValue, parseCanvasAspectRatioOption, type CanvasAspectRatioValue, } from "../values/controls-panel-values"; const canvasAspectRatioOptions = [ ...toolcraftCanvasAspectRatioPresets.map((preset) => ({ label: preset.value, value: preset.value, })), { label: "Custom", value: "custom" }, ] as const; export type BasicControlCommit = ( nextValue: unknown, meta?: ControlChangeMeta, ) => void; export type BasicControlKeyframeWrap = (args: { children: React.ReactNode; control: ToolcraftControlSchema; disableAction: boolean; name: string; providerKey: string; value: unknown; }) => React.ReactNode; export type BasicControlRenderArgs = { commit: BasicControlCommit; control: ToolcraftControlSchema; id: string; name: string; usesHeaderKeyframeAction: boolean; value: unknown; vectorPadShape: "compact" | "square"; withKeyframeLabelAction: BasicControlKeyframeWrap; }; function CanvasAspectRatioControl({ defaultValue, name, onValueChange, value, }: { defaultValue: unknown; name: string; onValueChange?: ( value: CanvasAspectRatioValue, meta?: ControlChangeMeta, ) => void; value: unknown; }): React.JSX.Element { const ratio = asCanvasAspectRatioValue(value, defaultValue); const selectedValue = ratio.mode === "custom" ? "custom" : ratio.value; function commitRatio( nextRatio: CanvasAspectRatioValue, meta?: ControlChangeMeta, ): void { onValueChange?.(nextRatio, meta); } function updatePreset(nextValue: string): void { if (nextValue === "custom") { commitRatio({ height: ratio.height, mode: "custom", value: `${ratio.width}:${ratio.height}`, width: ratio.width, }); return; } const nextRatio = parseCanvasAspectRatioOption(nextValue); if (nextRatio) { commitRatio(nextRatio); } } return (