The next-generation file converter. Open source, fully local* and free forever.
feat: awesome animations
JovannMC5fe5410453e5
diff --git a/src/lib/components/functional/FormatDropdown.svelte b/src/lib/components/functional/FormatDropdown.svelteindex f1639cf..19c36ea 100644--- a/src/lib/components/functional/FormatDropdown.svelte+++ b/src/lib/components/functional/FormatDropdown.svelte@@ -1,5 +1,10 @@<script lang="ts">- import { duration, fade, transition } from "$lib/util/animation";+ import {+ animateHeight,+ duration,+ fade,+ transition,+ } from "$lib/util/animation";import { m } from "$lib/paraglide/messages";import {isMobile,@@ -597,48 +602,63 @@{/each}</div><!-- available formats -->- <div- class="max-h-80 overflow-y-auto grid grid-cols-3 gap-2 p-2"- bind:this={formatList}- >- {#if filteredData.formats.length > 0}- {#each filteredData.formats as format (format)}- {@const unavailable = isUnavailable(format)}- {#if unavailable}- <Tooltip text={getUnavailableReason(format)}>- <button- data-selected={format === selected}- aria-disabled="true"- class="w-full p-2 text-center rounded-xl opacity-45 cursor-not-allowed"- tabindex="0"- onclick={(e) => e.preventDefault()}- onkeydown={(e) => e.preventDefault()}- >- {format}- </button>- </Tooltip>- {:else}- <button- data-selected={format === selected}- class="w-full p-2 text-center rounded-xl+ <div use:animateHeight>+ {#key currentCategory}+ <div+ class="max-h-80 overflow-y-auto grid grid-cols-3 gap-2 p-2"+ in:fade={{+ duration: duration,+ easing: quintOut,+ }}+ out:fade={{+ duration: duration,+ easing: quintOut,+ }}+ bind:this={formatList}+ >+ {#if filteredData.formats.length > 0}+ {#each filteredData.formats as format (format)}+ {@const unavailable = isUnavailable(format)}+ {#if unavailable}+ <Tooltip+ text={getUnavailableReason(format)}+ >+ <button+ data-selected={format === selected}+ aria-disabled="true"+ class="w-full p-2 text-center rounded-xl opacity-45 cursor-not-allowed"+ tabindex="0"+ onclick={(e) => e.preventDefault()}+ onkeydown={(e) =>+ e.preventDefault()}+ >+ {format}+ </button>+ </Tooltip>+ {:else}+ <button+ data-selected={format === selected}+ class="w-full p-2 text-center rounded-xl{format === selected- ? 'bg-accent text-black'- : format === from- ? 'bg-separator'- : 'hover:bg-panel'}"- onclick={() => selectOption(format)}- >- {format}- </button>+ ? 'bg-accent text-black'+ : format === from+ ? 'bg-separator'+ : 'hover:bg-panel'}"+ onclick={() => selectOption(format)}+ >+ {format}+ </button>+ {/if}+ {/each}+ {:else}+ <div class="col-span-3 text-center p-4 text-muted">+ {searchQuery+ ? m["convert.dropdown.no_results"]()+ : m["convert.dropdown.no_formats"]()}+ </div>{/if}- {/each}- {:else}- <div class="col-span-3 text-center p-4 text-muted">- {searchQuery- ? m["convert.dropdown.no_results"]()- : m["convert.dropdown.no_formats"]()}</div>- {/if}+ {/key}</div><!-- format options -->{#if file?.name.toLowerCase().endsWith(".zip")}diff --git a/src/lib/components/functional/popups/SettingsModal.svelte b/src/lib/components/functional/popups/SettingsModal.svelteindex 4ca5f07..8635a58 100644--- a/src/lib/components/functional/popups/SettingsModal.svelte+++ b/src/lib/components/functional/popups/SettingsModal.svelte@@ -14,6 +14,8 @@SettingCategories,} from "$lib/types/conversion-settings";import clsx from "clsx";+ import { animateHeight, duration, fade } from "$lib/util/animation";+ import { quintOut } from "svelte/easing";type Props = {file: VertFile | undefined;@@ -292,129 +294,165 @@</button>{/each}</div>- {#if activeTab === "Converter"}- <div class="flex flex-col gap-2">- {#each availableConverters as converter}- <button- class={clsx(- "w-full p-3 text-left rounded-xl border border-separator",- converter.name === validConverter?.name- ? "bg-accent-purple text-black"- : "hover:bg-panel",- )}- onclick={() => {- settings.converter = converter.name;- }}- >- {converter.name}- </button>- {/each}- </div>- {:else if availableCategories[activeTab]?.length}- <div class="grid grid-cols-2 gap-4">- {#each availableCategories[activeTab] as setting (setting.key)}- {@const fullWidth = setting.forceFullWidth || setting.type === "boolean"}- <div- class={clsx(- "flex min-w-0 gap-2",- fullWidth && "col-span-2",- setting.type === "boolean"- ? "flex-row justify-between"- : "flex-col",- )}- >- <p class="text-sm font-bold">{setting.label}</p>- {#if setting.description}- <p class="text-xs text-muted mt-1">- {setting.description}- </p>- {/if}- {#if setting.type === "select"}- <Dropdown- options={setting.options?.map((opt) =>- typeof opt === "string"- ? { value: opt, label: opt }- : opt,- ) || []}- selected={settings[setting.key] ??- targetFile.conversionSettings[- setting.key- ] ??- setting.default}- style="settings"- onselect={(value) =>- handleSettingChange(setting.key, value)}- disabled={setting.disabled}- />- {:else if setting.type === "boolean"}- <FancyInput- type="checkbox"- checked={settings[setting.key] ??- targetFile.conversionSettings[- setting.key- ] ??- setting.default}- onchange={(e: any) =>- handleSettingChange(- setting.key,- e.currentTarget.checked,+ <div use:animateHeight>+ {#key activeTab}+ <div+ class="pb-2"+ in:fade={{ duration, easing: quintOut }}+ out:fade={{ duration, easing: quintOut }}+ >+ {#if activeTab === "Converter"}+ <div class="flex flex-col gap-2">+ {#each availableConverters as converter}+ <button+ class={clsx(+ "transition w-full p-3 text-left rounded-xl border border-separator",+ converter.name ===+ validConverter?.name+ ? "bg-accent-purple text-black"+ : "hover:bg-panel",)}- disabled={setting.disabled}- />- {:else if setting.type === "range"}- {@const rangeValue = (settings[setting.key] ??- targetFile.conversionSettings[- setting.key- ] ??- setting.default ??- setting.min ??- 0) as number}- {@const rangeLabel =- setting.options?.[rangeValue]?.label ??- rangeValue}- <div class="flex items-center mt-2 gap-2">- <input- type="range"- min={setting.min}- max={setting.max}- step={setting.step}- value={rangeValue}- class="range-slider w-full"- oninput={(e) =>- handleSettingChange(- setting.key,- e.currentTarget.valueAsNumber,- )}- disabled={setting.disabled}- />- <span- class="text-sm max-w-28 w-full text-right"- >{rangeLabel}</span+ onclick={() => {+ settings.converter = converter.name;+ }}>- </div>- {:else}- <FancyInput- type={setting.type}- value={settings[setting.key] ??- targetFile.conversionSettings[- setting.key- ] ??- setting.default}- placeholder={setting.placeholder}- oninput={(e: any) =>- handleSettingChange(- setting.key,- e.currentTarget.value,+ {converter.name}+ </button>+ {/each}+ </div>+ {:else if availableCategories[activeTab]?.length}+ <div class="grid grid-cols-2 gap-4">+ {#each availableCategories[activeTab] as setting (setting.key)}+ {@const fullWidth =+ setting.forceFullWidth ||+ setting.type === "boolean"}+ <div+ class={clsx(+ "flex min-w-0 gap-2",+ fullWidth && "col-span-2",+ setting.type === "boolean"+ ? "flex-row justify-between"+ : "flex-col",)}- disabled={setting.disabled}- />- {/if}- </div>- {/each}- </div>- {:else}- <p class="text-sm text-muted">{m["convert.settings.none"]()}</p>- {/if}+ >+ <p class="text-sm font-bold">+ {setting.label}+ </p>+ {#if setting.description}+ <p class="text-xs text-muted mt-1">+ {setting.description}+ </p>+ {/if}+ {#if setting.type === "select"}+ <Dropdown+ options={setting.options?.map(+ (opt) =>+ typeof opt === "string"+ ? {+ value: opt,+ label: opt,+ }+ : opt,+ ) || []}+ selected={settings[+ setting.key+ ] ??+ targetFile+ .conversionSettings[+ setting.key+ ] ??+ setting.default}+ style="settings"+ onselect={(value) =>+ handleSettingChange(+ setting.key,+ value,+ )}+ disabled={setting.disabled}+ />+ {:else if setting.type === "boolean"}+ <FancyInput+ type="checkbox"+ checked={settings[+ setting.key+ ] ??+ targetFile+ .conversionSettings[+ setting.key+ ] ??+ setting.default}+ onchange={(e: any) =>+ handleSettingChange(+ setting.key,+ e.currentTarget.checked,+ )}+ disabled={setting.disabled}+ />+ {:else if setting.type === "range"}+ {@const rangeValue = (settings[+ setting.key+ ] ??+ targetFile.conversionSettings[+ setting.key+ ] ??+ setting.default ??+ setting.min ??+ 0) as number}+ {@const rangeLabel =+ setting.options?.[rangeValue]+ ?.label ?? rangeValue}+ <div+ class="flex items-center mt-2 gap-2"+ >+ <input+ type="range"+ min={setting.min}+ max={setting.max}+ step={setting.step}+ value={rangeValue}+ class="range-slider w-full"+ oninput={(e) =>+ handleSettingChange(+ setting.key,+ e.currentTarget+ .valueAsNumber,+ )}+ disabled={setting.disabled}+ />+ <span+ class="text-sm max-w-28 w-full text-right"+ >{rangeLabel}</span+ >+ </div>+ {:else}+ <FancyInput+ type={setting.type}+ value={settings[setting.key] ??+ targetFile+ .conversionSettings[+ setting.key+ ] ??+ setting.default}+ placeholder={setting.placeholder}+ oninput={(e: any) =>+ handleSettingChange(+ setting.key,+ e.currentTarget.value,+ )}+ disabled={setting.disabled}+ />+ {/if}+ </div>+ {/each}+ </div>+ {:else}+ <p class="text-sm text-muted">+ {m["convert.settings.none"]()}+ </p>+ {/if}+ </div>+ {/key}+ </div>{/if}</div></Modal>diff --git a/src/lib/components/functional/popups/SlowConversionToast.svelte b/src/lib/components/functional/popups/SlowConversionToast.svelteindex 2e8e98e..89402d4 100644--- a/src/lib/components/functional/popups/SlowConversionToast.svelte+++ b/src/lib/components/functional/popups/SlowConversionToast.svelte@@ -17,18 +17,27 @@<div class="flex flex-col gap-4"><p class="text-black">{additional.reason === "device"- ? m["convert.slow_conversion.device_body"]({ filename: additional.filename })- : m["convert.slow_conversion.timeout_body"]({ filename: additional.filename })}+ ? m["convert.slow_conversion.device_body"]({+ filename: additional.filename,+ })+ : m["convert.slow_conversion.timeout_body"]({+ filename: additional.filename,+ })}</p><div class="flex gap-4">- <button class="btn rounded-lg h-fit py-2 w-full" onclick={additional.onContinue}>+ <button+ class="btn rounded-lg h-fit py-2 w-full"+ onclick={additional.onContinue}+ >{m["convert.slow_conversion.continue"]()}</button><buttonclass="btn rounded-lg h-fit py-2 w-full bg-accent-blue text-black"onclick={() => additional.onSwitch()}>- {m["convert.slow_conversion.switch"]({ converter: additional.converter })}+ {m["convert.slow_conversion.switch"]({+ converter: additional.converter,+ })}</button></div></div>diff --git a/src/lib/converters/mediabunny/mediabunny.svelte.ts b/src/lib/converters/mediabunny/mediabunny.svelte.tsindex c998dfb..8b2a829 100644--- a/src/lib/converters/mediabunny/mediabunny.svelte.ts+++ b/src/lib/converters/mediabunny/mediabunny.svelte.ts@@ -437,17 +437,18 @@ export class MediabunnyConverter extends Converter {this.activeConversions.set(file.id, conversion);const mobile = get(isMobile);- const deviceMemory = (navigator as Navigator & { deviceMemory?: number })- .deviceMemory;+ const deviceMemory = (+ navigator as Navigator & { deviceMemory?: number }+ ).deviceMemory;const hardwareConcurrency = navigator.hardwareConcurrency || 3; // if we can't detect it, just fall back to something that will definitely warnconst likelySlowDevice =(mobile && hardwareConcurrency <= 4) ||hardwareConcurrency <= 4 ||(deviceMemory !== undefined && deviceMemory <= 4);if (likelySlowDevice) void file.slowConversionOffer("device");- this.log(`hardwareConcurrency: ${hardwareConcurrency}`)- this.log(`deviceMemory: ${deviceMemory}`)- this.log(`mobile: ${mobile}`)+ this.log(`hardwareConcurrency: ${hardwareConcurrency}`);+ this.log(`deviceMemory: ${deviceMemory}`);+ this.log(`mobile: ${mobile}`);const slowConversionTimer: ReturnType<typeof setTimeout> = setTimeout(() => {diff --git a/src/lib/css/app.scss b/src/lib/css/app.scssindex 15a0bd8..fb1b95a 100644--- a/src/lib/css/app.scss+++ b/src/lib/css/app.scss@@ -339,17 +339,21 @@ body {@apply bg-accent-purple !text-black;}+.transition {+ transition:+ opacity 0.2s ease,+ transform 0.2s ease,+ background-color 0.2s ease;+ transition-duration: 200ms;+}+@layer components {select {@apply appearance-none;}.btn {- @apply bg-button flex items-center justify-center overflow-hidden relative cursor-pointer px-6 h-14 rounded-full font-medium focus:!outline-none hover:scale-105 duration-200 active:scale-95 disabled:opacity-50 disabled:pointer-events-none hoverable;- transition:- opacity 0.2s ease,- transform 0.2s ease,- background-color 0.2s ease;+ @apply transition bg-button flex items-center justify-center overflow-hidden relative cursor-pointer px-6 h-14 rounded-full font-medium focus:!outline-none hover:scale-105 active:scale-95 disabled:opacity-50 disabled:pointer-events-none hoverable;}.btn.highlight {@@ -400,6 +404,7 @@ body {input[type="checkbox"] {@apply appearance-none w-5 h-5 rounded-md border-2 border-button cursor-pointer transition-colors duration-200;+ outline-offset: -2px;;}input[type="checkbox"]:hover {diff --git a/src/lib/sections/about/Sponsors.svelte b/src/lib/sections/about/Sponsors.svelteindex c07d44c..964ac8e 100644--- a/src/lib/sections/about/Sponsors.svelte+++ b/src/lib/sections/about/Sponsors.svelte@@ -37,7 +37,7 @@</div>{m["about.sponsors.title"]()}</h2>- <div class="mt-2 [&>*]:font-normal h-full flex justify-between flex-col">+ <div class="[&>*]:font-normal h-full flex justify-between flex-col gap-4"><div class="flex gap-3 justify-center text-lg"><ahref="https://eva.pink"diff --git a/src/lib/util/animation.ts b/src/lib/util/animation.tsindex 004e4a3..d7f1fce 100644--- a/src/lib/util/animation.ts+++ b/src/lib/util/animation.ts@@ -8,7 +8,6 @@ import {type FlyParams,} from "svelte/transition";-// Subscribe to storeslet effectsEnabled = true;let isMobileDevice = false;@@ -26,6 +25,124 @@ export const transition =export const duration = 500;+type HeightTransitionOptions = {+ duration?: number;+ easing?: string;+};++export function animateHeight(+ node: HTMLElement,+ options: HeightTransitionOptions = {},+) {+ let transitionDuration = options.duration ?? duration;+ let easing = options.easing ?? transition;+ let observedChild: Element | null = null;+ let frame = 0;+ let releaseTimer = 0;+ let settledHeight: number | undefined;+ let resizeObserver: ResizeObserver | undefined;+ let mutationObserver: MutationObserver | undefined;++ const originalPosition = node.style.position;+ const originalOverflow = node.style.overflow;+ const originalTransition = node.style.transition;+ const originalHeight = node.style.height;+ node.style.position = "relative";+ node.style.overflow = "hidden";++ const setChildLayout = (activeChild: Element | null) => {+ for (const childElement of node.children) {+ const childStyle = childElement as HTMLElement;+ if (childElement === activeChild) {+ childStyle.style.position = "relative";+ childStyle.style.top = "";+ childStyle.style.left = "";+ childStyle.style.width = "";+ } else {+ childStyle.style.position = "absolute";+ childStyle.style.top = "0";+ childStyle.style.left = "0";+ childStyle.style.width = "100%";+ }+ }+ };++ const updateHeight = () => {+ cancelAnimationFrame(frame);+ frame = requestAnimationFrame(() => {+ const activeChild = node.lastElementChild;+ setChildLayout(activeChild);++ if (!activeChild) {+ node.style.height = "";+ settledHeight = undefined;+ return;+ }++ const childChanged = activeChild !== observedChild;+ if (childChanged) {+ resizeObserver?.disconnect();+ observedChild = activeChild;+ resizeObserver?.observe(activeChild);+ }++ const nextHeightValue = activeChild.getBoundingClientRect().height;+ const currentHeight = node.getBoundingClientRect().height;+ const startHeight = childChanged+ ? node.style.height === "auto"+ ? (settledHeight ?? currentHeight)+ : currentHeight+ : currentHeight;+ if (Math.abs(startHeight - nextHeightValue) < 1) {+ settledHeight = nextHeightValue;+ node.style.height = "auto";+ return;+ }++ clearTimeout(releaseTimer);+ node.style.transition = `height ${transitionDuration}ms ${easing}`;+ node.style.height = `${startHeight}px`;+ requestAnimationFrame(() => {+ node.style.height = `${nextHeightValue}px`;+ releaseTimer = window.setTimeout(() => {+ settledHeight = nextHeightValue;+ node.style.height = "auto";+ }, transitionDuration);+ });+ });+ };++ resizeObserver = new ResizeObserver(updateHeight);+ mutationObserver = new MutationObserver(updateHeight);+ mutationObserver.observe(node, { childList: true });+ updateHeight();++ return {+ update(nextOptions: HeightTransitionOptions = {}) {+ transitionDuration = nextOptions.duration ?? duration;+ easing = nextOptions.easing ?? transition;+ updateHeight();+ },+ destroy() {+ cancelAnimationFrame(frame);+ clearTimeout(releaseTimer);+ resizeObserver?.disconnect();+ mutationObserver?.disconnect();+ node.style.position = originalPosition;+ node.style.height = originalHeight;+ node.style.overflow = originalOverflow;+ node.style.transition = originalTransition;+ for (const child of node.children) {+ const childStyle = child as HTMLElement;+ childStyle.style.position = "";+ childStyle.style.top = "";+ childStyle.style.left = "";+ childStyle.style.width = "";+ }+ },+ };+}+export function fade(node: HTMLElement, options: FadeParams) {if (!effectsEnabled) return {};const animation = svelteFade(node, options);