ffmpeg-explorer/src/FilterPicker.svelte

102 lines
2.2 KiB
Svelte
Raw Normal View History

2023-08-18 18:59:16 -04:00
<script>
import uFuzzy from "@leeoniya/ufuzzy";
2023-08-20 12:01:50 -04:00
import { v4 as uuidv4 } from 'uuid';
2023-08-18 18:59:16 -04:00
import FILTERS from "./filters.json";
import { filters } from "./stores.js";
2023-08-19 17:31:55 -04:00
export let select = "video";
$: selectedFilters = selectFilters(select);
$: allfilters = [...selectedFilters];
2023-08-18 18:59:16 -04:00
let q = "";
const uf = new uFuzzy();
2023-08-19 17:31:55 -04:00
function selectFilters(sel) {
if (sel == "video") {
return FILTERS.filter(f => f.type[0] === "V")
} else if (sel == "audio") {
return FILTERS.filter(f => f.type[0] === "A")
} else {
return [...FILTERS];
}
}
function reset() {
q = "";
}
2023-08-18 18:59:16 -04:00
function add(f) {
2023-08-20 12:01:50 -04:00
const newFilter = { ...f, filterId: f.id, id: uuidv4() };
2023-08-19 17:31:55 -04:00
if (f.params) {
newFilter.params = f.params.map((p) => {
p.value = null;
if (p.default != null) p.value = p.default;
return p;
});
}
2023-08-18 18:59:16 -04:00
$filters = [...$filters, newFilter];
console.log(newFilter);
}
function update() {
let newFilters = [];
const [idxs, info, order] = uf.search(
2023-08-19 17:31:55 -04:00
selectedFilters.map((m) => m.name + " " + m.description),
2023-08-18 18:59:16 -04:00
q
);
if (idxs) {
for (let i of idxs) {
2023-08-19 17:31:55 -04:00
newFilters.push(selectedFilters[i]);
2023-08-18 18:59:16 -04:00
}
allfilters = newFilters;
} else {
2023-08-19 17:31:55 -04:00
allfilters = [...selectedFilters];
2023-08-18 18:59:16 -04:00
}
}
</script>
<div class="holder">
<div class="search">
<input placeholder="Search Filters" on:keyup={update} bind:value={q} />
2023-08-19 17:31:55 -04:00
<select on:change={reset} bind:value={select}>
<option value="video">Video Filters</option>
<option value="audio">Audio Filters</option>
</select>
2023-08-18 18:59:16 -04:00
</div>
<div class="all-filters">
{#each allfilters as f}
<div class="filter" on:click={() => add(f)}>
2023-08-19 17:31:55 -04:00
<div class="name">{f.name} <span class="type">{f.type.replace("->", "⇒")}</span></div>
2023-08-18 18:59:16 -04:00
<div class="desc">{f.description}</div>
</div>
{/each}
</div>
</div>
<style>
.holder {
display: flex;
flex-direction: column;
2023-08-19 17:31:55 -04:00
height: 100%;
padding: 10px;
2023-08-20 14:08:08 -04:00
border: 1px solid var(--b1);
2023-08-18 18:59:16 -04:00
}
2023-08-19 17:31:55 -04:00
.type {
color: #999;
font-size: 0.8em;
}
2023-08-18 18:59:16 -04:00
.filter {
2023-08-20 14:08:08 -04:00
border-bottom: 1px solid var(--b1);
2023-08-18 18:59:16 -04:00
padding: 10px 0px;
cursor: pointer;
}
.all-filters {
flex: 1;
overflow: scroll;
}
.desc {
font-size: 0.9em;
}
</style>