Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Refine reference presets

Bittieb53c849f67f
diff --git a/src/components/workspace/ReferencesView.test.tsx b/src/components/workspace/ReferencesView.test.tsx
index b9fc3c5..7e1c5c1 100644
--- a/src/components/workspace/ReferencesView.test.tsx
+++ b/src/components/workspace/ReferencesView.test.tsx
@@ -90,9 +90,18 @@ describe("Reference type presets", () => {
const groups = within(dialog).getByRole("group", { name: "Location subcategories" });
fireEvent.click(within(groups).getByRole("button", { name: "Sci-fi" }));
fireEvent.change(within(dialog).getByRole("textbox", { name: "Search reference options" }), { target: { value: "lunar" } });
- expect(within(dialog).getByRole("button", { name: /Lunar research base/ })).toBeInTheDocument();
+ expect(within(dialog).getByRole("button", { name: /Lunar base/ })).toBeInTheDocument();
expect(within(dialog).queryByRole("button", { name: /Victorian manor/ })).not.toBeInTheDocument();
- fireEvent.click(within(dialog).getByRole("button", { name: /Lunar research base/ }));
+ fireEvent.click(within(dialog).getByRole("button", { name: /Lunar base/ }));
+ fireEvent.click(within(within(dialog).getByRole("group", { name: "Time of day" })).getByRole("button", { name: "Night" }));
+ fireEvent.click(within(within(dialog).getByRole("group", { name: "Season" })).getByRole("button", { name: "Winter" }));
+ expect(within(dialog).getByText("Lunar base, at night, in winter.")).toBeInTheDocument();
+ fireEvent.click(within(dialog).getByRole("button", { name: "Use location" }));
+
+ expect(state.latest().references[0]).toMatchObject({
+ intendedUse: ["location"],
+ description: "Lunar base, at night, in winter.",
+ });
fireEvent.click(screen.getByRole("button", { name: "Location" }));
const reopened = screen.getByRole("dialog", { name: "Choose a reference type" });
@@ -100,6 +109,6 @@ describe("Reference type presets", () => {
fireEvent.click(within(reopened).getByRole("button", { name: "Use Custom" }));
expect(state.latest().references[0].intendedUse).toEqual([]);
- expect(screen.getByRole("textbox", { name: "Prompt" })).toHaveValue("White lunar base under harsh sunlight.");
+ expect(screen.getByRole("textbox", { name: "Prompt" })).toHaveValue("Lunar base, at night, in winter.");
});
});
diff --git a/src/components/workspace/ReferencesView.tsx b/src/components/workspace/ReferencesView.tsx
index 03d7819..6608506 100644
--- a/src/components/workspace/ReferencesView.tsx
+++ b/src/components/workspace/ReferencesView.tsx
@@ -3,14 +3,18 @@ import { invoke } from "@tauri-apps/api/core";
import { useMemo, useState } from "react";
import { isReferenceDescribed, type ProjectConfig, type ProjectReference } from "../../lib/project";
import {
+ composeLocationPrompt,
+ locationSelectionFromPrompt,
REFERENCE_PRESETS,
REFERENCE_TYPES,
referenceType,
referenceTypeLabel,
selectedReferencePreset,
+ type LocationSettings,
type ReferencePreset,
type ReferenceType,
} from "../../lib/reference-presets";
+import { LOCATION_SETTING_GROUPS } from "../../lib/expanded-reference-options";
import { isTauri } from "../../lib/persistence";
import { ReferenceImage } from "./ReferenceImage";
@@ -30,6 +34,8 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
const [pickerType, setPickerType] = useState<ReferenceType>("custom");
const [pickerSubcategory, setPickerSubcategory] = useState("all");
const [presetSearch, setPresetSearch] = useState("");
+ const [locationPresetId, setLocationPresetId] = useState<string | null>(null);
+ const [locationSettings, setLocationSettings] = useState<LocationSettings>({});
const selected = config.references.find((ref) => ref.id === selectedId);
const jobs = useMemo(() => config.generationJobs.filter((job) => job.referenceIds.includes(selectedId ?? "")), [config.generationJobs, selectedId]);
const update = (id: string, patch: Partial<ProjectReference>) => onChange({ ...config, references: config.references.map((ref) => ref.id === id ? { ...ref, ...patch } : ref) });
@@ -81,6 +87,9 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
setPickerType(referenceType(selected));
setPickerSubcategory("all");
setPresetSearch("");
+ const location = locationSelectionFromPrompt(selected.description);
+ setLocationPresetId(location?.preset.id ?? null);
+ setLocationSettings(location?.settings ?? {});
setPresetDialog(true);
};
const chooseCustom = () => {
@@ -90,9 +99,22 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
};
const choosePreset = (preset: ReferencePreset) => {
if (!selected) return;
+ if (preset.type === "location") {
+ setLocationPresetId(preset.id);
+ setLocationSettings({});
+ return;
+ }
update(selected.id, { intendedUse: [preset.type], description: preset.prompt, content: preset.prompt });
setPresetDialog(false);
};
+ const chooseLocation = () => {
+ if (!selected) return;
+ const preset = REFERENCE_PRESETS.find((candidate) => candidate.type === "location" && candidate.id === locationPresetId);
+ if (!preset) return;
+ const prompt = composeLocationPrompt(preset, locationSettings);
+ update(selected.id, { intendedUse: ["location"], description: prompt, content: prompt });
+ setPresetDialog(false);
+ };
const visiblePresets = REFERENCE_PRESETS.filter((preset) => {
if (preset.type !== pickerType) return false;
if (pickerSubcategory !== "all" && preset.subcategory !== pickerSubcategory) return false;
@@ -100,6 +122,9 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
return !query || `${preset.name} ${preset.prompt} ${preset.subcategory} ${preset.searchTerms ?? ""}`.toLocaleLowerCase().includes(query);
});
const subcategories = [...new Set(REFERENCE_PRESETS.filter((preset) => preset.type === pickerType).map((preset) => preset.subcategory))];
+ const chosenLocationPreset = pickerType === "location"
+ ? REFERENCE_PRESETS.find((preset) => preset.type === "location" && preset.id === locationPresetId)
+ : undefined;
return <div className="references-view">
<main className="references-main">
@@ -187,7 +212,7 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
</header>
<div className="reference-preset-dialog__body">
<nav aria-label="Reference types">
- {REFERENCE_TYPES.map((type) => <button key={type.id} className={pickerType === type.id ? "active" : ""} aria-pressed={pickerType === type.id} onClick={() => { setPickerType(type.id); setPickerSubcategory("all"); setPresetSearch(""); }}>{type.label}<ChevronRight size={16} /></button>)}
+ {REFERENCE_TYPES.map((type) => <button key={type.id} className={pickerType === type.id ? "active" : ""} aria-pressed={pickerType === type.id} onClick={() => { setPickerType(type.id); setPickerSubcategory("all"); setPresetSearch(""); setLocationPresetId(null); setLocationSettings({}); }}>{type.label}<ChevronRight size={16} /></button>)}
</nav>
<section>
{pickerType === "custom" ? <div className="reference-custom-option">
@@ -201,8 +226,22 @@ export function ReferencesView({ config, folderPath, onChange }: { config: Proje
<button className={pickerSubcategory === "all" ? "active" : ""} aria-pressed={pickerSubcategory === "all"} onClick={() => setPickerSubcategory("all")}>All</button>
{subcategories.map((subcategory) => <button key={subcategory} className={pickerSubcategory === subcategory ? "active" : ""} aria-pressed={pickerSubcategory === subcategory} onClick={() => setPickerSubcategory(subcategory)}>{subcategory}</button>)}
</div>
+ {chosenLocationPreset && <div className="reference-location-settings">
+ <header><span><small>Location</small><b>{chosenLocationPreset.name}</b></span><button className="primary-button" onClick={chooseLocation}>Use location</button></header>
+ <p>Add any combination. Each row is optional.</p>
+ {LOCATION_SETTING_GROUPS.map((group) => <div key={group.id} className="reference-location-settings__group">
+ <b>{group.label}</b>
+ <span role="group" aria-label={group.label}>{group.options.map((option) => <button
+ key={option.id}
+ className={locationSettings[group.id] === option.id ? "active" : ""}
+ aria-pressed={locationSettings[group.id] === option.id}
+ onClick={() => setLocationSettings((current) => ({ ...current, [group.id]: current[group.id] === option.id ? undefined : option.id }))}
+ >{option.label}</button>)}</span>
+ </div>)}
+ <small className="reference-location-settings__preview">{composeLocationPrompt(chosenLocationPreset, locationSettings)}</small>
+ </div>}
<div className="reference-preset-grid">
- {visiblePresets.map((preset) => <button key={preset.id} onClick={() => choosePreset(preset)}>
+ {visiblePresets.map((preset) => <button key={preset.id} className={preset.id === locationPresetId ? "active" : ""} aria-pressed={preset.type === "location" ? preset.id === locationPresetId : undefined} onClick={() => choosePreset(preset)}>
<small>{preset.subcategory}</small><b>{preset.name}</b><span>{preset.prompt}</span>
</button>)}
{visiblePresets.length === 0 && <p>No options match that search.</p>}
diff --git a/src/lib/expanded-reference-options.ts b/src/lib/expanded-reference-options.ts
index 68dff98..9ef735d 100644
--- a/src/lib/expanded-reference-options.ts
+++ b/src/lib/expanded-reference-options.ts
@@ -3,11 +3,6 @@ export interface OptionGroup {
options: readonly string[];
}
-export interface OptionVariant {
- name: string;
- prompt: string;
-}
-
export const PRODUCT_GROUPS: readonly OptionGroup[] = [
{ subcategory: "Technology", options: ["Smartphone", "Laptop", "Tablet", "Smartwatch", "Wireless earbuds", "Camera", "Gaming console", "Desktop computer", "Smart speaker", "VR headset"] },
{ subcategory: "Fashion", options: ["Wristwatch", "Sneaker", "Handbag", "Sunglasses", "Jacket", "Dress", "Backpack", "Boot", "Wallet", "Headphones"] },
@@ -21,33 +16,51 @@ export const PRODUCT_GROUPS: readonly OptionGroup[] = [
{ subcategory: "Packaging", options: ["Shipping box", "Gift box", "Paper pouch", "Glass jar", "Metal tin", "Pump bottle", "Cardboard tube", "Takeaway cup", "Resealable bag", "Display carton"] },
];
-export const PRODUCT_VARIANTS: readonly OptionVariant[] = [
- { name: "Minimal", prompt: "minimal, clean" },
- { name: "Premium", prompt: "premium, refined" },
- { name: "Rugged", prompt: "rugged, durable" },
- { name: "Retro", prompt: "retro-inspired" },
- { name: "Eco", prompt: "sustainable, natural" },
-];
-
export const LOCATION_GROUPS: readonly OptionGroup[] = [
- { subcategory: "Urban", options: ["City alley", "Downtown avenue", "Rooftop", "Subway platform", "Night market", "City square", "Parking garage", "Pedestrian bridge", "Apartment street", "Train station"] },
+ { subcategory: "Urban", options: ["City alley", "Downtown avenue", "Rooftop", "Subway platform", "Street market", "City square", "Parking garage", "Pedestrian bridge", "Apartment street", "Train station"] },
{ subcategory: "Interiors", options: ["Hotel lobby", "Modern kitchen", "Artist studio", "Library", "Corner café", "Penthouse", "Warehouse loft", "Recording studio", "Museum gallery", "Home office"] },
- { subcategory: "Nature", options: ["Pine forest", "Desert canyon", "Alpine lake", "Wildflower meadow", "Waterfall", "Volcanic field", "Bamboo grove", "Glacier valley", "Misty marsh", "Redwood forest"] },
+ { subcategory: "Nature", options: ["Pine forest", "Desert canyon", "Alpine lake", "Wildflower meadow", "Waterfall", "Volcanic field", "Bamboo grove", "Glacier valley", "Marsh", "Redwood forest"] },
{ subcategory: "Historic", options: ["Medieval market", "Victorian manor", "Roman courtyard", "Ancient temple", "Castle hall", "Old observatory", "Monastery", "Colonial street", "Art Deco ballroom", "Renaissance workshop"] },
{ subcategory: "Sci-fi", options: ["Lunar base", "Orbital station", "Mars habitat", "Starship bridge", "Cyberpunk alley", "Alien greenhouse", "Robot factory", "Spaceport", "Cryogenic bay", "Underwater laboratory"] },
{ subcategory: "Fantasy", options: ["Enchanted forest", "Wizard library", "Dragon cave", "Floating city", "Elven palace", "Ancient ruins", "Crystal cavern", "Mountain fortress", "Hidden village", "Royal throne room"] },
- { subcategory: "Coastal", options: ["Tropical beach", "Rocky cove", "Fishing harbor", "Lighthouse cliff", "Boardwalk", "Coral lagoon", "Sea cave", "Marina", "Coastal village", "Storm pier"] },
+ { subcategory: "Coastal", options: ["Tropical beach", "Rocky cove", "Fishing harbor", "Lighthouse cliff", "Boardwalk", "Coral lagoon", "Sea cave", "Marina", "Coastal village", "Pier"] },
{ subcategory: "Rural", options: ["Farmhouse", "Country road", "Vineyard", "Orchard", "Windmill field", "Mountain village", "Rice terrace", "Ranch", "Lavender farm", "Remote cabin"] },
{ subcategory: "Industrial", options: ["Steel mill", "Shipyard", "Power station", "Factory floor", "Cargo terminal", "Oil refinery", "Aircraft hangar", "Mining tunnel", "Data center", "Construction site"] },
{ subcategory: "Public spaces", options: ["Airport terminal", "Concert hall", "University campus", "Sports arena", "Hospital corridor", "Shopping arcade", "Courthouse", "Community pool", "Convention center", "Botanical garden"] },
];
-export const LOCATION_VARIANTS: readonly OptionVariant[] = [
- { name: "At dawn", prompt: "at dawn" },
- { name: "At night", prompt: "at night" },
- { name: "In rain", prompt: "in light rain" },
- { name: "In winter", prompt: "in winter" },
- { name: "Golden hour", prompt: "at golden hour" },
+export interface LocationSettingGroup {
+ id: "time" | "weather" | "season";
+ label: string;
+ options: ReadonlyArray<{ id: string; label: string; prompt: string }>;
+}
+
+/** Optional, independent qualifiers. Keeping them outside the location names
+ * lets one place be reused as, for example, "Coastal village, at night, in
+ * winter" instead of filling the catalog with five near-duplicates. */
+export const LOCATION_SETTING_GROUPS: readonly LocationSettingGroup[] = [
+ { id: "time", label: "Time of day", options: [
+ { id: "dawn", label: "Dawn", prompt: "at dawn" },
+ { id: "morning", label: "Morning", prompt: "in the morning" },
+ { id: "midday", label: "Midday", prompt: "at midday" },
+ { id: "golden-hour", label: "Golden hour", prompt: "at golden hour" },
+ { id: "dusk", label: "Dusk", prompt: "at dusk" },
+ { id: "night", label: "Night", prompt: "at night" },
+ ] },
+ { id: "weather", label: "Weather", options: [
+ { id: "clear", label: "Clear", prompt: "in clear weather" },
+ { id: "overcast", label: "Overcast", prompt: "under overcast skies" },
+ { id: "rain", label: "Rain", prompt: "in rain" },
+ { id: "fog", label: "Fog", prompt: "in fog" },
+ { id: "snow", label: "Snow", prompt: "in snow" },
+ { id: "storm", label: "Storm", prompt: "during a storm" },
+ ] },
+ { id: "season", label: "Season", options: [
+ { id: "spring", label: "Spring", prompt: "in spring" },
+ { id: "summer", label: "Summer", prompt: "in summer" },
+ { id: "autumn", label: "Autumn", prompt: "in autumn" },
+ { id: "winter", label: "Winter", prompt: "in winter" },
+ ] },
];
export const STYLE_GROUPS: readonly OptionGroup[] = [
@@ -62,11 +75,3 @@ export const STYLE_GROUPS: readonly OptionGroup[] = [
{ subcategory: "Commercial", options: ["Luxury editorial", "Clean product ad", "Lifestyle campaign", "Beauty campaign", "Automotive campaign", "Sports campaign", "Food commercial", "Technology launch", "Travel campaign", "Fashion lookbook"] },
{ subcategory: "Digital", options: ["Photoreal 3D", "Low-poly 3D", "Voxel art", "Isometric render", "Holographic render", "Unreal environment", "Procedural texture", "Digital matte painting", "Vector art", "UI motion design"] },
];
-
-export const STYLE_VARIANTS: readonly OptionVariant[] = [
- { name: "Moody", prompt: "moody" },
- { name: "Bright", prompt: "bright" },
- { name: "Minimal", prompt: "minimal" },
- { name: "Textured", prompt: "textured" },
- { name: "High contrast", prompt: "high-contrast" },
-];
diff --git a/src/lib/known-characters.ts b/src/lib/known-characters.ts
index c2379f4..585d368 100644
--- a/src/lib/known-characters.ts
+++ b/src/lib/known-characters.ts
@@ -41,6 +41,7 @@ export const KNOWN_CHARACTERS = [
["Anthony DiNozzo","Michael Weatherly","NCIS"],
["Anthony Hopkins","Anthony Hopkins","Real Person / Celebrity"],
["Anthony Mackie","Anthony Mackie","Real Person / Celebrity"],
+ ["Ariana Grande","Ariana Grande","Real Person / Celebrity"],
["Ashton Kutcher","Ashton Kutcher","Real Person / Celebrity"],
["Axel Foley","Eddie Murphy","Beverly Hills Cop"],
["Barack Obama","Barack Obama","Real Person / Celebrity"],
@@ -108,6 +109,7 @@ export const KNOWN_CHARACTERS = [
["Commodus","Joaquin Phoenix","Gladiator"],
["Conan","Arnold Schwarzenegger","Conan the Barbarian"],
["Conan O'Brien","Conan O'Brien","Late Night"],
+ ["Cosmo Kramer","Michael Richards","Seinfeld"],
["Cristiano Ronaldo","Cristiano Ronaldo","Real Person / Celebrity"],
["Daemon Targaryen","Matt Smith","House of the Dragon"],
["Daenerys Targaryen","Emilia Clarke","Game of Thrones"],
@@ -185,7 +187,6 @@ export const KNOWN_CHARACTERS = [
["Gellert Grindelwald","Mads Mikkelsen","Fantastic Beasts"],
["Geordi La Forge","LeVar Burton","Star Trek: The Next Generation"],
["George Costanza","Jason Alexander","Seinfeld"],
- ["Glenn Rhee","Steven Yeun","The Walking Dead"],
["Gloria Pritchett","Sofia Vergara","Modern Family"],
["God","Morgan Freeman","Bruce Almighty"],
["Goofy","Goofy","Disney"],
@@ -244,6 +245,7 @@ export const KNOWN_CHARACTERS = [
["Jax Teller","Charlie Hunnam","Sons of Anarchy"],
["Jean-Luc Picard","Patrick Stewart","Star Trek: The Next Generation"],
["Jeff Goldblum","Jeff Goldblum","Real Person / Celebrity"],
+ ["Jennifer Lopez","Jennifer Lopez","Real Person / Celebrity"],
["Jennifer Love Hewitt","Jennifer Love Hewitt","Real Person / Celebrity"],
["Jeremy Grey","Vince Vaughn","Wedding Crashers"],
["Jeremy Renner","Jeremy Renner","Real Person / Celebrity"],
@@ -309,6 +311,7 @@ export const KNOWN_CHARACTERS = [
["Leonardo DiCaprio","Leonardo DiCaprio","Real Person / Celebrity"],
["Lex Luthor","Kevin Spacey","Superman Returns"],
["Linus Caldwell","Matt Damon","Ocean's Eleven"],
+ ["Lisa Tragnetti","Alexandra Daddario","True Detective"],
["Liz Lemon","Tina Fey","30 Rock"],
["Lloyd Christmas","Jim Carrey","Dumb and Dumber"],
["Loki","Tom Hiddleston","Marvel's Avengers"],
@@ -466,6 +469,7 @@ export const KNOWN_CHARACTERS = [
["The Narrator","Edward Norton","Fight Club"],
["The Tenth Doctor","David Tennant","Doctor Who"],
["The Terminator T-800","Arnold Schwarzenegger","The Terminator"],
+ ["The Thirteenth Doctor","Jodie Whittaker","Doctor Who"],
["The Twelfth Doctor","Peter Capaldi","Doctor Who"],
["Thor","Chris Hemsworth","Marvel's Avengers"],
["Tim \"The Tool Man\" Taylor","Tim Allen","Home Improvement"],
diff --git a/src/lib/reference-presets.test.ts b/src/lib/reference-presets.test.ts
index dd3cc88..c62d0d5 100644
--- a/src/lib/reference-presets.test.ts
+++ b/src/lib/reference-presets.test.ts
@@ -1,15 +1,19 @@
import { describe, expect, it } from "vitest";
-import { REFERENCE_PRESETS, type PresetReferenceType } from "./reference-presets";
+import { KNOWN_CHARACTERS } from "./known-characters";
+import { LOCATION_GROUPS } from "./expanded-reference-options";
+import { composeLocationPrompt, locationSelectionFromPrompt, REFERENCE_PRESETS, type PresetReferenceType } from "./reference-presets";
const TYPES: PresetReferenceType[] = ["character", "product", "location", "style"];
describe("reference preset catalog", () => {
- it("offers about 500 choices for every prepared type", () => {
- for (const type of TYPES) {
- const count = REFERENCE_PRESETS.filter((preset) => preset.type === type).length;
- expect(count, type).toBeGreaterThanOrEqual(499);
- expect(count, type).toBeLessThanOrEqual(520);
- }
+ it("tracks the upstream known-good characters and keeps the other catalogs unique", () => {
+ expect(KNOWN_CHARACTERS).toHaveLength(503);
+ expect(KNOWN_CHARACTERS).toContainEqual(["Ariana Grande", "Ariana Grande", "Real Person / Celebrity"]);
+ expect(KNOWN_CHARACTERS).toContainEqual(["The Thirteenth Doctor", "Jodie Whittaker", "Doctor Who"]);
+ expect(KNOWN_CHARACTERS.map(([name]) => String(name))).not.toContain("Glenn Rhee");
+ expect(REFERENCE_PRESETS.filter((preset) => preset.type === "product")).toHaveLength(100);
+ expect(REFERENCE_PRESETS.filter((preset) => preset.type === "location")).toHaveLength(100);
+ expect(REFERENCE_PRESETS.filter((preset) => preset.type === "style")).toHaveLength(100);
});
it("organizes every prepared type into subcategories", () => {
@@ -26,4 +30,17 @@ describe("reference preset catalog", () => {
expect(new Set(ids).size).toBe(ids.length);
expect(Math.max(...REFERENCE_PRESETS.map((preset) => preset.prompt.length))).toBeLessThanOrEqual(100);
});
+
+ it("does not multiply products or styles by adjectives", () => {
+ expect(REFERENCE_PRESETS.some((preset) => /^(Eco|Premium|Rugged|Textured|Bright) /.test(preset.name))).toBe(false);
+ });
+
+ it("keeps time, weather and season out of base locations and composes them independently", () => {
+ const names = LOCATION_GROUPS.flatMap((group) => group.options);
+ expect(names.some((name) => /\b(night|dawn|dusk|misty|storm|winter|summer|spring|autumn)\b/i.test(name))).toBe(false);
+ const coastal = REFERENCE_PRESETS.find((preset) => preset.type === "location" && preset.name === "Coastal village")!;
+ const prompt = composeLocationPrompt(coastal, { time: "night", season: "winter" });
+ expect(prompt).toBe("Coastal village, at night, in winter.");
+ expect(locationSelectionFromPrompt(prompt)).toEqual({ preset: coastal, settings: { time: "night", season: "winter" } });
+ });
});
diff --git a/src/lib/reference-presets.ts b/src/lib/reference-presets.ts
index 38a4e11..43c67c3 100644
--- a/src/lib/reference-presets.ts
+++ b/src/lib/reference-presets.ts
@@ -1,14 +1,5 @@
import { KNOWN_CHARACTERS } from "./known-characters";
-import {
- LOCATION_GROUPS,
- LOCATION_VARIANTS,
- PRODUCT_GROUPS,
- PRODUCT_VARIANTS,
- STYLE_GROUPS,
- STYLE_VARIANTS,
- type OptionGroup,
- type OptionVariant,
-} from "./expanded-reference-options";
+import { LOCATION_GROUPS, LOCATION_SETTING_GROUPS, PRODUCT_GROUPS, STYLE_GROUPS, type OptionGroup } from "./expanded-reference-options";
import type { ProjectReference } from "./project";
export type ReferenceType = "custom" | "character" | "product" | "location" | "style";
@@ -80,43 +71,60 @@ const knownCharacterPresets: ReferencePreset[] = KNOWN_CHARACTERS.map(([name, ac
searchTerms: `${actor} ${franchise}`,
}));
-const expandOptions = (
- type: PresetReferenceType,
- groups: readonly OptionGroup[],
- variants: readonly OptionVariant[],
- label: (option: string, variant: OptionVariant) => string,
- prompt: (option: string, variant: OptionVariant) => string,
-): ReferencePreset[] => groups.flatMap((group) => group.options.flatMap((option) => variants.map((variant) => ({
- id: `${type}-${safeId(group.subcategory)}-${safeId(option)}-${safeId(variant.name)}`,
- type,
- subcategory: group.subcategory,
- name: label(option, variant),
- prompt: prompt(option, variant),
-}))));
-
-const expandedProductPresets = expandOptions(
- "product",
- PRODUCT_GROUPS,
- PRODUCT_VARIANTS,
- (option, variant) => `${variant.name} ${option}`,
- (option, variant) => `${variant.prompt} ${option.toLocaleLowerCase()}.`,
-);
-const expandedLocationPresets = expandOptions(
- "location",
- LOCATION_GROUPS,
- LOCATION_VARIANTS,
- (option, variant) => `${option} · ${variant.name}`,
- (option, variant) => `${option}, ${variant.prompt}.`,
-);
-const expandedStylePresets = expandOptions(
- "style",
- STYLE_GROUPS,
- STYLE_VARIANTS,
- (option, variant) => `${variant.name} ${option}`,
- (option, variant) => `${variant.prompt} ${option.toLocaleLowerCase()}.`,
-);
-
-const curatedPresets: ReferencePreset[] = [
+/** Product, location and style catalogs contain unique subjects. Qualifying
+ * adjectives no longer multiply each subject into five near-duplicates. */
+const optionsAsPresets = (type: PresetReferenceType, groups: readonly OptionGroup[]): ReferencePreset[] =>
+ groups.flatMap((group) => group.options.map((option) => ({
+ id: `${type}-${safeId(group.subcategory)}-${safeId(option)}`,
+ type,
+ subcategory: group.subcategory,
+ name: option,
+ prompt: `${option}.`,
+ })));
+
+const productPresets = optionsAsPresets("product", PRODUCT_GROUPS);
+const locationPresets = optionsAsPresets("location", LOCATION_GROUPS);
+const stylePresets = optionsAsPresets("style", STYLE_GROUPS);
+
+export type LocationSettings = Partial<Record<(typeof LOCATION_SETTING_GROUPS)[number]["id"], string>>;
+
+export interface LocationSelection {
+ preset: ReferencePreset;
+ settings: LocationSettings;
+}
+
+export function composeLocationPrompt(preset: ReferencePreset, settings: LocationSettings): string {
+ const qualifiers = LOCATION_SETTING_GROUPS.flatMap((group) => {
+ const option = group.options.find((candidate) => candidate.id === settings[group.id]);
+ return option ? [option.prompt] : [];
+ });
+ return `${preset.name}${qualifiers.length ? `, ${qualifiers.join(", ")}` : ""}.`;
+}
+
+/** Recovers picker state from its prompt, avoiding UI-only fields in portable
+ * project JSON. Only a prompt this picker itself can compose is recognized. */
+export function locationSelectionFromPrompt(prompt: string): LocationSelection | undefined {
+ for (const preset of [...locationPresets].sort((left, right) => right.name.length - left.name.length)) {
+ const base = preset.name;
+ if (prompt === `${base}.`) return { preset, settings: {} };
+ if (!prompt.startsWith(`${base}, `) || !prompt.endsWith(".")) continue;
+ const qualifiers = prompt.slice(base.length + 2, -1).split(", ");
+ const settings: LocationSettings = {};
+ let lastGroup = -1;
+ let valid = true;
+ for (const qualifier of qualifiers) {
+ const groupIndex = LOCATION_SETTING_GROUPS.findIndex((group) => group.options.some((option) => option.prompt === qualifier));
+ const option = groupIndex >= 0 ? LOCATION_SETTING_GROUPS[groupIndex].options.find((candidate) => candidate.prompt === qualifier) : undefined;
+ if (!option || groupIndex <= lastGroup) { valid = false; break; }
+ settings[LOCATION_SETTING_GROUPS[groupIndex].id] = option.id;
+ lastGroup = groupIndex;
+ }
+ if (valid && composeLocationPrompt(preset, settings) === prompt) return { preset, settings };
+ }
+ return undefined;
+}
+
+const curatedCharacterPresets: ReferencePreset[] = [
{ id: "character-alice", type: "character", subcategory: "Literature & legend", name: "Alice in Wonderland", prompt: "Alice in her blue dress and white apron." },
{ id: "character-dracula", type: "character", subcategory: "Literature & legend", name: "Count Dracula", prompt: "Count Dracula in formal black evening wear." },
{ id: "character-robin-hood", type: "character", subcategory: "Literature & legend", name: "Robin Hood", prompt: "Robin Hood in practical forest-green clothing." },
@@ -124,57 +132,33 @@ const curatedPresets: ReferencePreset[] = [
{ id: "character-frankenstein", type: "character", subcategory: "Literature & legend", name: "Frankenstein's Creature", prompt: "Frankenstein's towering, solemn creature." },
{ id: "character-dorothy-gale", type: "character", subcategory: "Literature & legend", name: "Dorothy Gale", prompt: "Dorothy Gale in a blue gingham dress." },
{ id: "character-king-arthur", type: "character", subcategory: "Literature & legend", name: "King Arthur", prompt: "King Arthur in polished medieval armor." },
-
- { id: "product-watch", type: "product", subcategory: "Fashion", name: "Luxury wristwatch", prompt: "Brushed steel watch with sapphire crystal." },
- { id: "product-skincare", type: "product", subcategory: "Beauty", name: "Skincare bottle", prompt: "Minimal frosted-glass skincare bottle." },
- { id: "product-sneaker", type: "product", subcategory: "Fashion", name: "Performance sneaker", prompt: "Modern mesh sneaker with a sculpted sole." },
- { id: "product-smartphone", type: "product", subcategory: "Technology", name: "Flagship smartphone", prompt: "Slim glass smartphone with a satin frame." },
- { id: "product-car", type: "product", subcategory: "Vehicles", name: "Sports car", prompt: "Low sports car with precise LED lights." },
- { id: "product-coffee", type: "product", subcategory: "Appliances", name: "Espresso machine", prompt: "Compact brushed-steel espresso machine." },
- { id: "product-chair", type: "product", subcategory: "Furniture", name: "Designer lounge chair", prompt: "Sculptural wood and fabric lounge chair." },
-
- { id: "location-cyberpunk-alley", type: "location", subcategory: "Urban", name: "Neon city alley", prompt: "Rainy neon alley with reflective pavement." },
- { id: "location-victorian-manor", type: "location", subcategory: "Historic", name: "Victorian manor", prompt: "Weathered Victorian manor with dark wood." },
- { id: "location-moon-base", type: "location", subcategory: "Sci-fi", name: "Lunar research base", prompt: "White lunar base under harsh sunlight." },
- { id: "location-alpine-village", type: "location", subcategory: "Nature", name: "Alpine village", prompt: "Timber village beneath snowy mountains." },
- { id: "location-art-deco-lobby", type: "location", subcategory: "Interiors", name: "Art Deco hotel lobby", prompt: "Brass and dark-stone Art Deco lobby." },
- { id: "location-medieval-market", type: "location", subcategory: "Historic", name: "Medieval market", prompt: "Busy medieval market with canvas stalls." },
- { id: "location-tropical-beach", type: "location", subcategory: "Nature", name: "Remote tropical beach", prompt: "Secluded turquoise beach with palms." },
- { id: "location-modern-studio", type: "location", subcategory: "Interiors", name: "Modern creative studio", prompt: "Bright timber studio with large windows." },
-
- { id: "style-film-noir", type: "style", subcategory: "Cinematic", name: "Film noir", prompt: "High-contrast monochrome with hard shadows." },
- { id: "style-documentary", type: "style", subcategory: "Cinematic", name: "35 mm documentary", prompt: "Natural light, handheld framing, subtle grain." },
- { id: "style-watercolor", type: "style", subcategory: "Illustration", name: "Storybook watercolor", prompt: "Soft watercolor on textured paper." },
- { id: "style-stop-motion", type: "style", subcategory: "Animation", name: "Handmade stop motion", prompt: "Tactile miniatures with stepped movement." },
- { id: "style-editorial", type: "style", subcategory: "Commercial", name: "Luxury editorial", prompt: "Sculpted light and deliberate negative space." },
- { id: "style-retrofuturism", type: "style", subcategory: "Retro", name: "1970s retrofuturism", prompt: "Rounded forms and warm analog controls." },
- { id: "style-anime", type: "style", subcategory: "Animation", name: "Cinematic anime", prompt: "Clean linework with painted backgrounds." },
- { id: "style-clay", type: "style", subcategory: "Animation", name: "Clay animation", prompt: "Hand-sculpted clay with playful movement." },
];
export const REFERENCE_PRESETS: readonly ReferencePreset[] = [
...knownCharacterPresets,
- ...expandedProductPresets,
- ...expandedLocationPresets,
- ...expandedStylePresets,
- ...curatedPresets,
-]
- .sort((left, right) => left.type.localeCompare(right.type) || left.subcategory.localeCompare(right.subcategory) || left.name.localeCompare(right.name));
+ ...productPresets,
+ ...locationPresets,
+ ...stylePresets,
+ ...curatedCharacterPresets,
+].sort((left, right) => left.type.localeCompare(right.type) || left.subcategory.localeCompare(right.subcategory) || left.name.localeCompare(right.name));
+
+const presetForReference = (reference: ProjectReference): ReferencePreset | undefined => {
+ const intended = reference.intendedUse.length === 1 ? reference.intendedUse[0] : undefined;
+ return REFERENCE_PRESETS.find((preset) => preset.type === intended && preset.prompt === reference.description)
+ ?? (intended === "location" ? locationSelectionFromPrompt(reference.description)?.preset : undefined);
+};
export function referenceType(reference: ProjectReference): ReferenceType {
const stored = reference.intendedUse.length === 1
? REFERENCE_TYPES.find((type) => type.id !== "custom" && type.id === reference.intendedUse[0])?.id
: undefined;
- /* Existing references were all free-written prompts, even when they carried
- * one or more library tags. They stay editable as Custom. A non-custom type
- * is only claimed when its prompt is one of that type's actual presets. */
- return stored && REFERENCE_PRESETS.some((preset) => preset.type === stored && preset.prompt === reference.description)
- ? stored
- : "custom";
+ return stored && presetForReference(reference)?.type === stored ? stored : "custom";
}
export const referenceTypeLabel = (type: ReferenceType): string =>
REFERENCE_TYPES.find((candidate) => candidate.id === type)?.label ?? "Custom";
-export const selectedReferencePreset = (reference: ProjectReference): ReferencePreset | undefined =>
- REFERENCE_PRESETS.find((preset) => preset.type === referenceType(reference) && preset.prompt === reference.description);
+export const selectedReferencePreset = (reference: ProjectReference): ReferencePreset | undefined => {
+ const preset = presetForReference(reference);
+ return preset?.type === referenceType(reference) ? preset : undefined;
+};
diff --git a/src/styles/references.css b/src/styles/references.css
index 49bf39c..132fb7f 100644
--- a/src/styles/references.css
+++ b/src/styles/references.css
@@ -828,6 +828,79 @@
background: var(--accent-soft);
}
+.reference-preset-grid > button.active {
+ border-color: var(--accent-bright);
+ background: var(--accent-soft);
+}
+
+.reference-location-settings {
+ display: flex;
+ flex-direction: column;
+ gap: var(--space-3);
+ margin-bottom: var(--space-4);
+ padding: var(--space-4);
+ border: 1px solid var(--accent);
+ border-radius: var(--radius-md);
+ background: var(--accent-soft);
+}
+
+.reference-location-settings > header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: var(--space-3);
+}
+
+.reference-location-settings > header span,
+.reference-location-settings > header small,
+.reference-location-settings > header b {
+ display: block;
+}
+
+.reference-location-settings > header small {
+ color: var(--text-muted);
+ font-size: var(--text-2xs);
+ text-transform: uppercase;
+}
+
+.reference-location-settings > p,
+.reference-location-settings__preview {
+ color: var(--text-muted);
+ font-size: var(--text-sm);
+}
+
+.reference-location-settings__group {
+ display: flex;
+ flex-direction: column;
+ gap: var(--space-2);
+}
+
+.reference-location-settings__group > b {
+ color: var(--text-secondary);
+ font-size: var(--text-xs);
+}
+
+.reference-location-settings__group > span {
+ display: flex;
+ flex-wrap: wrap;
+ gap: var(--space-2);
+}
+
+.reference-location-settings__group button {
+ min-height: var(--control-sm);
+ padding: 0 var(--space-3);
+ border: 1px solid var(--line);
+ border-radius: var(--radius-pill);
+ color: var(--text-secondary);
+ background: var(--panel-3);
+}
+
+.reference-location-settings__group button:hover,
+.reference-location-settings__group button.active {
+ border-color: var(--accent-bright);
+ color: var(--accent-bright);
+}
+
.reference-preset-grid b,
.reference-preset-grid span,
.reference-preset-grid small {