key out gif backgrounds
This commit is contained in:
@@ -1,22 +1,61 @@
|
||||
<script module lang="ts">
|
||||
export type GifKeySettings = { enabled: boolean; color: string; tolerance: number }
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { GifBudgetMode, GifDither } from "./api"
|
||||
import Dropdown from "./ui/Dropdown.svelte"
|
||||
import Slider from "./ui/Slider.svelte"
|
||||
import Toggle from "./ui/Toggle.svelte"
|
||||
import { fadeMotion } from "./ui/motion"
|
||||
|
||||
let { budgetMode = $bindable(), dither = $bindable(), colors = $bindable(), disabled = false }: {
|
||||
budgetMode: GifBudgetMode; dither: GifDither; colors: number; disabled?: boolean
|
||||
let { budgetMode = $bindable(), dither = $bindable(), colors = $bindable(), colorKey = $bindable(), disabled = false }: {
|
||||
budgetMode: GifBudgetMode; dither: GifDither; colors: number; colorKey: GifKeySettings; disabled?: boolean
|
||||
} = $props()
|
||||
const priorities = [
|
||||
{ value:"balanced", label:"Balanced" }, { value:"resolution", label:"Preserve resolution" }, { value:"framerate", label:"Preserve frame rate" },
|
||||
] as const
|
||||
const dithers = [{ value:"floyd_steinberg",label:"Floyd-Steinberg" }, { value:"bayer",label:"Bayer" }, { value:"none",label:"None" }] as const
|
||||
|
||||
function toggleKey(enabled: boolean) {
|
||||
colorKey.enabled = enabled
|
||||
if (enabled && colors < 3) colors = 3
|
||||
}
|
||||
</script>
|
||||
|
||||
<h3>GIF compression</h3>
|
||||
<div class="form-field"><span>Budget priority</span><Dropdown label="GIF budget priority" bind:value={budgetMode} options={priorities} {disabled} /></div>
|
||||
<div>
|
||||
<div class="row between"><span>Palette colors</span><output class="mono">{colors}</output></div>
|
||||
<Slider label="GIF palette colors" bind:value={colors} min={2} max={256} {disabled} />
|
||||
<Slider label="GIF palette colors" bind:value={colors} min={colorKey.enabled ? 3 : 2} max={256} {disabled} />
|
||||
</div>
|
||||
<div class="form-field"><span>Dithering</span><Dropdown label="GIF dithering" bind:value={dither} options={dithers} {disabled} /></div>
|
||||
<div class="row between">
|
||||
<span>Color key transparency</span>
|
||||
<Toggle label="Color key transparency" checked={colorKey.enabled} onchange={toggleKey} {disabled} />
|
||||
</div>
|
||||
{#if colorKey.enabled}
|
||||
<div class="key-settings stack" transition:fadeMotion inert={!colorKey.enabled}>
|
||||
<label class="form-field">
|
||||
<span>Key color</span>
|
||||
<span class="field mono key-picker">
|
||||
<span class="swatch" style:background={colorKey.color} aria-hidden="true"></span>
|
||||
<span aria-hidden="true">{colorKey.color.toUpperCase()}</span>
|
||||
<input type="color" bind:value={colorKey.color} {disabled} />
|
||||
</span>
|
||||
</label>
|
||||
<div>
|
||||
<div class="row between"><span>Color tolerance</span><output class="mono">{colorKey.tolerance}%</output></div>
|
||||
<Slider label="Color tolerance" bind:value={colorKey.tolerance} min={1} max={100} {disabled} valueText={colorKey.tolerance + "%"} />
|
||||
<p class="note">Higher tolerance removes more colors close to the key.</p>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.key-picker { position:relative; display:flex; align-items:center; gap:8px; }
|
||||
.key-picker:has(input:focus-visible) { outline:var(--edge) solid var(--ink); outline-offset:4px; }
|
||||
.key-picker input { position:absolute; inset:0; width:100%; height:100%; opacity:0; cursor:pointer; }
|
||||
.key-picker input:disabled { cursor:default; }
|
||||
.swatch { width:24px; height:20px; border:1px solid var(--field); border-radius:var(--mark-radius); }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user