Skip to content

Free open-source image editor for the browser

552 B
Raw Blame
import { type EditorDocument, editLayer, type Fill } from "@/core/document";
import { change, parse } from "@/lib/parse";
import { fillSchema } from "./model";

const fillChange = change(fillSchema);

export function setFill(
  document: EditorDocument,
  fill: Partial<Fill>,
  id: string,
) {
  const values = parse(fillChange, fill, "Invalid fill setting");
  editLayer(document, id, (layer) => {
    if (layer.kind !== "fill") {
      throw Error("Select a color layer.");
    }
    return { ...layer, fill: { ...layer.fill, ...values } };
  });
}