The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat(create): Wan-native sizes, an orientation flip and ratio chips (D#93)
purplea3ec682d3952
diff --git a/src/components/create/experimental/ParamGroups.tsx b/src/components/create/experimental/ParamGroups.tsxindex 7b94a1f7..725a1019 100644--- a/src/components/create/experimental/ParamGroups.tsx+++ b/src/components/create/experimental/ParamGroups.tsx@@ -1,4 +1,5 @@-import { Gauge, Boxes, FlaskConical, RotateCcw, HelpCircle } from 'lucide-react'+import { Gauge, Boxes, FlaskConical, RotateCcw, HelpCircle, RectangleHorizontal, RectangleVertical } from 'lucide-react'+import { VIDEO_RES_PRESETS, ASPECT_RATIOS, applyAspect, presetForOrientation, matchesPreset } from '../../../lib/create-resolution'import { useCreateStore } from '../../../stores/createStore'import { useCreateExp } from './CreateContext'import { cloudModelById, defaultCloudModel } from '../../../stores/cloudCatalogStore'@@ -66,6 +67,39 @@ export function ParamGroups() {<NumberField label="Width" value={s.width} min={64} max={4096} step={64} mono onChange={(v) => s.setSize(v, s.height)} suffix="px" /><NumberField label="Height" value={s.height} min={64} max={4096} step={64} mono onChange={(v) => s.setSize(s.width, v)} suffix="px" /></div>+ {/* D#93 (stasicby): Wan's native sizes as one-click chips, an+ orientation flip, and ratio chips that respend the current pixel+ budget. Everything just writes the same width/height fields. */}+ <div className="flex flex-wrap items-center gap-1 pt-1">+ {isVideo && VIDEO_RES_PRESETS.map((p) => (+ <button+ key={p.label}+ onClick={() => { const d = presetForOrientation(p, s.height > s.width); s.setSize(d.width, d.height) }}+ className={cn(+ 'px-1.5 py-0.5 rounded border t-control transition-colors',+ matchesPreset(s.width, s.height, p)+ ? 'border-white/20 bg-white/[0.08] text-gray-200'+ : 'border-white/[0.08] text-gray-400 hover:text-gray-200 hover:bg-white/[0.06]',+ )}+ >{p.label}</button>+ ))}+ <button+ aria-label="Swap orientation"+ title="Swap portrait and landscape"+ onClick={() => s.setSize(s.height, s.width)}+ className="px-1.5 py-0.5 rounded border border-white/[0.08] t-control text-gray-400 hover:text-gray-200 hover:bg-white/[0.06] transition-colors inline-flex items-center gap-1"+ >+ {s.height > s.width ? <RectangleVertical size={10} /> : <RectangleHorizontal size={10} />}+ flip+ </button>+ {ASPECT_RATIOS.map((r) => (+ <button+ key={r.label}+ onClick={() => { const d = applyAspect(s.width, s.height, r.w, r.h); s.setSize(d.width, d.height) }}+ className="px-1.5 py-0.5 rounded border border-white/[0.08] t-control text-gray-400 hover:text-gray-200 hover:bg-white/[0.06] transition-colors"+ >{r.label}</button>+ ))}+ </div></Section>{/* OUTPUT */}diff --git a/src/lib/__tests__/create-resolution.test.ts b/src/lib/__tests__/create-resolution.test.tsnew file mode 100644index 00000000..5559aaac--- /dev/null+++ b/src/lib/__tests__/create-resolution.test.ts@@ -0,0 +1,79 @@+// D#93 (stasicby): 480p one-side reachable, portrait/landscape one click,+// ratio switches that do not silently change the render cost.+import { readFileSync } from 'node:fs'+import { join } from 'node:path'+import { describe, it, expect } from 'vitest'+import {+ VIDEO_RES_PRESETS,+ ASPECT_RATIOS,+ applyAspect,+ presetForOrientation,+ matchesPreset,+} from '../create-resolution'++describe('video resolution presets', () => {+ it('offers exactly the Wan-native sizes from the report', () => {+ const sizes = VIDEO_RES_PRESETS.map((p) => `${p.width}x${p.height}`)+ expect(sizes).toContain('832x480')+ expect(sizes).toContain('720x480')+ expect(sizes).toContain('1280x720')+ })++ it('keeps the current orientation instead of flipping back to landscape', () => {+ const p = VIDEO_RES_PRESETS[0]+ expect(presetForOrientation(p, false)).toEqual({ width: 832, height: 480 })+ expect(presetForOrientation(p, true)).toEqual({ width: 480, height: 832 })+ })++ it('lights the chip in either orientation', () => {+ const p = VIDEO_RES_PRESETS[0]+ expect(matchesPreset(832, 480, p)).toBe(true)+ expect(matchesPreset(480, 832, p)).toBe(true)+ expect(matchesPreset(848, 480, p)).toBe(false)+ })+})++describe('aspect switching', () => {+ it('respends the same pixel budget within one grid cell', () => {+ for (const r of ASPECT_RATIOS) {+ const d = applyAspect(1024, 576, r.w, r.h)+ const before = 1024 * 576+ const after = d.width * d.height+ expect(Math.abs(after - before) / before).toBeLessThan(0.15)+ }+ })++ it('snaps to the 16 px grid every local family accepts', () => {+ for (const r of ASPECT_RATIOS) {+ const d = applyAspect(832, 480, r.w, r.h)+ expect(d.width % 16).toBe(0)+ expect(d.height % 16).toBe(0)+ }+ })++ it('1:1 of a 16:9 canvas lands on a square', () => {+ const d = applyAspect(1024, 576, 1, 1)+ expect(d.width).toBe(d.height)+ })++ it('never leaves the field bounds', () => {+ const tiny = applyAspect(64, 64, 16, 9)+ expect(tiny.height).toBeGreaterThanOrEqual(64)+ const huge = applyAspect(4096, 4096, 16, 9)+ expect(huge.width).toBeLessThanOrEqual(4096)+ })+})++describe('ParamGroups wiring (source guards)', () => {+ const src = readFileSync(join(__dirname, '../../components/create/experimental/ParamGroups.tsx'), 'utf8')++ it('renders presets only for video, flip and ratios for every intent', () => {+ expect(src).toContain('isVideo && VIDEO_RES_PRESETS.map')+ expect(src).toContain('aria-label="Swap orientation"')+ expect(src).toContain('ASPECT_RATIOS.map')+ })++ it('flip swaps the existing fields instead of inventing new state', () => {+ expect(src).toContain('s.setSize(s.height, s.width)')+ })+})diff --git a/src/lib/create-resolution.ts b/src/lib/create-resolution.tsnew file mode 100644index 00000000..4eec9ab9--- /dev/null+++ b/src/lib/create-resolution.ts@@ -0,0 +1,52 @@+// D#93 (stasicby): Wan's native training sizes were not reachable in one+// click, and there was no way to flip a video between portrait and landscape+// without retyping both fields. Pure math here, the UI just writes the same+// width/height the fields already own.++export interface ResPreset { label: string; width: number; height: number }++// Wan 2.1/2.2 train on exactly these (D#93): 480p in both flavours, and 720p.+export const VIDEO_RES_PRESETS: ResPreset[] = [+ { label: '480p', width: 832, height: 480 },+ { label: '480p 4:3', width: 720, height: 480 },+ { label: '720p', width: 1280, height: 720 },+]++export const ASPECT_RATIOS = [+ { label: '16:9', w: 16, h: 9 },+ { label: '9:16', w: 9, h: 16 },+ { label: '4:3', w: 4, h: 3 },+ { label: '3:4', w: 3, h: 4 },+ { label: '1:1', w: 1, h: 1 },+] as const++// Every local family accepts multiples of 16; finer grids (the latent 8) are+// a subset. Clamped to the same bounds as the NumberFields.+const GRID = 16+const snap = (v: number) => Math.min(4096, Math.max(64, Math.round(v / GRID) * GRID))++/** New dims in the given ratio, spending roughly the same pixel budget the+ * user has set, snapped to the grid. Changing the ratio must not silently+ * double the render cost. */+export function applyAspect(width: number, height: number, rw: number, rh: number): { width: number; height: number } {+ const area = width * height+ const w = Math.sqrt((area * rw) / rh)+ return { width: snap(w), height: snap((w * rh) / rw) }+}++/** A preset keeps the user's current orientation: picking 480p on a portrait+ * canvas gives 480x832, not a silent flip back to landscape. */+export function presetForOrientation(p: ResPreset, portrait: boolean): { width: number; height: number } {+ const long = Math.max(p.width, p.height)+ const short = Math.min(p.width, p.height)+ return portrait ? { width: short, height: long } : { width: long, height: short }+}++/** True when the current canvas is this preset in either orientation, so the+ * chip can light up without caring which way the video points. */+export function matchesPreset(width: number, height: number, p: ResPreset): boolean {+ return (+ (width === p.width && height === p.height) ||+ (width === p.height && height === p.width)+ )+}