Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion apps/website/e2e/workshop-apps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,49 @@ test('makes a Cinematic Studio grade palette from an uploaded image', async ({
'Your palette'
)
await page.getByRole('button', { name: 'Edit palette' }).click()
await expect(page.getByLabel(/^Color 1: #/)).toBeVisible()
await page.getByLabel(/^Color 1: #/).click()
const hex = page.getByRole('textbox', { name: 'Hex color' })
await hex.fill('#3b1b6e')
await hex.press('Enter')
await expect(page.getByLabel('Color 1: #3b1b6e')).toBeVisible()
await expect(page.getByRole('button', { name: /^Grade/ })).toContainText(
'Your palette'
)
})

test('offers the starting frame beside the Cinematic Studio scene in video mode', async ({
page,
context
}) => {
await mockFlags(context, { apps: true, workflows: false })
await page.goto('/hub/apps/cinematic-studio/')

await page.getByRole('button', { name: 'Video', exact: true }).click()

await expect(
page.getByRole('button', { name: 'Add a starting frame' })
).toBeVisible()
await expect(page.getByRole('heading', { name: 'References' })).toHaveCount(0)
})

test('@mobile keeps the Cinematic Studio camera badges to one line and the camera sheet steady across tabs', async ({
page,
context
}) => {
await mockFlags(context, { apps: true, workflows: false })
await page.goto('/hub/apps/cinematic-studio/')

const specs = page.getByTestId('camera-specs')
await expect(specs.getByText('+2', { exact: true })).toBeVisible()
await expect(specs.getByText('50mm', { exact: true })).toBeHidden()
expect((await specs.boundingBox())?.height).toBeLessThan(32)

await page.getByRole('button', { name: /^Camera/ }).click()
const sheet = page.getByRole('dialog', { name: 'Camera' })
const heights = []
for (const tab of ['Body', 'Lens', 'Focal length', 'Aperture']) {
await sheet.getByRole('button', { name: tab, exact: true }).click()
heights.push((await sheet.boundingBox())?.height)
}
expect(new Set(heights).size).toBe(1)
})
2 changes: 2 additions & 0 deletions apps/website/src/components/ui/button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const buttonVariants = cva(
'bg-primary-comfy-yellow text-primary-comfy-ink uppercase hover:bg-primary-comfy-yellow/90',
outline:
'border text-primary-comfy-yellow uppercase hover:bg-primary-comfy-yellow hover:text-primary-comfy-ink',
ghost:
'bg-transparency-white-t8 font-medium tracking-normal text-primary-warm-white hover:bg-transparency-white-t20',
link: "h-auto justify-start px-0 py-1 text-base text-primary-comfy-yellow uppercase hover:opacity-90 [&_svg:not([class*='size-'])]:size-6",
underlineLink:
"relative h-auto justify-start px-0 py-1 text-primary-comfy-yellow uppercase after:absolute after:bottom-0 after:left-0 after:h-0.5 after:w-full after:origin-left after:scale-x-0 after:bg-current after:transition-transform after:duration-200 hover:opacity-90 hover:after:scale-x-100 [&_svg:not([class*='size-'])]:size-6",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<script setup lang="ts">
import { clamp } from 'es-toolkit'
import { computed, ref, useTemplateRef, watch } from 'vue'

import type { Locale } from '../../../i18n/translations'
import type { Hsv } from '../../../lib/workshop/cinematic-studio/color-space'
import {
hexToHsv,
hsvToHex,
isHex
} from '../../../lib/workshop/cinematic-studio/color-space'
import { tc } from '../../../lib/workshop/cinematic-studio/copy'

const { locale = 'en' } = defineProps<{ locale?: Locale }>()

const color = defineModel<string>({ required: true })

const hsv = ref<Hsv>(hexToHsv(color.value))
const hexText = ref(color.value)
watch(color, (next) => {
if (next === hsvToHex(hsv.value)) return
hsv.value = hexToHsv(next)
hexText.value = next
})

function update(next: Hsv) {
hsv.value = next
color.value = hsvToHex(next)
hexText.value = color.value
}

const area = useTemplateRef<HTMLElement>('area')

function pick(event: PointerEvent) {
const box = area.value?.getBoundingClientRect()
if (!box) return
update({
...hsv.value,
s: clamp((event.clientX - box.left) / box.width, 0, 1),
v: 1 - clamp((event.clientY - box.top) / box.height, 0, 1)
})
}

function startPick(event: PointerEvent) {
area.value?.setPointerCapture(event.pointerId)
pick(event)
}

const STEP = 0.02
const KEYS: Readonly<Record<string, readonly [number, number]>> = {
ArrowLeft: [-STEP, 0],
ArrowRight: [STEP, 0],
ArrowUp: [0, STEP],
ArrowDown: [0, -STEP]
}

function nudge(event: KeyboardEvent) {
const step = KEYS[event.key]
if (!step) return
event.preventDefault()
update({
...hsv.value,
s: clamp(hsv.value.s + step[0], 0, 1),
v: clamp(hsv.value.v + step[1], 0, 1)
})
}

function setHue(event: Event) {
if (!(event.target instanceof HTMLInputElement)) return
update({ ...hsv.value, h: Number(event.target.value) })
}

function commitHex() {
const typed = hexText.value.trim()
const hex = (typed.startsWith('#') ? typed : `#${typed}`).toLowerCase()
if (isHex(hex)) update(hexToHsv(hex))
else hexText.value = color.value
}

const hueColor = computed(() => hsvToHex({ h: hsv.value.h, s: 1, v: 1 }))
</script>

<template>
<div class="flex flex-col gap-3">
<div
ref="area"
role="slider"
tabindex="0"
:aria-label="tc('cinematic.colors.shade', locale)"
aria-valuemin="0"
aria-valuemax="100"
:aria-valuenow="Math.round(hsv.s * 100)"
Comment thread
mariana953 marked this conversation as resolved.
Resolved
:aria-valuetext="color"
class="relative h-36 w-full cursor-crosshair touch-none rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-primary-comfy-yellow/60"
:style="{
backgroundColor: hueColor,
backgroundImage:
'linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent)'
}"
@pointerdown="startPick"
@pointermove="(event) => event.buttons && pick(event)"
@keydown="nudge"
Comment thread
mariana953 marked this conversation as resolved.
Resolved
>
<span
class="pointer-events-none absolute size-4 -translate-1/2 rounded-full border-2 border-white shadow-[0_0_0_1px_rgb(0_0_0/0.4)]"
:style="{
left: `${hsv.s * 100}%`,
top: `${(1 - hsv.v) * 100}%`,
backgroundColor: color
}"
aria-hidden="true"
/>
</div>
<input
type="range"
min="0"
max="360"
:value="Math.round(hsv.h)"
:aria-label="tc('cinematic.colors.hue', locale)"
class="h-3 w-full cursor-pointer appearance-none rounded-full bg-[linear-gradient(to_right,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00)] [&::-moz-range-thumb]:size-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-2 [&::-moz-range-thumb]:border-white [&::-moz-range-thumb]:bg-transparent [&::-webkit-slider-thumb]:size-4 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:border-2 [&::-webkit-slider-thumb]:border-white [&::-webkit-slider-thumb]:shadow-[0_0_0_1px_rgb(0_0_0/0.4)]"
@input="setHue"
/>
<label class="flex items-center gap-2">
<span
class="size-8 shrink-0 rounded-lg ring-1 ring-transparency-white-t20 ring-inset"
:style="{ backgroundColor: color }"
aria-hidden="true"
/>
<span class="sr-only">{{ tc('cinematic.colors.hex', locale) }}</span>
<input
v-model="hexText"
type="text"
spellcheck="false"
maxlength="7"
class="h-8 w-full rounded-lg bg-transparency-white-t4 px-2.5 font-mono text-sm text-primary-warm-white uppercase outline-none focus-visible:ring-1 focus-visible:ring-primary-comfy-yellow/60"
@change="commitHex"
@keydown.enter="commitHex"
/>
</label>
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,40 @@ describe('CinematicColors', () => {
expect(main.value).toBeUndefined()
})

it('edits the chosen swatch from the hex field', async () => {
const { colors, user } = renderColors(['#aa0000', '#00aa00'])
await user.click(screen.getByRole('button', { name: 'Color 2: #00aa00' }))
const hex = screen.getByRole('textbox', { name: 'Hex color' })
await user.clear(hex)
await user.type(hex, '3b1b6e{Enter}')
expect(colors.value).toEqual(['#aa0000', '#3b1b6e'])
})

it('keeps the color when the hex field holds no color', async () => {
const { colors, user } = renderColors(['#aa0000'])
const hex = screen.getByRole('textbox', { name: 'Hex color' })
await user.clear(hex)
await user.type(hex, 'nope{Enter}')
expect(colors.value).toEqual(['#aa0000'])
expect(hex).toHaveValue('#aa0000')
})

it('moves the shade square from the keyboard and reports its saturation', async () => {
const { colors, user } = renderColors(['#808080'])
const shade = screen.getByRole('slider', {
name: 'Saturation and brightness'
})
expect(shade).toHaveAttribute('aria-valuemin', '0')
expect(shade).toHaveAttribute('aria-valuemax', '100')
expect(shade).toHaveAttribute('aria-valuenow', '0')

shade.focus()
await user.keyboard('{ArrowRight}{ArrowRight}')

expect(shade).toHaveAttribute('aria-valuenow', '4')
expect(colors.value[0]).not.toBe('#808080')
})

it('clears every color', async () => {
const { colors, main, user } = renderColors(['#aa0000'], 0)
await user.click(screen.getByRole('button', { name: 'Clear colors' }))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<script setup lang="ts">
import { Plus, Star, X } from '@lucide/vue'
import { nextTick, useTemplateRef } from 'vue'
import { ref } from 'vue'

import { cn } from '@comfyorg/tailwind-utils'

import type { Locale } from '../../../i18n/translations'
import { MAX_COLORS } from '../../../lib/workshop/cinematic-studio/colors'
import { tc } from '../../../lib/workshop/cinematic-studio/copy'
import CinematicColorPicker from './CinematicColorPicker.vue'

const { locale = 'en' } = defineProps<{ locale?: Locale }>()

const colors = defineModel<readonly string[]>({ required: true })
const main = defineModel<number | undefined>('main')

const swatches = useTemplateRef<HTMLElement>('swatches')
const active = ref(0)

const t = (key: Parameters<typeof tc>[0]) => tc(key, locale)

Expand All @@ -23,17 +24,15 @@ function setColor(index: number, value: string) {

function remove(index: number) {
colors.value = colors.value.filter((_, at) => at !== index)
active.value = Math.min(active.value, colors.value.length - 1)
if (main.value === index) main.value = undefined
else if (main.value !== undefined && main.value > index) main.value -= 1
}

async function add() {
function add() {
if (colors.value.length >= MAX_COLORS) return
colors.value = [...colors.value, colors.value.at(-1) ?? '#808080']
await nextTick()
swatches.value
?.querySelectorAll<HTMLInputElement>('input[type="color"]')
[colors.value.length - 1]?.click()
active.value = colors.value.length - 1
}

function toggleMain(index: number) {
Expand All @@ -49,7 +48,7 @@ function clear() {
<template>
<section
:aria-label="t('cinematic.colors.title')"
class="flex flex-col gap-2 rounded-xl border border-transparency-white-t8 p-2.5"
class="flex flex-col gap-3 rounded-xl bg-transparency-white-t4 p-3"
>
<div class="flex items-center justify-between gap-2">
<span
Expand All @@ -69,25 +68,21 @@ function clear() {
</button>
</div>
</div>
<div ref="swatches" class="flex flex-wrap items-center gap-2">
<div class="flex flex-wrap items-center gap-2">
<div v-for="(color, index) in colors" :key="index" class="group relative">
<label
<button
type="button"
:class="
cn(
'block size-9 cursor-pointer rounded-lg ring-1 ring-transparency-white-t20 ring-inset focus-within:ring-2 focus-within:ring-primary-comfy-yellow',
main === index && 'ring-2 ring-primary-warm-white'
'block size-9 rounded-lg ring-1 ring-transparency-white-t20 transition-[box-shadow,transform] duration-150 outline-none ring-inset hover:scale-105 focus-visible:ring-2 focus-visible:ring-primary-comfy-yellow',
active === index && 'ring-2 ring-primary-warm-white'
)
"
:style="{ backgroundColor: color }"
>
<input
type="color"
:value="color"
class="sr-only"
:aria-label="`${t('cinematic.colors.color')} ${index + 1}: ${color}`"
@input="setColor(index, ($event.target as HTMLInputElement).value)"
/>
</label>
:aria-label="`${t('cinematic.colors.color')} ${index + 1}: ${color}`"
:aria-pressed="active === index"
@click="active = index"
/>
<button
type="button"
:class="
Expand Down Expand Up @@ -126,8 +121,12 @@ function clear() {
<Plus class="size-4" aria-hidden="true" />
</button>
</div>
<p class="text-xs text-primary-warm-gray">
{{ t('cinematic.colors.hint') }}
</p>
<CinematicColorPicker
v-if="colors[active]"
:model-value="colors[active]"
:locale
@update:model-value="setColor(active, $event)"
/>
<slot />
</section>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const showCost = computed(
const layout = computed(() =>
wide
? {
root: 'flex flex-col gap-2.5',
root: 'flex flex-col gap-2.5 text-center',
row: 'flex flex-col items-stretch gap-2',
button: 'w-full rounded-full px-5'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ import { cn } from '@comfyorg/tailwind-utils'
import type { Locale } from '../../../i18n/translations'
import { tc } from '../../../lib/workshop/cinematic-studio/copy'

const { disabled = false, locale = 'en' } = defineProps<{
const {
disabled = false,
compact = false,
locale = 'en'
} = defineProps<{
disabled?: boolean
compact?: boolean
locale?: Locale
}>()
const mode = defineModel<'image' | 'video'>({ required: true })
</script>

<template>
<div
class="flex gap-1 rounded-xl border border-transparency-white-t20 bg-primary-comfy-ink-light p-1"
:class="
cn(
'flex gap-1 rounded-xl border border-transparency-white-t20 bg-primary-comfy-ink-light p-1',
compact && 'gap-0.5 rounded-full border-transparency-white-t8 p-0.5'
)
"
role="group"
:aria-label="tc('cinematic.video.mode', locale)"
>
Expand All @@ -25,6 +35,7 @@ const mode = defineModel<'image' | 'video'>({ required: true })
:class="
cn(
'min-h-10 flex-1 rounded-lg px-5 text-sm font-semibold text-primary-warm-white transition-colors hover:bg-transparency-white-t8 disabled:opacity-50',
compact && 'min-h-7 rounded-full px-3 text-xs',
mode === option && 'bg-transparency-white-t20'
)
"
Expand Down
Loading
Loading