feat: add generate tools

This commit is contained in:
2026-09-07 10:16:12 +05:00
parent 6be9d10c42
commit b3d460a951
+95
View File
@@ -7,11 +7,13 @@ import {
analogousSet, analogousSet,
complementarySet, complementarySet,
hexToRgb, hexToRgb,
mixColors,
monochromaticSet, monochromaticSet,
renderBlend, renderBlend,
renderSwatches, renderSwatches,
renderWheel, renderWheel,
shadeSet, shadeSet,
sortPalette,
stepColors, stepColors,
tetradicSet, tetradicSet,
triadicSet, triadicSet,
@@ -642,6 +644,97 @@ const shadesTool: ToolEntry<ShadesParams> = {
renderSwatches(shadeSet(p.baseColor, p.count, p.depth), p.width, p.layout), renderSwatches(shadeSet(p.baseColor, p.count, p.depth), p.width, p.layout),
}; };
interface MixColorsParams {
colors: string[];
width: number;
}
export const mixColorsSchema = toolSchema<MixColorsParams>(
{
colors: field.colors({ default: ["#ff0000", "#00ff00", "#0000ff"] }),
width: field.slider({ min: 128, max: 1024, step: 16, default: 512 }),
},
{
layout: {
groups: [
{ title: "Colors", fields: ["colors"] },
{ title: "Output", fields: ["width"] },
],
},
},
);
const mixColorsTool: ToolEntry<MixColorsParams> = {
id: "mix-colors-png",
title: "Mix Colors PNG",
description:
"Averages the selected colors into one swatch. Colors become one uniform fill.",
category: "generate",
schema: mixColorsSchema,
generate: (p) => renderSwatches([mixColors(p.colors)], p.width, "strip"),
};
interface SortColorsParams {
colors: string[];
order: "hue" | "luma" | "sat";
width: number;
layout: "strip" | "grid";
}
export const sortColorsSchema = toolSchema<SortColorsParams>(
{
colors: field.colors({
default: [
"#ff0000",
"#ff8800",
"#ffff00",
"#00cc44",
"#0066ff",
"#8800ff",
],
}),
order: field.select({
default: "hue",
options: [
{ value: "hue", label: "Hue" },
{ value: "luma", label: "Brightness" },
{ value: "sat", label: "Saturation" },
],
}),
width: field.slider({ min: 128, max: 1024, step: 16, default: 512 }),
layout: field.select({
default: "grid",
options: [
{ value: "grid", label: "Grid" },
{ value: "strip", label: "Strip" },
],
}),
},
{
layout: {
groups: [
{ title: "Colors", fields: ["colors"] },
{
title: "Output",
cols: 2,
fields: ["order", "width", "layout"],
},
],
},
},
);
const sortColorsTool: ToolEntry<SortColorsParams> = {
id: "sort-colors-png",
title: "Sort Colors PNG",
description:
"Renders the chosen colors as swatches sorted by hue, brightness or saturation.",
category: "generate",
schema: sortColorsSchema,
generate: (p) =>
renderSwatches(sortPalette(p.colors, p.order), p.width, p.layout),
};
interface TextToPngParams { interface TextToPngParams {
text: string; text: string;
style: FontStyle; style: FontStyle;
@@ -716,5 +809,7 @@ export const generateEntries = [
analogousTool, analogousTool,
monochromaticTool, monochromaticTool,
shadesTool, shadesTool,
mixColorsTool,
sortColorsTool,
textToPng, textToPng,
]; ];