Add Prompt Builder sets/framing and harden mobile draft look settings.
Sets and beats filter by shot size; scenes reorder/delete; portrait links Prompt Builder; landscape queue collapses; per-engine look settings and prompt Clear persist across iOS resumes.
This commit is contained in:
+188
-9
@@ -18,11 +18,37 @@ export type PromptSequenceCharacterState = {
|
||||
outfitId: string | null
|
||||
}
|
||||
|
||||
export type PromptSequenceShotSize = '' | 'wide' | 'medium' | 'close-up' | 'detail'
|
||||
|
||||
export const PROMPT_SEQUENCE_SHOT_SIZES = ['wide', 'medium', 'close-up', 'detail'] as const
|
||||
|
||||
export type PromptSequenceBeat = {
|
||||
id: string
|
||||
name: string
|
||||
text: string
|
||||
/** Empty = always include for any shot size. */
|
||||
framings: Array<'wide' | 'medium' | 'close-up' | 'detail'>
|
||||
}
|
||||
|
||||
export type PromptSequenceSet = {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
beats: PromptSequenceBeat[]
|
||||
}
|
||||
|
||||
export type PromptSequenceSetState = {
|
||||
setId: string
|
||||
on: boolean
|
||||
}
|
||||
|
||||
export type PromptSequenceScene = {
|
||||
id: string
|
||||
title: string
|
||||
style: string
|
||||
settings: string
|
||||
shotSize: PromptSequenceShotSize
|
||||
setStates: PromptSequenceSetState[]
|
||||
characterStates: PromptSequenceCharacterState[]
|
||||
prompt: string
|
||||
}
|
||||
@@ -31,6 +57,7 @@ export type PromptSequence = {
|
||||
id: string
|
||||
name: string
|
||||
characters: PromptSequenceCharacter[]
|
||||
sets: PromptSequenceSet[]
|
||||
scenes: PromptSequenceScene[]
|
||||
createdAt: number
|
||||
updatedAt: number
|
||||
@@ -55,16 +82,34 @@ export function emptyCharacter(): PromptSequenceCharacter {
|
||||
return { id: newId(), name: '', description: '', outfits: [] }
|
||||
}
|
||||
|
||||
export function emptyBeat(): PromptSequenceBeat {
|
||||
return { id: newId(), name: '', text: '', framings: [] }
|
||||
}
|
||||
|
||||
export function emptySet(): PromptSequenceSet {
|
||||
return { id: newId(), name: '', description: '', beats: [emptyBeat()] }
|
||||
}
|
||||
|
||||
export function defaultCharacterState(characterId: string, on = true): PromptSequenceCharacterState {
|
||||
return { characterId, on, outfitId: null }
|
||||
}
|
||||
|
||||
export function emptyScene(index = 1, characters: PromptSequenceCharacter[] = []): PromptSequenceScene {
|
||||
export function defaultSetState(setId: string, on = true): PromptSequenceSetState {
|
||||
return { setId, on }
|
||||
}
|
||||
|
||||
export function emptyScene(
|
||||
index = 1,
|
||||
characters: PromptSequenceCharacter[] = [],
|
||||
sets: PromptSequenceSet[] = []
|
||||
): PromptSequenceScene {
|
||||
return {
|
||||
id: newId(),
|
||||
title: `Scene ${Math.max(1, index)}`,
|
||||
style: '',
|
||||
settings: '',
|
||||
shotSize: '',
|
||||
setStates: sets.map(set => defaultSetState(set.id, true)),
|
||||
characterStates: characters.map(character => defaultCharacterState(character.id, true)),
|
||||
prompt: ''
|
||||
}
|
||||
@@ -76,6 +121,11 @@ export function cloneSceneForNext(previous: PromptSequenceScene, nextIndex: numb
|
||||
title: `Scene ${nextIndex}`,
|
||||
style: previous.style,
|
||||
settings: previous.settings,
|
||||
shotSize: previous.shotSize || '',
|
||||
setStates: (previous.setStates || []).map(state => ({
|
||||
setId: state.setId,
|
||||
on: !!state.on
|
||||
})),
|
||||
characterStates: (previous.characterStates || []).map(state => ({
|
||||
characterId: state.characterId,
|
||||
on: !!state.on,
|
||||
@@ -110,6 +160,38 @@ export function formatCharacterLine(
|
||||
return `${base}. Outfit: ${outfitText}`
|
||||
}
|
||||
|
||||
export function beatMatchesShotSize(
|
||||
beat: { framings?: string[] },
|
||||
shotSize: string = ''
|
||||
) {
|
||||
const framings = Array.isArray(beat.framings) ? beat.framings.filter(Boolean) : []
|
||||
if (!framings.length) return true
|
||||
if (!shotSize) return true
|
||||
return framings.includes(shotSize)
|
||||
}
|
||||
|
||||
/** Set description + matching beat texts (one per line). No set/beat names or framing tags. */
|
||||
export function assembleSetBlock(
|
||||
scene: { shotSize?: string; setStates?: PromptSequenceSetState[] },
|
||||
sets: PromptSequenceSet[] = []
|
||||
) {
|
||||
const states = scene.setStates || []
|
||||
const stateById = new Map(states.map(state => [state.setId, state]))
|
||||
const chunks: string[] = []
|
||||
for (const set of sets) {
|
||||
const state = stateById.get(set.id)
|
||||
if (state && !state.on) continue
|
||||
const description = String(set.description || '').trim()
|
||||
const beatLines = (set.beats || [])
|
||||
.filter(beat => beatMatchesShotSize(beat, scene.shotSize || ''))
|
||||
.map(beat => String(beat.text || '').trim())
|
||||
.filter(Boolean)
|
||||
const lines = [description, ...beatLines].filter(Boolean)
|
||||
if (lines.length) chunks.push(lines.join('\n'))
|
||||
}
|
||||
return chunks.join('\n')
|
||||
}
|
||||
|
||||
export function resolveSceneCharacterLines(
|
||||
scene: { characterStates?: PromptSequenceCharacterState[] },
|
||||
characters: PromptSequenceCharacter[] = []
|
||||
@@ -119,7 +201,6 @@ export function resolveSceneCharacterLines(
|
||||
return characters
|
||||
.map((character) => {
|
||||
const state = stateById.get(character.id)
|
||||
// Missing state (legacy) => on
|
||||
if (state && !state.on) return ''
|
||||
const outfitId = state?.outfitId || null
|
||||
const outfit = outfitId
|
||||
@@ -135,12 +216,18 @@ export function assembleSceneText(
|
||||
style?: string
|
||||
settings?: string
|
||||
prompt?: string
|
||||
shotSize?: string
|
||||
setStates?: PromptSequenceSetState[]
|
||||
characterStates?: PromptSequenceCharacterState[]
|
||||
/** Legacy per-scene characters (migration / old tests). */
|
||||
characters?: Array<{ name?: string; description?: string }>
|
||||
},
|
||||
sequenceCharacters?: PromptSequenceCharacter[]
|
||||
sequenceCharacters?: PromptSequenceCharacter[],
|
||||
sequenceSets?: PromptSequenceSet[]
|
||||
) {
|
||||
const setBlock = sequenceSets?.length
|
||||
? assembleSetBlock(scene, sequenceSets)
|
||||
: ''
|
||||
const characterBlock = sequenceCharacters?.length
|
||||
? resolveSceneCharacterLines(scene, sequenceCharacters).join('\n')
|
||||
: (scene.characters || [])
|
||||
@@ -150,6 +237,7 @@ export function assembleSceneText(
|
||||
const parts = [
|
||||
String(scene.style || '').trim(),
|
||||
String(scene.settings || '').trim(),
|
||||
setBlock,
|
||||
characterBlock,
|
||||
String(scene.prompt || '').trim()
|
||||
].filter(Boolean)
|
||||
@@ -163,17 +251,25 @@ export function assembleSceneText(
|
||||
*/
|
||||
export function assembleSequenceText(sequence: {
|
||||
characters?: PromptSequenceCharacter[]
|
||||
sets?: PromptSequenceSet[]
|
||||
scenes?: Array<{
|
||||
style?: string
|
||||
settings?: string
|
||||
prompt?: string
|
||||
shotSize?: string
|
||||
setStates?: PromptSequenceSetState[]
|
||||
characterStates?: PromptSequenceCharacterState[]
|
||||
characters?: Array<{ name?: string; description?: string }>
|
||||
}>
|
||||
}) {
|
||||
const characters = sequence.characters || []
|
||||
const sets = sequence.sets || []
|
||||
return (sequence.scenes || [])
|
||||
.map(scene => assembleSceneText(scene, characters.length ? characters : undefined))
|
||||
.map(scene => assembleSceneText(
|
||||
scene,
|
||||
characters.length ? characters : undefined,
|
||||
sets.length ? sets : undefined
|
||||
))
|
||||
.filter(Boolean)
|
||||
.join('\n\n\n')
|
||||
}
|
||||
@@ -191,6 +287,12 @@ export function normalizePromptSequenceTitle(raw: unknown, fallback: string) {
|
||||
return title || fallback
|
||||
}
|
||||
|
||||
export function normalizeShotSize(raw: unknown): PromptSequenceShotSize {
|
||||
const value = String(raw || '').trim()
|
||||
if (value === 'wide' || value === 'medium' || value === 'close-up' || value === 'detail') return value
|
||||
return ''
|
||||
}
|
||||
|
||||
export function normalizeOutfit(raw: unknown): PromptSequenceOutfit {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
return {
|
||||
@@ -211,6 +313,32 @@ export function normalizeCharacter(raw: unknown): PromptSequenceCharacter {
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeBeat(raw: unknown): PromptSequenceBeat {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
const framings = Array.isArray(rec.framings)
|
||||
? [...new Set(rec.framings.map(item => String(item || '').trim()).filter((item): item is 'wide' | 'medium' | 'close-up' | 'detail' =>
|
||||
item === 'wide' || item === 'medium' || item === 'close-up' || item === 'detail'
|
||||
))]
|
||||
: []
|
||||
return {
|
||||
id: String(rec.id || '').trim() || newId(),
|
||||
name: String(rec.name || '').trim().slice(0, 120),
|
||||
text: normalizePromptSequenceField(rec.text),
|
||||
framings
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeSet(raw: unknown): PromptSequenceSet {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
const beats = Array.isArray(rec.beats) ? rec.beats.map(normalizeBeat) : []
|
||||
return {
|
||||
id: String(rec.id || '').trim() || newId(),
|
||||
name: String(rec.name || '').trim().slice(0, 120),
|
||||
description: normalizePromptSequenceField(rec.description),
|
||||
beats: beats.length ? beats : [emptyBeat()]
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeCharacterState(raw: unknown, fallbackCharacterId = ''): PromptSequenceCharacterState {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
const characterId = String(rec.characterId || fallbackCharacterId || '').trim()
|
||||
@@ -223,6 +351,14 @@ export function normalizeCharacterState(raw: unknown, fallbackCharacterId = ''):
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeSetState(raw: unknown, fallbackSetId = ''): PromptSequenceSetState {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
return {
|
||||
setId: String(rec.setId || fallbackSetId || '').trim(),
|
||||
on: rec.on === undefined ? true : !!rec.on
|
||||
}
|
||||
}
|
||||
|
||||
function liftLegacyCharacters(scenesRaw: unknown[]): PromptSequenceCharacter[] {
|
||||
const byId = new Map<string, PromptSequenceCharacter>()
|
||||
for (const scene of scenesRaw) {
|
||||
@@ -261,10 +397,27 @@ function syncCharacterStates(
|
||||
})
|
||||
}
|
||||
|
||||
function syncSetStates(
|
||||
statesRaw: unknown,
|
||||
sets: PromptSequenceSet[],
|
||||
defaultOn = true
|
||||
): PromptSequenceSetState[] {
|
||||
const incoming = Array.isArray(statesRaw)
|
||||
? statesRaw.map(state => normalizeSetState(state)).filter(state => state.setId)
|
||||
: []
|
||||
const byId = new Map(incoming.map(state => [state.setId, state]))
|
||||
return sets.map((set) => {
|
||||
const existing = byId.get(set.id)
|
||||
if (existing) return { setId: set.id, on: existing.on }
|
||||
return defaultSetState(set.id, defaultOn)
|
||||
})
|
||||
}
|
||||
|
||||
export function normalizeScene(
|
||||
raw: unknown,
|
||||
index: number,
|
||||
characters: PromptSequenceCharacter[] = []
|
||||
characters: PromptSequenceCharacter[] = [],
|
||||
sets: PromptSequenceSet[] = []
|
||||
): PromptSequenceScene {
|
||||
const rec = (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
||||
return {
|
||||
@@ -272,6 +425,8 @@ export function normalizeScene(
|
||||
title: normalizePromptSequenceTitle(rec.title, `Scene ${index + 1}`),
|
||||
style: normalizePromptSequenceField(rec.style),
|
||||
settings: normalizePromptSequenceField(rec.settings),
|
||||
shotSize: normalizeShotSize(rec.shotSize),
|
||||
setStates: syncSetStates(rec.setStates, sets, true),
|
||||
characterStates: syncCharacterStates(rec.characterStates, characters, true),
|
||||
prompt: normalizePromptSequenceField(rec.prompt)
|
||||
}
|
||||
@@ -287,14 +442,16 @@ export function normalizePromptSequence(raw: unknown): PromptSequence | null {
|
||||
? rec.characters.map(normalizeCharacter)
|
||||
: liftLegacyCharacters(scenesRaw)
|
||||
if (!characters.length) characters = [emptyCharacter()]
|
||||
const sets = Array.isArray(rec.sets) ? rec.sets.map(normalizeSet) : []
|
||||
const scenes = scenesRaw.length
|
||||
? scenesRaw.map((scene, index) => normalizeScene(scene, index, characters))
|
||||
: [emptyScene(1, characters)]
|
||||
? scenesRaw.map((scene, index) => normalizeScene(scene, index, characters, sets))
|
||||
: [emptyScene(1, characters, sets)]
|
||||
const createdAt = Number(rec.createdAt) || Date.now()
|
||||
return {
|
||||
id: String(rec.id || '').trim() || newId(),
|
||||
name,
|
||||
characters,
|
||||
sets,
|
||||
scenes,
|
||||
createdAt,
|
||||
updatedAt: Number(rec.updatedAt) || createdAt
|
||||
@@ -307,7 +464,7 @@ export function ensureSceneStatesForCharacters(
|
||||
characters: PromptSequenceCharacter[],
|
||||
opts?: { newCharacterId?: string; turnOnSceneIndex?: number }
|
||||
) {
|
||||
const newId = opts?.newCharacterId
|
||||
const newCharacterId = opts?.newCharacterId
|
||||
const turnOnIndex = opts?.turnOnSceneIndex
|
||||
for (let i = 0; i < scenes.length; i++) {
|
||||
const scene = scenes[i]
|
||||
@@ -315,10 +472,32 @@ export function ensureSceneStatesForCharacters(
|
||||
scene.characterStates = characters.map((character) => {
|
||||
const existing = byId.get(character.id)
|
||||
if (existing) return existing
|
||||
const on = newId && character.id === newId
|
||||
const on = newCharacterId && character.id === newCharacterId
|
||||
? i === turnOnIndex
|
||||
: true
|
||||
return defaultCharacterState(character.id, on)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure every scene has a state row for every sequence set. */
|
||||
export function ensureSceneStatesForSets(
|
||||
scenes: PromptSequenceScene[],
|
||||
sets: PromptSequenceSet[],
|
||||
opts?: { newSetId?: string; turnOnSceneIndex?: number }
|
||||
) {
|
||||
const newSetId = opts?.newSetId
|
||||
const turnOnIndex = opts?.turnOnSceneIndex
|
||||
for (let i = 0; i < scenes.length; i++) {
|
||||
const scene = scenes[i]
|
||||
const byId = new Map((scene.setStates || []).map(state => [state.setId, state]))
|
||||
scene.setStates = sets.map((set) => {
|
||||
const existing = byId.get(set.id)
|
||||
if (existing) return existing
|
||||
const on = newSetId && set.id === newSetId
|
||||
? i === turnOnIndex
|
||||
: true
|
||||
return defaultSetState(set.id, on)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user