Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import { play } from "#lib/components/landing/sound.ts";import { cubicIn, cubicOut } from "svelte/easing";import { Tween, prefersReducedMotion } from "svelte/motion";
export interface InsertTiming { drop: number; lift: number; on?: number; off?: number;}
const BOB_RATE = 2.2;const WHIRR_DELAY = 100;
export class Insert { height = new Tween(1); power = new Tween(0); inserted = $state(false); moving = $state(false); #timing: Required<InsertTiming>;
constructor({ drop, lift, on = 0, off = 0 }: InsertTiming) { this.#timing = { drop, lift, on, off }; }
get lit() { return this.power.current > 0.5; }
hang(time: number, reach: number, bob: number) { return this.height.current * (reach + Math.sin(time * BOB_RATE) * bob); }
toggle = async () => { if (this.moving) return; this.moving = true; this.inserted = !this.inserted; const { drop, lift, on, off } = this.#timing; const ms = (n: number) => (prefersReducedMotion.current ? 0 : n); if (this.inserted) { await this.height.set(0, { duration: ms(drop), easing: cubicIn }); play("open", { theme: "mech" }); setTimeout(() => play("loading", { theme: "mech" }), WHIRR_DELAY); await this.power.set(1, { duration: ms(on), easing: cubicOut }); } else { await this.power.set(0, { duration: ms(off), easing: cubicIn }); play("close", { theme: "mech" }); await this.height.set(1, { duration: ms(lift), easing: cubicOut }); } this.moving = false; };}