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

View file

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

View file

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

View file

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

View file

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