The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Pickers: choices the model can't do look unavailable and say how to get them
Adarsha4db97d063ac
diff --git a/src/app/tab-row.css b/src/app/tab-row.cssindex 74248dd3..29922325 100644--- a/src/app/tab-row.css+++ b/src/app/tab-row.css@@ -129,7 +129,7 @@/* Hover only while the mouse leads (html[data-input], nav/input-modality.ts), as in the nav: never a second fillbeside the keyboard's ring. */@media (hover: hover) {- html:not([data-input="keyboard"]) .tab-pill:not([data-on], [data-state="active"]):hover {+ html:not([data-input="keyboard"]) .tab-pill:not([data-on], [data-state="active"], :disabled, [aria-disabled="true"]):hover {background-color: var(--tab-hi);color: var(--foreground);}@@ -139,7 +139,7 @@color: var(--muted-foreground);}}- html .tab-pill:not([data-on], [data-state="active"]):active:active {+ html .tab-pill:not([data-on], [data-state="active"], :disabled, [aria-disabled="true"]):active:active {background-color: var(--tab-press);transition-duration: 0ms;}diff --git a/src/components/faceless/controls.tsx b/src/components/faceless/controls.tsxindex 3e425dbc..33c09b78 100644--- a/src/components/faceless/controls.tsx+++ b/src/components/faceless/controls.tsx@@ -4,7 +4,9 @@ import { AlertTriangle, Info, Loader2 } from "lucide-react";import { useId, useState } from "react";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";import { Switch } from "@/components/ui/switch";+import { UNAVAILABLE_OPTION, UnavailableNote, useUnavailableNote } from "@/components/ui/unavailable";import { radioKeys, radioTab } from "@/components/studio/radio-keys";+import type { Unavailable } from "@/lib/unavailable";import { formatLength, PART_LABELS, type EstimateResult, type StepPart } from "@/lib/catalog/faceless";import type { Engine } from "@/lib/catalog/types";import { cn } from "@/lib/utils";@@ -18,31 +20,41 @@ export function Segmented<T extends string | number>({className,}: {value: T;- options: { value: T; label: string; hint?: string }[];+ /** `unavailable`: a choice the current setup can't do; pressing it says why (src/components/ui/unavailable.tsx). */+ options: { value: T; label: string; hint?: string; unavailable?: Unavailable | false | null }[];onChange: (v: T) => void;label: string;className?: string;}) {+ const note = useUnavailableNote(options);+ const checked = (o: (typeof options)[number]) => value === o.value && !note.isUnavailable(o);+ const stop = options.find(checked)?.value ?? options.find((o) => !note.isUnavailable(o))?.value ?? options[0]?.value;return (- <div role="radiogroup" aria-label={label} onKeyDown={radioKeys} className={cn("inline-flex max-w-full flex-wrap gap-0.5 rounded-full bg-muted p-0.5", className)}>- {options.map((o) => (- <button- key={String(o.value)}- type="button"- role="radio"- aria-checked={value === o.value}- tabIndex={radioTab(value === o.value)}- title={o.hint}- onClick={() => onChange(o.value)}- className={cn(- "h-8 rounded-full px-3 text-[13px] font-medium whitespace-nowrap text-muted-foreground transition outline-none focus-visible:ring-2 focus-visible:ring-ring",- value === o.value ? "bg-background text-foreground shadow-soft" : "hover:text-foreground",- )}- >- {o.label}- </button>- ))}- </div>+ <>+ <div role="radiogroup" aria-label={label} onKeyDown={radioKeys} className={cn("inline-flex max-w-full flex-wrap gap-0.5 rounded-full bg-muted p-0.5", className)}>+ {options.map((o) => {+ const off = note.isUnavailable(o);+ return (+ <button+ key={String(o.value)}+ type="button"+ role="radio"+ aria-checked={checked(o)}+ tabIndex={radioTab(stop === o.value)}+ {...note.optionProps({ ...o, title: o.hint })}+ onClick={() => note.press(o, onChange)}+ className={cn(+ "h-8 rounded-full px-3 text-[13px] font-medium whitespace-nowrap text-muted-foreground transition outline-none focus-visible:ring-2 focus-visible:ring-ring",+ checked(o) ? "bg-background text-foreground shadow-soft" : off ? UNAVAILABLE_OPTION : "hover:text-foreground",+ )}+ >+ {o.label}+ </button>+ );+ })}+ </div>+ <UnavailableNote {...note.noteProps} />+ </>);}diff --git a/src/components/genjutsu/genjutsu-studio.tsx b/src/components/genjutsu/genjutsu-studio.tsxindex e2b210dd..b1dc82ef 100644--- a/src/components/genjutsu/genjutsu-studio.tsx+++ b/src/components/genjutsu/genjutsu-studio.tsx@@ -53,6 +53,7 @@ import {MODE_TARGETS,modeHint,OPEN_TARGET_PROBLEM,+ resolutionChoices,resolutionWords,SCENE_ACTIONS,SOURCE_LABELS,@@ -298,6 +299,36 @@ export function GenjutsuStudio({ examples, modeExamples, live }: { examples?: Exconst seedNumber = seedOf(seed);// Modes with no seed field of their own show one once a seed is set (an example's or a pasted setup's).const seedShown = !isCharacter && !fresh && seed.trim() !== "" && seedFor === mode;+ /** A model picked in the list (or by a note's Switch): the rest of the setup stays where it still applies. */+ const pickMaker = (id: string) => {+ setPicked((p) => ({ ...p, [choiceKey]: id }));+ // Another model than Scene edit: back to swapping (Remove it and New background are Scene edit's).+ if (mode === "swap" && !options.find((m) => m.id === id)?.actions) setAction("change");+ // Motion transfer's MiniMax H3 takes up to 15 s: a longer selection is cut back to its first 15 s.+ const most = mode === "motion" ? options.find((m) => m.id === id)?.part?.max : undefined;+ if (most && range && range.endTime - range.startTime > most + 0.05) setRange({ ...range, endTime: Math.round((range.startTime + most) * 100) / 100 });+ };+ // Resolutions the picked model can't render stay in view, muted; pressing one says what renders it, with Switch.+ const resChoices = maker ? resolutionChoices(maker, options, tier, isOn) : [];+ const resolutionOptions = GENJUTSU.qualities.map((q) => {+ const c = resChoices.find((r) => r.quality === q);+ const route = c?.route;+ return {+ value: q,+ label: q,+ unavailable: c && !c.ok && {+ why: c.why ?? "",+ fix: route && {+ label: "Switch",+ run: () => {+ if (route.pick) pickMaker(route.pick);+ if (route.tier) setTier(route.tier);+ setQuality(route.quality);+ },+ },+ },+ };+ });// Character swap's H3 makers take H3's two qualities; the other makers (Recast, P-Video…) Genjutsu's own.// A size this engine can't make worth it (your GPU's 4K) is asked as 2K, as the picker shows it.const askedQuality = isCharacter && maker?.h3 ? (qualityOff(engine, charQuality) ? "2K" : charQuality) : quality;@@ -1193,14 +1224,7 @@ export function GenjutsuStudio({ examples, modeExamples, live }: { examples?: Ex<MakerListoptions={options}value={maker.pair && maker.tier === "high" ? maker.pair : maker.id}- onChange={(id) => {- setPicked((p) => ({ ...p, [choiceKey]: id }));- // Another model than Scene edit: back to swapping (Remove it and New background are Scene edit's).- if (mode === "swap" && !options.find((m) => m.id === id)?.actions) setAction("change");- // Motion transfer's MiniMax H3 takes up to 15 s: a longer selection is cut back to its first 15 s.- const most = mode === "motion" ? options.find((m) => m.id === id)?.part?.max : undefined;- if (most && range && range.endTime - range.startTime > most + 0.05) setRange({ ...range, endTime: Math.round((range.startTime + most) * 100) / 100 });- }}+ onChange={pickMaker}mark={(m) => (m.features && !m.features.some((f) => !!live?.[f]) ? mark(m.features[0]) : undefined)}/></Field>@@ -1232,7 +1256,7 @@ export function GenjutsuStudio({ examples, modeExamples, live }: { examples?: Exlabel="Resolution"value={(maker && GENJUTSU.qualities.find((q) => q === qualityFor(maker, quality))) || quality}onChange={setQuality}- options={GENJUTSU.qualities.map((q) => ({ value: q, label: q }))}+ options={resolutionOptions}/></Field>)}diff --git a/src/components/kinetic/controls.tsx b/src/components/kinetic/controls.tsxindex 8c87a805..aff9a48c 100644--- a/src/components/kinetic/controls.tsx+++ b/src/components/kinetic/controls.tsx@@ -2,11 +2,15 @@import { ChevronDown, Diamond } from "lucide-react";import { useId, useState } from "react";+import { UNAVAILABLE_OPTION, UnavailableNote, useUnavailableNote } from "@/components/ui/unavailable";+import type { Unavailable } from "@/lib/unavailable";import { cn } from "@/lib/utils";/*** Kinetic's small controls: segmented choices, a slider with its number field (and, for the numbers a track can* animate, a key button), and a collapsible panel. Every target is at least 44 px; sliders get a 44 px hit area.+ * A choice's `unavailable` (one the current setup can't do) stays in view, muted; pressing it says why+ * (src/components/ui/unavailable.tsx).*/export const chipClass = (on: boolean) =>@@ -18,6 +22,8 @@ export const chipClass = (on: boolean) =>export const iconButton ="grid size-11 shrink-0 place-items-center rounded-full text-foreground outline-none transition-colors hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-40";+type Choice<T> = { id: T; label: string; unavailable?: Unavailable | false | null };+/** One choice of several (a radio group of chips). `value` null shows none chosen (a Pro value moved it). */export function Choices<T extends string>({label,@@ -28,12 +34,14 @@ export function Choices<T extends string>({className,}: {label: string;- choices: readonly { id: T; label: string }[];+ choices: readonly Choice<T>[];value: T | null;onChange: (v: T) => void;note?: string;className?: string;}) {+ const items = choices.map((c) => ({ ...c, value: c.id }));+ const said = useUnavailableNote(items);return (<div className={cn("min-w-0", className)}><p className="mb-1.5 text-[12px] font-medium text-muted-foreground">@@ -41,12 +49,16 @@ export function Choices<T extends string>({{note && <span className="font-normal"> · {note}</span>}</p><div role="radiogroup" aria-label={label} className="flex min-w-0 flex-wrap gap-1.5">- {choices.map((c) => (- <button key={c.id} type="button" role="radio" aria-checked={value === c.id} onClick={() => onChange(c.id)} className={chipClass(value === c.id)}>- {c.label}- </button>- ))}+ {items.map((c) => {+ const on = value === c.id && !said.isUnavailable(c);+ return (+ <button key={c.id} type="button" role="radio" aria-checked={on} {...said.optionProps(c)} onClick={() => said.press(c, onChange)} className={cn(chipClass(on), !on && said.isUnavailable(c) && UNAVAILABLE_OPTION)}>+ {c.label}+ </button>+ );+ })}</div>+ <UnavailableNote {...said.noteProps} /></div>);}@@ -60,31 +72,38 @@ export function Segmented<T extends string>({hideLabel,}: {label: string;- choices: readonly { id: T; label: string }[];+ choices: readonly Choice<T>[];value: T | null;onChange: (v: T) => void;hideLabel?: boolean;}) {+ const items = choices.map((c) => ({ ...c, value: c.id }));+ const said = useUnavailableNote(items);return (<div className="min-w-0">{!hideLabel && <p className="mb-1.5 text-[12px] font-medium text-muted-foreground">{label}</p>}<div role="radiogroup" aria-label={label} className="grid min-w-0 auto-cols-fr grid-flow-col gap-0.5 rounded-full bg-secondary p-0.5">- {choices.map((c) => (- <button- key={c.id}- type="button"- role="radio"- aria-checked={value === c.id}- onClick={() => onChange(c.id)}- className={cn(- "h-11 min-w-0 truncate rounded-full px-2 text-[13px] font-medium transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring",- value === c.id ? "bg-foreground text-background" : "text-muted-foreground hover:text-foreground",- )}- >- {c.label}- </button>- ))}+ {items.map((c) => {+ const on = value === c.id && !said.isUnavailable(c);+ return (+ <button+ key={c.id}+ type="button"+ role="radio"+ aria-checked={on}+ {...said.optionProps(c)}+ onClick={() => said.press(c, onChange)}+ className={cn(+ "h-11 min-w-0 truncate rounded-full px-2 text-[13px] font-medium transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring",+ on ? "bg-foreground text-background" : said.isUnavailable(c) ? UNAVAILABLE_OPTION : "text-muted-foreground hover:text-foreground",+ )}+ >+ {c.label}+ </button>+ );+ })}</div>+ <UnavailableNote {...said.noteProps} /></div>);}diff --git a/src/components/layers/bits.tsx b/src/components/layers/bits.tsxindex 37e13362..ac654d7e 100644--- a/src/components/layers/bits.tsx+++ b/src/components/layers/bits.tsx@@ -1,9 +1,15 @@"use client";+import { UNAVAILABLE_OPTION, UnavailableNote, useUnavailableNote } from "@/components/ui/unavailable";import { radioKeys, radioTab } from "@/components/studio/radio-keys";+import type { Unavailable } from "@/lib/unavailable";import { cn } from "@/lib/utils";-/** Segmented control (the app's track + white thumb), a radio group for keyboards and screen readers. */+/**+ * Segmented control (the app's track + white thumb), a radio group for keyboards and screen readers. An option's third+ * entry (or `unavailable` for the whole control) is a choice the current setup can't do: it stays, muted, and pressing+ * it says why (src/components/ui/unavailable.tsx). A plain `disabled` reads the same way.+ */export function Segmented<T extends string>({label,value,@@ -11,34 +17,43 @@ export function Segmented<T extends string>({onChange,className,disabled,+ unavailable,}: {label: string;value: T;- options: readonly (readonly [T, string])[];+ options: readonly (readonly [T, string] | readonly [T, string, Unavailable | false | null | undefined])[];onChange: (v: T) => void;className?: string;disabled?: boolean;+ unavailable?: Unavailable;}) {+ const items = options.map(([v, text, u]) => ({ value: v, text, unavailable: u || unavailable, disabled }));+ const note = useUnavailableNote(items);+ const checked = (o: (typeof items)[number]) => value === o.value && !note.isUnavailable(o);+ const stop = items.find(checked)?.value ?? items.find((o) => !note.isUnavailable(o))?.value ?? items[0]?.value;return (- <div role="radiogroup" aria-label={label} onKeyDown={radioKeys} className={cn("grid h-9 rounded-full bg-muted p-0.5 text-[13px] font-medium", className)} style={{ gridTemplateColumns: `repeat(${options.length}, minmax(0, 1fr))` }}>- {options.map(([v, text]) => (- <button- key={v}- type="button"- role="radio"- aria-checked={value === v}- tabIndex={radioTab(value === v)}- disabled={disabled}- onClick={() => onChange(v)}- className={cn(- "truncate rounded-full px-2 transition-colors disabled:opacity-50",- value === v ? "bg-background text-foreground shadow-soft" : "text-muted-foreground hover:text-foreground",- )}- >- {text}- </button>- ))}- </div>+ <>+ <div role="radiogroup" aria-label={label} onKeyDown={radioKeys} className={cn("grid h-9 rounded-full bg-muted p-0.5 text-[13px] font-medium", className)} style={{ gridTemplateColumns: `repeat(${items.length}, minmax(0, 1fr))` }}>+ {items.map((o) => (+ <button+ key={o.value}+ type="button"+ role="radio"+ aria-checked={checked(o)}+ tabIndex={radioTab(stop === o.value)}+ {...note.optionProps(o)}+ onClick={() => note.press(o, onChange)}+ className={cn(+ "truncate rounded-full px-2 transition-colors",+ checked(o) ? "bg-background text-foreground shadow-soft" : note.isUnavailable(o) ? UNAVAILABLE_OPTION : "text-muted-foreground hover:text-foreground",+ )}+ >+ {o.text}+ </button>+ ))}+ </div>+ <UnavailableNote {...note.noteProps} />+ </>);}diff --git a/src/components/shorts/ui.tsx b/src/components/shorts/ui.tsxindex 8487b653..3b9e46e7 100644--- a/src/components/shorts/ui.tsx+++ b/src/components/shorts/ui.tsx@@ -3,10 +3,12 @@import { Check, CircleAlert, Film, Library, Loader2, Upload, X } from "lucide-react";import { useRef, useState } from "react";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";+import { UNAVAILABLE_OPTION, UnavailableNote, useUnavailableNote } from "@/components/ui/unavailable";import { LibraryGrid } from "@/components/studio/media-slot";import { radioKeys, radioTab } from "@/components/studio/radio-keys";import { useAskBeforeUpload } from "@/lib/api";import { toolPoolPrice } from "@/lib/run-place";+import type { Unavailable } from "@/lib/unavailable";import { cn } from "@/lib/utils";import type { SourceClip } from "./use-source-clip";@@ -22,37 +24,50 @@ export function Segmented<T extends string | number>({}: {label: string;value: T;- options: { value: T; label: string; hint?: string; disabled?: boolean; title?: string }[];+ /**+ * `unavailable`: a choice the current model or mode can't do. It stays in view, muted; pressing it picks nothing and+ * says why, with the way to get it (src/components/ui/unavailable.tsx). A plain `disabled` reads the same way, with+ * its `title` as the reason.+ */+ options: { value: T; label: string; hint?: string; disabled?: boolean; title?: string; unavailable?: Unavailable | false | null }[];onChange: (v: T) => void;className?: string;/** The id of text that says more (why some options are turned off). */describedBy?: string;}) {- // The Tab stop is the checked option, or the first one that can be picked when it's turned off- // (a disabled button can't take focus, and the whole group would be skipped).- const stop = options.some((o) => o.value === value && !o.disabled) ? value : options.find((o) => !o.disabled)?.value;+ const note = useUnavailableNote(options);+ // An unavailable choice is never drawn as the picked one. The Tab stop is the checked option, else the first one+ // that can be picked (so the group always takes focus).+ const checked = (o: (typeof options)[number]) => o.value === value && !note.isUnavailable(o);+ const stop = options.find(checked)?.value ?? options.find((o) => !note.isUnavailable(o))?.value ?? options[0]?.value;return (- <div role="radiogroup" aria-label={label} aria-describedby={describedBy} onKeyDown={radioKeys} className={cn("flex w-full rounded-full bg-muted p-0.5", className)}>- {options.map((o) => (- <button- key={String(o.value)}- type="button"- role="radio"- aria-checked={value === o.value}- tabIndex={radioTab(stop === o.value)}- disabled={o.disabled}- title={o.title}- onClick={() => onChange(o.value)}- className={cn(- "flex h-8 min-w-0 flex-1 items-center justify-center gap-1 rounded-full px-2 text-[13px] font-medium whitespace-nowrap text-muted-foreground transition-colors outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:text-muted-foreground",- value === o.value && "bg-background text-foreground shadow-soft",- )}- >- {o.label}- {o.hint && <span className="hidden text-[11px] font-normal text-muted-foreground sm:inline">{o.hint}</span>}- </button>- ))}- </div>+ <>+ <div role="radiogroup" aria-label={label} aria-describedby={describedBy} onKeyDown={radioKeys} className={cn("flex w-full rounded-full bg-muted p-0.5", className)}>+ {options.map((o) => {+ const off = note.isUnavailable(o);+ return (+ <button+ key={String(o.value)}+ type="button"+ role="radio"+ aria-checked={checked(o)}+ tabIndex={radioTab(stop === o.value)}+ {...note.optionProps(o)}+ onClick={() => note.press(o, onChange)}+ className={cn(+ "flex h-8 min-w-0 flex-1 items-center justify-center gap-1 rounded-full px-2 text-[13px] font-medium whitespace-nowrap text-muted-foreground transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring",+ off ? UNAVAILABLE_OPTION : "hover:text-foreground",+ checked(o) && "bg-background text-foreground shadow-soft",+ )}+ >+ {o.label}+ {o.hint && <span className="hidden text-[11px] font-normal text-muted-foreground sm:inline">{o.hint}</span>}+ </button>+ );+ })}+ </div>+ <UnavailableNote {...note.noteProps} />+ </>);}diff --git a/src/components/ui/unavailable.tsx b/src/components/ui/unavailable.tsxnew file mode 100644index 00000000..7a6da019--- /dev/null+++ b/src/components/ui/unavailable.tsx@@ -0,0 +1,89 @@+"use client";++import { Info } from "lucide-react";+import { useId, useState } from "react";+import { pressOption, runFix, unavailableOf, type Unavailable } from "@/lib/unavailable";+import { cn } from "@/lib/utils";++/*+ * Choices the current model or mode can't do (src/lib/unavailable.ts): every picker shows them the same way.+ *+ * - The option stays in view, muted, with a not-allowed cursor and aria-disabled (never `disabled`, so it can still be+ * focused and pressed). Hover and press never light it, and it is never drawn as the picked one.+ * - Pressing it picks nothing. A short note under the picker says why, with the way to get it ("Switch").+ * - The note goes away when something else is picked, when its fix runs, or once the choice can be picked again.+ *+ * Use: `const note = useUnavailableNote(options)`; on each option `onClick={() => note.press(o, onChange)}`,+ * `{...note.optionProps(o)}` and `className={cn(base, note.isUnavailable(o) && UNAVAILABLE_OPTION)}`; after the+ * picker `<UnavailableNote {...note.noteProps} />`.+ */++/** An option the current setup can't do: muted, not-allowed, and no hover light (its own fill stays as it is). */+export const UNAVAILABLE_OPTION =+ "cursor-not-allowed text-muted-foreground opacity-45 shadow-none hover:text-muted-foreground";++type Opt<T> = { value: T; unavailable?: Unavailable | false | null; disabled?: boolean; title?: string };++/** The note's state for one picker: which unavailable option was pressed, and its words while it still applies. */+export function useUnavailableNote<T>(options: readonly Opt<T>[]) {+ const id = useId();+ const [said, setSaid] = useState<{ value: T } | null>(null);+ const option = said ? options.find((o) => Object.is(o.value, said.value)) : undefined;+ // Read again from the current options: once the setup can do it, the note is gone by itself.+ const reason = option ? unavailableOf(option) : undefined;+ const close = () => setSaid(null);+ return {+ /** The reason being said (undefined: no note). */+ reason,+ isUnavailable: (o: Opt<T>) => !!unavailableOf(o),+ /** An available option is picked (and the note closes); an unavailable one only opens its note. */+ press: (o: Opt<T>, pick: (v: T) => void) =>+ pressOption(+ o,+ (v) => {+ close();+ pick(v);+ },+ (v) => setSaid({ value: v }),+ ),+ /** ARIA and the tooltip for an option. */+ optionProps: (o: Opt<T>) => {+ const u = unavailableOf(o);+ if (!u) return { title: o.title };+ return {+ "aria-disabled": true as const,+ title: u.why,+ ...(reason && option && Object.is(option.value, o.value) ? { "aria-describedby": id } : {}),+ };+ },+ noteProps: { id, reason, onClose: close },+ };+}++/** The note under a picker: why the pressed choice can't be had now, and the way to get it. */+export function UnavailableNote({ id, reason, onClose, className }: { id?: string; reason: Unavailable | undefined; onClose: () => void; className?: string }) {+ if (!reason) return null;+ return (+ <p+ id={id}+ role="status"+ className={cn(+ "mt-1.5 flex w-full basis-full items-center gap-2 rounded-xl bg-muted/60 py-1.5 pr-1.5 pl-2.5 text-[12px] leading-snug text-pretty text-muted-foreground",+ "motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-top-1",+ className,+ )}+ >+ <Info className="size-3.5 shrink-0 text-brand-text" aria-hidden />+ <span className="min-w-0 flex-1">{reason.why}</span>+ {reason.fix && (+ <button+ type="button"+ onClick={() => runFix(reason, onClose)}+ className="inline-flex h-7 shrink-0 items-center rounded-full bg-brand-faint px-3 text-[12px] font-medium text-brand-text transition-colors outline-none hover:bg-brand-faint-hover focus-visible:ring-2 focus-visible:ring-ring max-sm:h-8"+ >+ {reason.fix.label}+ </button>+ )}+ </p>+ );+}diff --git a/src/lib/catalog/genjutsu.ts b/src/lib/catalog/genjutsu.tsindex c5a13a6f..7d8a0e83 100644--- a/src/lib/catalog/genjutsu.ts+++ b/src/lib/catalog/genjutsu.ts@@ -17,6 +17,7 @@* comfyui-oss-4.md §c.*/import { keepOffered } from "@/lib/model-access";+import { listWords } from "@/lib/unavailable";import { silenceRef } from "./canvas";import {anchorAspect,@@ -1072,6 +1073,81 @@ export function resolutionWords(m: Maker, quality: string): string | undefined {return px(res) > px(quality) ? `renders ${res} (its lowest)` : `renders up to ${res}`;}+/** Where a resolution the picked model can't render can be had: its other Quality tier, or another model in the list. */+export interface ResolutionRoute {+ /** The model in the picker to switch to (undefined: keep the one picked). */+ pick?: string;+ /** The Quality tier to switch to (undefined: keep it). */+ tier?: GenjutsuTier;+ /** The resolution asked for there. */+ quality: GenjutsuQuality;+ /** Its name in words: "High quality", "MiniMax H3", "Fuobe Genjutsu on High quality". */+ words: string;+}++/** One resolution in the picker: the picked model renders it, or why not (plain words) and the way to get it. */+export interface ResolutionChoice {+ quality: GenjutsuQuality;+ ok: boolean;+ why?: string;+ route?: ResolutionRoute;+}++const tierWords = (t: GenjutsuTier | undefined) => (t === "high" ? "High quality" : "Standard quality");++/**+ * The picker's resolutions for the picked model: the ones it renders are open; for each other one, the nearest way to+ * get it (the same model's other tier first, then the other models in the list, each at the tier picked, then at its+ * other tier), said in plain words. Resolutions with the same way are said together ("720p and 1080p need MiniMax+ * H3"). One that no model here renders names the sharpest there is instead.+ */+export function resolutionChoices(+ maker: Maker,+ options: Maker[],+ tier: GenjutsuTier,+ on: (id: string) => boolean = () => true,+ qualities: readonly GenjutsuQuality[] = GENJUTSU.qualities,+): ResolutionChoice[] {+ const renders = (m: Maker, q: string) => qualityFor(m, q) === q;+ type Way = { m: Maker; pick?: string; tier?: GenjutsuTier; words: string };+ const ways: Way[] = [];+ const add = (w: Way) => {+ if (on(w.m.id) && !ways.some((x) => x.m.id === w.m.id) && w.m.id !== maker.id) ways.push(w);+ };+ const other = maker.pair ? getMaker(maker.pair, maker.engine) : undefined;+ if (other) add({ m: other, tier: other.tier, words: tierWords(other.tier) });+ for (const o of options) {+ if (o.id === maker.id || o.id === maker.pair) continue;+ const pair = o.pair ? getMaker(o.pair, o.engine) : undefined;+ const atTier = pair && o.tier !== tier ? pair : o;+ const offTier = pair ? (atTier === o ? pair : o) : undefined;+ add({ m: atTier, pick: o.id, words: o.label });+ if (offTier) add({ m: offTier, pick: o.id, tier: offTier.tier, words: `${o.label} on ${tierWords(offTier.tier)}` });+ }+ const sharpest = [...qualities].sort((a, b) => px(b) - px(a)).find((q) => renders(maker, q) || ways.some((w) => renders(w.m, q)));++ const rows = qualities.map((q) => {+ if (renders(maker, q)) return { quality: q, ok: true as const };+ const way = ways.find((w) => renders(w.m, q));+ if (way) return { quality: q, ok: false as const, key: `to:${way.m.id}`, way, at: q };+ // No model here renders it: the sharpest there is, and where (none: the picked model already is the sharpest).+ const best = sharpest && !renders(maker, sharpest) ? ways.find((w) => renders(w.m, sharpest)) : undefined;+ return { quality: q, ok: false as const, key: `none:${best?.m.id ?? ""}`, way: best, at: sharpest, none: true };+ });++ return rows.map((r) => {+ if (r.ok) return { quality: r.quality, ok: true };+ const same = rows.filter((x) => !x.ok && x.key === r.key).map((x) => x.quality);+ const route = r.way && r.at ? { pick: r.way.pick, tier: r.way.tier, quality: r.at, words: r.way.words } : undefined;+ let why: string;+ if (!("none" in r)) why = `${listWords(same)} ${same.length > 1 ? "need" : "needs"} ${r.way!.words}`;+ else if (!maker.qualities?.length && !route) why = `${maker.label} ${maker.renders ?? "keeps your clip's size"}`;+ else if (route) why = `No model here renders ${listWords(same)} yet · the sharpest is ${route.quality}, with ${route.words}`;+ else why = `No model here renders ${listWords(same)} yet · ${sharpest ?? qualityFor(maker, r.quality) ?? ""} is the sharpest`;+ return { quality: r.quality, ok: false, why, route };+ });+}+// ---------------------------------------------------------------------------// Wordsdiff --git a/src/lib/unavailable.ts b/src/lib/unavailable.tsnew file mode 100644index 00000000..46f1a8e2--- /dev/null+++ b/src/lib/unavailable.ts@@ -0,0 +1,55 @@+/**+ * One rule for every choice the current model or mode can't do (a resolution, a quality, a length, a mode):+ * it stays in view, looks clearly unavailable, and pressing it says why in plain words and offers the way to get it.+ * Nothing is hidden and nothing is refused without a word.+ */++/** Why a choice can't be picked now, and the one step that makes it possible (when there is one). */+export interface Unavailable {+ /** Plain words, no full stop: "720p and 1080p need MiniMax H3". */+ why: string;+ /** The way to get it: a short verb ("Switch", "Use 720p") and what it does. */+ fix?: { label: string; run: () => void };+}++/** The words said for a turned-off choice that came without its own reason. */+export const UNAVAILABLE_FALLBACK = "Not available with this setup";++/**+ * An option's unavailable state: its own `unavailable`, else a plain `disabled` (older call sites) read the same way,+ * with its `title` as the reason.+ */+export function unavailableOf(o: { unavailable?: Unavailable | false | null; disabled?: boolean; title?: string }): Unavailable | undefined {+ if (o.unavailable) return o.unavailable;+ if (o.disabled) return { why: o.title?.trim() || UNAVAILABLE_FALLBACK };+ return undefined;+}++/**+ * What pressing an option does: an available one is picked; an unavailable one is never picked, and its reason is+ * said instead (the caller shows the note with the way to get it).+ */+export function pressOption<T>(o: { value: T; unavailable?: Unavailable | false | null; disabled?: boolean; title?: string }, pick: (v: T) => void, say: (v: T, u: Unavailable) => void): void {+ const u = unavailableOf(o);+ if (u) say(o.value, u);+ else pick(o.value);+}++/**+ * The note's fix, run: the step itself, then the note closes. Kept apart so a test can run it without a page.+ */+export function runFix(u: Unavailable, close: () => void): void {+ u.fix?.run();+ close();+}++/** "720p", "720p and 1080p", "720p, 1080p and 2K". */+export function listWords(items: string[]): string {+ if (items.length <= 1) return items[0] ?? "";+ return `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;+}++/** The ARIA a choice gets when it can't be picked: still focusable and pressable (to hear why), never `disabled`. */+export function unavailableAria(u: Unavailable | undefined): { "aria-disabled"?: true } {+ return u ? { "aria-disabled": true } : {};+}diff --git a/tests/unavailable-option.test.ts b/tests/unavailable-option.test.tsnew file mode 100644index 00000000..3d7eb3e2--- /dev/null+++ b/tests/unavailable-option.test.ts@@ -0,0 +1,139 @@+import { createElement } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { describe, expect, it, vi } from "vitest";+import { Segmented } from "@/components/shorts/ui";+import { UnavailableNote } from "@/components/ui/unavailable";+import { getMaker, makersFor, MOTION_H3, ORIGINALS, resolutionChoices } from "@/lib/catalog/genjutsu";+import { listWords, pressOption, runFix, unavailableOf, UNAVAILABLE_FALLBACK } from "@/lib/unavailable";++/*+ * One rule for every choice the current model or mode can't do (src/lib/unavailable.ts, src/components/ui/unavailable.tsx):+ * it stays in view, looks unavailable, is never drawn as picked, and pressing it says why with the way to get it.+ */++describe("unavailable choices", () => {+ it("reads a plain disabled option the same way, with its title as the reason", () => {+ expect(unavailableOf({ disabled: true, title: "Above the clip's own frame rate" })).toEqual({ why: "Above the clip's own frame rate" });+ expect(unavailableOf({ disabled: true })).toEqual({ why: UNAVAILABLE_FALLBACK });+ expect(unavailableOf({ title: "x" })).toBeUndefined();+ expect(unavailableOf({ unavailable: false })).toBeUndefined();+ });++ it("picks an available option and only explains an unavailable one", () => {+ const pick = vi.fn();+ const say = vi.fn();+ pressOption({ value: "480p" }, pick, say);+ expect(pick).toHaveBeenCalledWith("480p");+ pressOption({ value: "1080p", unavailable: { why: "1080p needs MiniMax H3" } }, pick, say);+ expect(pick).toHaveBeenCalledTimes(1);+ expect(say).toHaveBeenCalledWith("1080p", { why: "1080p needs MiniMax H3" });+ });++ it("runs the note's Switch, then closes the note", () => {+ const order: string[] = [];+ runFix({ why: "720p needs High quality", fix: { label: "Switch", run: () => order.push("switch") } }, () => order.push("close"));+ expect(order).toEqual(["switch", "close"]);+ });++ it("says lists in plain words", () => {+ expect(listWords(["720p"])).toBe("720p");+ expect(listWords(["720p", "1080p"])).toBe("720p and 1080p");+ expect(listWords(["720p", "1080p", "2K"])).toBe("720p, 1080p and 2K");+ });+});++describe("Segmented with a choice the model can't do", () => {+ const html = renderToStaticMarkup(+ createElement(Segmented<string>, {+ label: "Resolution",+ // The remembered value is one the model can't render: it is not drawn as picked.+ value: "1080p",+ onChange: () => {},+ options: [+ { value: "480p", label: "480p" },+ { value: "720p", label: "720p", unavailable: { why: "720p needs High quality" } },+ { value: "1080p", label: "1080p", disabled: true, title: "No model here renders 1080p yet" },+ ],+ }),+ );+ const button = (label: string) => html.match(new RegExp(`<button[^>]*>${label}</button>`))![0];++ it("keeps every option in view, focusable and pressable (never the disabled attribute)", () => {+ for (const l of ["480p", "720p", "1080p"]) expect(button(l)).not.toMatch(/\sdisabled=""/);+ });++ it("marks unavailable options aria-disabled, muted, not-allowed, with no hover light", () => {+ for (const l of ["720p", "1080p"]) {+ const b = button(l);+ expect(b).toContain('aria-disabled="true"');+ expect(b).toContain("cursor-not-allowed");+ expect(b).toContain("opacity-45");+ expect(b).not.toContain("hover:text-foreground");+ expect(b).not.toContain("bg-background text-foreground");+ }+ expect(button("720p")).toContain('title="720p needs High quality"');+ expect(button("480p")).not.toContain("aria-disabled");+ });++ it("never draws an unavailable value as the picked one, and keeps a Tab stop on one that can be picked", () => {+ expect(button("1080p")).toContain('aria-checked="false"');+ expect(button("480p")).toContain('tabindex="0"');+ expect(html).not.toContain('aria-checked="true"');+ });++ it("shows no note until one is pressed, and the note carries the Switch", () => {+ expect(html).not.toContain('role="status"');+ const note = renderToStaticMarkup(createElement(UnavailableNote, { reason: { why: "720p and 1080p need MiniMax H3", fix: { label: "Switch", run: () => {} } }, onClose: () => {} }));+ expect(note).toContain('role="status"');+ expect(note).toContain("720p and 1080p need MiniMax H3");+ expect(note).toMatch(/<button[^>]*>Switch<\/button>/);+ });+});++describe("Genjutsu resolutions for the picked model", () => {+ const options = makersFor("open", "motion");+ const lite = getMaker(ORIGINALS.motionLite, "open")!;+ const full = getMaker(ORIGINALS.motion, "open")!;+ const h3 = getMaker(MOTION_H3, "open")!;++ it("Motion transfer on Genjutsu Standard: 480p open, 720p one tap away on High, 1080p names the sharpest", () => {+ const [p480, p720, p1080] = resolutionChoices(lite, options, "standard");+ expect(p480).toEqual({ quality: "480p", ok: true });+ expect(p720).toMatchObject({ ok: false, why: "720p needs High quality", route: { pick: undefined, tier: "high", quality: "720p" } });+ expect(p1080).toMatchObject({ ok: false, why: "No model here renders 1080p yet · the sharpest is 720p, with High quality", route: { tier: "high", quality: "720p" } });+ });++ it("goes to another model when the other tier is switched off", () => {+ const on = (id: string) => id !== full.id;+ const [, p720] = resolutionChoices(lite, options, "standard", on);+ expect(p720).toMatchObject({ ok: false, why: "720p needs MiniMax H3", route: { pick: h3.id, quality: "720p" } });+ expect(p720.route?.tier).toBeUndefined();+ });++ it("offers no Switch when the picked model already is the sharpest", () => {+ const [p480, p720, p1080] = resolutionChoices(h3, options, "standard");+ expect([p480.ok, p720.ok]).toEqual([true, true]);+ expect(p1080).toEqual({ quality: "1080p", ok: false, why: "No model here renders 1080p yet · 720p is the sharpest", route: undefined });+ });++ it("the Switch keeps the rest of the setup: it only names the model, the tier and the resolution", () => {+ const calls: unknown[] = [];+ const [, p720] = resolutionChoices(lite, options, "standard");+ const route = p720.route!;+ runFix(+ {+ why: p720.why!,+ fix: {+ label: "Switch",+ run: () => {+ if (route.pick) calls.push(["pick", route.pick]);+ if (route.tier) calls.push(["tier", route.tier]);+ calls.push(["quality", route.quality]);+ },+ },+ },+ () => calls.push("close"),+ );+ expect(calls).toEqual([["tier", "high"], ["quality", "720p"], "close"]);+ });+});