fix: migrate & fix av-sync

This commit is contained in:
Tomáš Mládek 2025-09-27 21:27:00 +02:00
parent c30bffac73
commit 597aff5784
5 changed files with 51 additions and 32 deletions

View file

@ -8,11 +8,14 @@
import FlashIndicator from './components/FlashIndicator.svelte';
import Scale from './components/Scale.svelte';
export let frame = 0;
export let fps = 60;
export let debug = false;
interface Props {
frame?: number;
fps?: number;
debug?: boolean;
}
let { frame = $bindable(0), fps = $bindable(60), debug = $bindable(false) }: Props = $props();
onMount(() => {
window.setFps = async (newFps: number) => {
fps = newFps;
await tick();
@ -23,6 +26,7 @@
await tick();
};
onMount(() => {
if (window.location.search.includes('debug')) {
debug = true;
}

View file

@ -1,18 +1,24 @@
<script lang="ts">
export let frame: number;
export let fps: number;
interface Props {
frame: number;
fps: number;
}
let el: SVGSVGElement;
$: center = el?.clientWidth / 2;
$: radius = center;
let { frame, fps }: Props = $props();
let opacity = 1;
$: opacity = ease(1 - ((frame % fps) / fps) * 2);
let el: SVGSVGElement | undefined = $state();
let opacity = $state(1);
function ease(x: number) {
x = Math.max(0, Math.min(1, x));
return 1 - Math.cos((x * Math.PI) / 2);
}
let center = $derived((el?.clientWidth ?? 0) / 2);
let radius = $derived(center);
$effect(() => {
opacity = ease(1 - ((frame % fps) / fps) * 2);
});
</script>
<svg class="indicator" bind:this={el} style="--opacity: {opacity}">

View file

@ -1,6 +1,10 @@
<script lang="ts">
export let frame: number;
export let fps: number;
interface Props {
frame: number;
fps: number;
}
let { frame, fps }: Props = $props();
</script>
<div class="scale" style="--frame: {frame}; --fps: {fps}">

View file

@ -1,14 +1,18 @@
<script lang="ts">
export let frame: number;
export let fps: number;
interface Props {
frame: number;
fps: number;
}
let el: SVGSVGElement;
$: center = el?.clientWidth / 2;
$: radius = center;
let d = '';
let circleOpacity = 1;
let { frame, fps }: Props = $props();
$: {
let el: SVGSVGElement | undefined = $state();
let center = $derived((el?.clientWidth ?? 0) / 2);
let radius = $derived(center);
let d = $state('');
let circleOpacity = $state(1);
$effect(() => {
const angle = ((frame / fps) * 360) % 360;
const radians = (angle * Math.PI) / 180;
const x = center + radius * Math.cos(radians);
@ -17,7 +21,7 @@
const flashFrames = fps / 10;
circleOpacity = (flashFrames - (frame % fps)) / flashFrames;
}
});
</script>
<svg class="indicator" style="--circle-opacity: {circleOpacity}" bind:this={el}>

View file

@ -1,7 +1,8 @@
import './app.css';
import App from './App.svelte';
import { mount } from "svelte";
const app = new App({
const app = mount(App, {
target: document.getElementById('app')!
});