feat!: release v2 (#6545)
Co-authored-by: Artur <145776561+arturict@users.noreply.github.com> Co-authored-by: arturict <arturict@users.noreply.github.com> Co-authored-by: Thomas <thomas@ajnart.fr> Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com> Co-authored-by: Danura30082 <danura30082+github@gmail.com> Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com> Co-authored-by: ajnart <thomas@ajnart.fr> Co-authored-by: ajnart <thomas@ajnart.dev> Co-authored-by: chenjun <chenjun@foxmail.com> Co-authored-by: Wikibear <wikibear@users.noreply.github.com> Co-authored-by: Bergasha <bergasha@gmail.com> Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com> Co-authored-by: Lucas Araujo <lucas.lra@gmail.com> Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com> Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social> Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com> Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com> Co-authored-by: thrawnx <tight.bulb9384@fastmail.com> Co-authored-by: Chris <58918656+nordada@users.noreply.github.com> Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com> Co-authored-by: Yanis <naamaneyanis@gmail.com> Co-authored-by: Wikibear <me@sej.de> Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386
-139176
No files matched your search
@@ -0,0 +1,70 @@
|
||||
// Pure timing helpers. Every visual value in the reel is a function of time.
|
||||
|
||||
export const clamp = (v: number, a = 0, b = 1) => Math.min(b, Math.max(a, v));
|
||||
export const lerp = (a: number, b: number, t: number) => a + (b - a) * t;
|
||||
export const seg = (t: number, a: number, b: number) => clamp((t - a) / (b - a));
|
||||
export const map = (t: number, a: number, b: number, c: number, d: number) => lerp(c, d, seg(t, a, b));
|
||||
|
||||
export const E = {
|
||||
linear: (t: number) => t,
|
||||
inQuad: (t: number) => t * t,
|
||||
outQuad: (t: number) => 1 - (1 - t) * (1 - t),
|
||||
inCubic: (t: number) => t * t * t,
|
||||
outCubic: (t: number) => 1 - (1 - t) ** 3,
|
||||
inOutCubic: (t: number) => (t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2),
|
||||
outQuart: (t: number) => 1 - (1 - t) ** 4,
|
||||
inQuart: (t: number) => t ** 4,
|
||||
inOutQuart: (t: number) => (t < 0.5 ? 8 * t ** 4 : 1 - (-2 * t + 2) ** 4 / 2),
|
||||
outQuint: (t: number) => 1 - (1 - t) ** 5,
|
||||
inOutQuint: (t: number) => (t < 0.5 ? 16 * t ** 5 : 1 - (-2 * t + 2) ** 5 / 2),
|
||||
outExpo: (t: number) => (t >= 1 ? 1 : 1 - 2 ** (-10 * t)),
|
||||
inExpo: (t: number) => (t <= 0 ? 0 : 2 ** (10 * t - 10)),
|
||||
inOutExpo: (t: number) =>
|
||||
t <= 0 ? 0 : t >= 1 ? 1 : t < 0.5 ? 2 ** (20 * t - 10) / 2 : (2 - 2 ** (-20 * t + 10)) / 2,
|
||||
outBack: (t: number, s = 1.70158) => 1 + (s + 1) * (t - 1) ** 3 + s * (t - 1) ** 2,
|
||||
inBack: (t: number, s = 1.70158) => (s + 1) * t ** 3 - s * t * t,
|
||||
outCirc: (t: number) => Math.sqrt(1 - (t - 1) ** 2),
|
||||
inOutSine: (t: number) => -(Math.cos(Math.PI * t) - 1) / 2,
|
||||
};
|
||||
|
||||
/** Analytic damped spring from 0 to 1. `t` in seconds. */
|
||||
export function spring(t: number, freq = 3.2, damp = 0.42) {
|
||||
if (t <= 0) return 0;
|
||||
const w = 2 * Math.PI * freq;
|
||||
const wd = w * Math.sqrt(1 - damp * damp);
|
||||
return 1 - Math.exp(-damp * w * t) * (Math.cos(wd * t) + ((damp * w) / wd) * Math.sin(wd * t));
|
||||
}
|
||||
|
||||
/** Seeded, stateless pseudo random in [0, 1). */
|
||||
export function rand(seed: number) {
|
||||
const x = Math.sin(seed * 127.1 + 311.7) * 43758.5453123;
|
||||
return x - Math.floor(x);
|
||||
}
|
||||
|
||||
/** Smooth 1D value noise, stateless. */
|
||||
export function noise(x: number, seed = 0) {
|
||||
const i = Math.floor(x);
|
||||
const f = x - i;
|
||||
const u = f * f * (3 - 2 * f);
|
||||
return lerp(rand(i + seed * 97.3), rand(i + 1 + seed * 97.3), u) * 2 - 1;
|
||||
}
|
||||
|
||||
/** Envelope: 0 → 1 during [a, a+inD], holds, 1 → 0 during [b-outD, b]. */
|
||||
export function env(t: number, a: number, b: number, inD = 0.5, outD = 0.4, ei = E.outExpo, eo = E.inCubic) {
|
||||
if (t < a || t > b) return 0;
|
||||
const i = ei(seg(t, a, a + inD));
|
||||
const o = 1 - eo(seg(t, b - outD, b));
|
||||
return Math.min(i, o);
|
||||
}
|
||||
|
||||
/** Beat pulse: sharp attack, exponential decay after each hit time. */
|
||||
export function pulse(t: number, hits: number[], decay = 6) {
|
||||
let v = 0;
|
||||
for (const h of hits) if (t >= h) v = Math.max(v, Math.exp(-(t - h) * decay));
|
||||
return v;
|
||||
}
|
||||
|
||||
// Tempo of the soundtrack (MOKKA – Synthetic Pleasures); scene lengths are whole bars of it.
|
||||
export const BPM = 93;
|
||||
export const BEAT = 60 / BPM;
|
||||
export const BAR = BEAT * 4;
|
||||
@@ -0,0 +1,147 @@
|
||||
// Minimal DOM helpers for frame-driven animation.
|
||||
|
||||
type Child = Node | string | null | undefined | false;
|
||||
|
||||
export function h<K extends keyof HTMLElementTagNameMap>(
|
||||
tag: K,
|
||||
props: { class?: string; style?: Partial<CSSStyleDeclaration> | string; html?: string; [k: string]: unknown } = {},
|
||||
...children: Child[]
|
||||
): HTMLElementTagNameMap[K] {
|
||||
const el = document.createElement(tag);
|
||||
for (const [key, value] of Object.entries(props)) {
|
||||
if (value == null) continue;
|
||||
if (key === "class") el.className = value as string;
|
||||
else if (key === "style") {
|
||||
if (typeof value === "string") el.style.cssText = value;
|
||||
else Object.assign(el.style, value);
|
||||
} else if (key === "html") el.innerHTML = value as string;
|
||||
else el.setAttribute(key, String(value));
|
||||
}
|
||||
for (const child of children) {
|
||||
if (child == null || child === false) continue;
|
||||
el.append(typeof child === "string" ? document.createTextNode(child) : child);
|
||||
}
|
||||
return el;
|
||||
}
|
||||
|
||||
export const div = (cls = "", ...children: Child[]) => h("div", { class: cls }, ...children);
|
||||
|
||||
export interface Tf {
|
||||
x?: number;
|
||||
y?: number;
|
||||
z?: number;
|
||||
s?: number;
|
||||
sx?: number;
|
||||
sy?: number;
|
||||
r?: number;
|
||||
rx?: number;
|
||||
ry?: number;
|
||||
skx?: number;
|
||||
o?: number;
|
||||
blur?: number;
|
||||
bright?: number;
|
||||
px?: boolean;
|
||||
}
|
||||
|
||||
/** Apply a transform snapshot. Translation in px, rotations in degrees. */
|
||||
export function tf(el: HTMLElement | SVGElement, t: Tf) {
|
||||
const s = t.s ?? 1;
|
||||
const sx = (t.sx ?? 1) * s;
|
||||
const sy = (t.sy ?? 1) * s;
|
||||
let str = `translate3d(${(t.x ?? 0).toFixed(2)}px,${(t.y ?? 0).toFixed(2)}px,${(t.z ?? 0).toFixed(2)}px)`;
|
||||
if (t.rx) str += ` rotateX(${t.rx.toFixed(3)}deg)`;
|
||||
if (t.ry) str += ` rotateY(${t.ry.toFixed(3)}deg)`;
|
||||
if (t.r) str += ` rotate(${t.r.toFixed(3)}deg)`;
|
||||
if (t.skx) str += ` skewX(${t.skx.toFixed(3)}deg)`;
|
||||
if (sx !== 1 || sy !== 1) str += ` scale(${sx.toFixed(4)},${sy.toFixed(4)})`;
|
||||
el.style.transform = str;
|
||||
const o = t.o ?? 1;
|
||||
el.style.opacity = o.toFixed(3);
|
||||
el.style.visibility = o <= 0.001 ? "hidden" : "visible";
|
||||
const filters: string[] = [];
|
||||
if (t.blur && t.blur > 0.05) filters.push(`blur(${t.blur.toFixed(2)}px)`);
|
||||
if (t.bright != null && t.bright !== 1) filters.push(`brightness(${t.bright.toFixed(3)})`);
|
||||
el.style.filter = filters.join(" ");
|
||||
}
|
||||
|
||||
export function show(el: HTMLElement, on: boolean) {
|
||||
el.style.display = on ? "" : "none";
|
||||
}
|
||||
|
||||
/** Tabler icon placeholder, hydrated from node_modules before rendering starts. */
|
||||
export function icon(name: string, size = 24, stroke = 2, cls = "") {
|
||||
const el = h("span", { class: `ti ${cls}`, "data-icon": name });
|
||||
el.style.width = `${size}px`;
|
||||
el.style.height = `${size}px`;
|
||||
el.style.setProperty("--sw", String(stroke));
|
||||
return el;
|
||||
}
|
||||
|
||||
/** Service logo from dashboard-icons. */
|
||||
export function logo(name: string, size = 40, cls = "") {
|
||||
const ext = ["linkwarden", "plantit", "tubearchivist", "unmanic", "xteve"].includes(name) ? "png" : "svg";
|
||||
return h("img", { class: `svc ${cls}`, src: `assets/icons/${name}.${ext}`, width: size, height: size, alt: "" });
|
||||
}
|
||||
|
||||
export async function hydrateIcons(root: ParentNode) {
|
||||
const nodes = [...root.querySelectorAll<HTMLElement>("[data-icon]")];
|
||||
const names = [...new Set(nodes.map((n) => n.dataset.icon!))];
|
||||
const cache = new Map<string, string>();
|
||||
await Promise.all(
|
||||
names.map(async (name) => {
|
||||
const [dir, file] = name.startsWith("filled:") ? ["filled", name.slice(7)] : ["outline", name];
|
||||
const res = await fetch(`node_modules/@tabler/icons/icons/${dir}/${file}.svg`);
|
||||
if (!res.ok) throw new Error(`missing icon ${name}`);
|
||||
cache.set(name, await res.text());
|
||||
}),
|
||||
);
|
||||
for (const n of nodes) n.innerHTML = cache.get(n.dataset.icon!)!;
|
||||
}
|
||||
|
||||
/** Split text into per-character spans (words kept together). */
|
||||
export function chars(text: string, cls = "ch") {
|
||||
const wrap = h("span", { class: "chars" });
|
||||
const out: HTMLElement[] = [];
|
||||
text.split(/(\s+)/).forEach((word) => {
|
||||
if (/^\s+$/.test(word)) {
|
||||
wrap.append(document.createTextNode(word));
|
||||
return;
|
||||
}
|
||||
const w = h("span", { class: "word" });
|
||||
for (const c of word) {
|
||||
const s = h("span", { class: cls }, c);
|
||||
out.push(s);
|
||||
w.append(s);
|
||||
}
|
||||
wrap.append(w);
|
||||
});
|
||||
return { el: wrap, chars: out };
|
||||
}
|
||||
|
||||
/** Split text into word spans inside overflow masks. */
|
||||
export function words(text: string) {
|
||||
const wrap = h("span", { class: "words" });
|
||||
const out: HTMLElement[] = [];
|
||||
text.split(/\s+/).forEach((word, i) => {
|
||||
if (i) wrap.append(document.createTextNode(" "));
|
||||
const mask = h("span", { class: "wmask" });
|
||||
const w = h("span", { class: "w" }, word);
|
||||
mask.append(w);
|
||||
out.push(w);
|
||||
wrap.append(mask);
|
||||
});
|
||||
return { el: wrap, words: out };
|
||||
}
|
||||
|
||||
/** Layout offset of `el` inside `root`, ignoring transforms (transformed ancestors count as offsetParents in Chrome). */
|
||||
export function offsetWithin(el: HTMLElement, root: HTMLElement) {
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
let e: HTMLElement | null = el;
|
||||
while (e && e !== root) {
|
||||
x += e.offsetLeft;
|
||||
y += e.offsetTop;
|
||||
e = e.offsetParent as HTMLElement | null;
|
||||
}
|
||||
return [x, y] as const;
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
// Reusable motion components. Each exposes update(t) driven by scene-local time.
|
||||
import { E, clamp, seg, lerp, spring } from "./anim";
|
||||
import { h, words, chars } from "./dom";
|
||||
|
||||
/** Word-by-word masked rise. */
|
||||
export class Headline {
|
||||
el: HTMLElement;
|
||||
ws: HTMLElement[];
|
||||
constructor(
|
||||
text: string,
|
||||
opts: { size: number; cls?: string; accent?: string[]; color?: string; weight?: number; lh?: number } = {
|
||||
size: 96,
|
||||
},
|
||||
) {
|
||||
const { el, words: ws } = words(text);
|
||||
this.el = h("div", { class: `display ${opts.cls ?? ""}` }, el);
|
||||
this.el.style.fontSize = `${opts.size}px`;
|
||||
if (opts.weight) this.el.style.fontWeight = String(opts.weight);
|
||||
if (opts.lh) this.el.style.lineHeight = String(opts.lh);
|
||||
if (opts.color) this.el.style.color = opts.color;
|
||||
this.ws = ws;
|
||||
const accent = new Set((opts.accent ?? []).map((w) => w.toLowerCase()));
|
||||
for (const w of ws)
|
||||
if (accent.has(w.textContent!.toLowerCase().replace(/[.,!?]/g, ""))) w.style.color = "var(--coral)";
|
||||
}
|
||||
update(t: number, tin: number, tout = Infinity, stagger = 0.055, dur = 0.75) {
|
||||
this.ws.forEach((w, i) => {
|
||||
const p = E.outExpo(seg(t, tin + i * stagger, tin + i * stagger + dur));
|
||||
const q = E.inCubic(seg(t, tout + i * stagger * 0.3, tout + i * stagger * 0.3 + 0.3));
|
||||
const y = (1 - p) * 115 - q * 115;
|
||||
const rot = (1 - p) * 7 - q * 4;
|
||||
w.style.transform = `translateY(${y.toFixed(2)}%) rotate(${rot.toFixed(2)}deg)`;
|
||||
// Rotated words can poke out of their mask while parked; hide them.
|
||||
w.style.visibility = p <= 0 || q >= 1 ? "hidden" : "visible";
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/** Per-character reveal with blur + scale, for punchier moments. */
|
||||
export class CharPop {
|
||||
el: HTMLElement;
|
||||
cs: HTMLElement[];
|
||||
constructor(text: string, size: number, cls = "display") {
|
||||
const { el, chars: cs } = chars(text);
|
||||
this.el = h("div", { class: cls }, el);
|
||||
this.el.style.fontSize = `${size}px`;
|
||||
this.cs = cs;
|
||||
}
|
||||
update(t: number, tin: number, tout = Infinity, stagger = 0.03, from: "center" | "left" = "left") {
|
||||
const n = this.cs.length;
|
||||
this.cs.forEach((c, i) => {
|
||||
const order = from === "center" ? Math.abs(i - (n - 1) / 2) : i;
|
||||
const s0 = tin + order * stagger;
|
||||
const p = seg(t, s0, s0 + 0.6);
|
||||
const sp = spring(t - s0, 2.6, 0.5);
|
||||
const q = E.inExpo(seg(t, tout + order * stagger * 0.4, tout + order * stagger * 0.4 + 0.35));
|
||||
const y = (1 - sp) * 60 - q * 40;
|
||||
const sc = lerp(1.6, 1, E.outExpo(p)) * (1 - q * 0.3);
|
||||
c.style.transform = `translateY(${y.toFixed(2)}px) scale(${sc.toFixed(3)})`;
|
||||
c.style.opacity = String(clamp(p * 3) * (1 - q));
|
||||
const b = (1 - E.outCubic(p)) * 14 + q * 10;
|
||||
c.style.filter = b > 0.1 ? `blur(${b.toFixed(2)}px)` : "";
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/** Chapter marker: index + label with a drawn rule. */
|
||||
export class Chapter {
|
||||
el: HTMLElement;
|
||||
num: HTMLElement;
|
||||
rule: HTMLElement;
|
||||
lab: HTMLElement;
|
||||
constructor(index: string, label: string) {
|
||||
this.num = h(
|
||||
"div",
|
||||
{ class: "mono", style: "font-size:17px;font-weight:700;color:var(--coral);letter-spacing:.1em" },
|
||||
index,
|
||||
);
|
||||
this.rule = h("div", { style: "height:2px;width:64px;background:var(--coral);transform-origin:0 50%" });
|
||||
this.lab = h("div", { class: "label", style: "color:var(--text);opacity:.9" }, label);
|
||||
this.el = h("div", { class: "abs row", style: "gap:18px;left:96px;top:78px" }, this.num, this.rule, this.lab);
|
||||
}
|
||||
update(t: number, tin: number, tout = Infinity) {
|
||||
const p = E.outExpo(seg(t, tin, tin + 0.8));
|
||||
const q = E.inCubic(seg(t, tout, tout + 0.4));
|
||||
this.rule.style.transform = `scaleX(${(p * (1 - q)).toFixed(3)})`;
|
||||
this.num.style.opacity = String(p * (1 - q));
|
||||
this.num.style.transform = `translateX(${((1 - p) * -20).toFixed(1)}px)`;
|
||||
this.lab.style.clipPath = `inset(0 ${((1 - E.outQuart(seg(t, tin + 0.15, tin + 0.9))) * 100).toFixed(1)}% 0 0)`;
|
||||
this.lab.style.opacity = String(1 - q);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/** Plain text typewriter with caret. */
|
||||
export class TypeLine {
|
||||
el: HTMLElement;
|
||||
txt: HTMLElement;
|
||||
caret: HTMLElement;
|
||||
constructor(
|
||||
public text: string,
|
||||
cls = "",
|
||||
caretColor = "var(--coral)",
|
||||
) {
|
||||
this.txt = h("span");
|
||||
this.caret = h("span", { class: "caret" });
|
||||
this.caret.style.background = caretColor;
|
||||
this.el = h("span", { class: cls }, this.txt, this.caret);
|
||||
}
|
||||
update(t: number, t0: number, cps = 28, caretUntil = Infinity) {
|
||||
const n = Math.max(0, Math.min(this.text.length, Math.floor((t - t0) * cps)));
|
||||
this.txt.textContent = this.text.slice(0, n);
|
||||
const typing = t >= t0 && n < this.text.length;
|
||||
const blink = typing || Math.floor(t * 2.2) % 2 === 0;
|
||||
this.caret.style.opacity = t < t0 - 0.4 || t > caretUntil ? "0" : blink ? "1" : "0";
|
||||
return n >= this.text.length;
|
||||
}
|
||||
get duration() {
|
||||
return this.text.length;
|
||||
}
|
||||
}
|
||||
|
||||
export type Tok = [string, string?];
|
||||
|
||||
/** Syntax-highlighted code typewriter: lines of [text, class] tokens. */
|
||||
export class CodeType {
|
||||
el: HTMLElement;
|
||||
spans: { el: HTMLElement; text: string; start: number }[] = [];
|
||||
lines: HTMLElement[] = [];
|
||||
caret: HTMLElement;
|
||||
total = 0;
|
||||
lineStart: number[] = [];
|
||||
constructor(code: Tok[][], cls = "mono") {
|
||||
this.el = h("div", { class: cls });
|
||||
this.caret = h("span", { class: "caret" });
|
||||
let n = 0;
|
||||
code.forEach((line) => {
|
||||
const ln = h("div", { style: "white-space:pre;min-height:1.5em" });
|
||||
this.lineStart.push(n);
|
||||
line.forEach(([text, c]) => {
|
||||
const s = h("span", { class: c ? `tok-${c}` : "" });
|
||||
this.spans.push({ el: s, text, start: n });
|
||||
n += text.length;
|
||||
ln.append(s);
|
||||
});
|
||||
n += 1; // newline
|
||||
this.lines.push(ln);
|
||||
this.el.append(ln);
|
||||
});
|
||||
this.total = n;
|
||||
}
|
||||
/** Reveal n characters. Returns index of the current line. */
|
||||
set(n: number, showCaret = true) {
|
||||
let caretHost: HTMLElement | null = null;
|
||||
for (const s of this.spans) {
|
||||
const k = clamp(n - s.start, 0, s.text.length);
|
||||
s.el.textContent = s.text.slice(0, k);
|
||||
if (n >= s.start && n <= s.start + s.text.length) caretHost = s.el;
|
||||
}
|
||||
let line = 0;
|
||||
this.lineStart.forEach((st, i) => {
|
||||
if (n >= st) line = i;
|
||||
});
|
||||
if (showCaret && caretHost) caretHost.after(this.caret);
|
||||
else if (showCaret) this.lines[line]?.append(this.caret);
|
||||
this.caret.style.display = showCaret ? "" : "none";
|
||||
return line;
|
||||
}
|
||||
}
|
||||
|
||||
/** Number that counts up with easing. */
|
||||
export function countTo(
|
||||
el: HTMLElement,
|
||||
t: number,
|
||||
t0: number,
|
||||
t1: number,
|
||||
to: number,
|
||||
from = 0,
|
||||
fmt = (v: number) => String(Math.round(v)),
|
||||
) {
|
||||
el.textContent = fmt(lerp(from, to, E.outExpo(seg(t, t0, t1))));
|
||||
}
|
||||
|
||||
/** Draw an SVG path progressively. Requires pathLength="1". */
|
||||
export function drawPath(p: SVGPathElement | SVGGeometryElement, a: number, b = 0) {
|
||||
p.style.strokeDasharray = "1 1";
|
||||
const len = clamp(a - b);
|
||||
p.style.strokeDasharray = `${len} ${2}`;
|
||||
p.style.strokeDashoffset = String(-b);
|
||||
}
|
||||
|
||||
export const svgNS = "http://www.w3.org/2000/svg";
|
||||
export function svg<K extends keyof SVGElementTagNameMap>(tag: K, attrs: Record<string, string | number> = {}) {
|
||||
const el = document.createElementNS(svgNS, tag);
|
||||
for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, String(v));
|
||||
return el;
|
||||
}
|
||||
|
||||
/** Evaluate point on cubic bezier. */
|
||||
export function bez(p0: number[], p1: number[], p2: number[], p3: number[], t: number) {
|
||||
const u = 1 - t;
|
||||
return [0, 1].map(
|
||||
(i) => u * u * u * p0[i]! + 3 * u * u * t * p1[i]! + 3 * u * t * t * p2[i]! + t * t * t * p3[i]!,
|
||||
) as [number, number];
|
||||
}
|
||||
|
||||
/** Typewriter that keeps its final layout: untyped text is present but transparent, so wrapping never jumps. */
|
||||
export class TypeBlock {
|
||||
el: HTMLElement;
|
||||
shown: HTMLElement;
|
||||
rest: HTMLElement;
|
||||
caret: HTMLElement;
|
||||
constructor(
|
||||
public text: string,
|
||||
cls = "",
|
||||
caretColor = "var(--coral)",
|
||||
) {
|
||||
this.shown = h("span");
|
||||
this.rest = h("span", { style: "color:transparent" });
|
||||
this.caret = h("span", { class: "caret" });
|
||||
this.caret.style.background = caretColor;
|
||||
this.caret.style.marginRight = "-3px";
|
||||
this.el = h("span", { class: cls }, this.shown, this.caret, this.rest);
|
||||
}
|
||||
update(t: number, t0: number, cps = 28, caretUntil = Infinity) {
|
||||
const n = Math.max(0, Math.min(this.text.length, Math.floor((t - t0) * cps)));
|
||||
this.shown.textContent = this.text.slice(0, n);
|
||||
this.rest.textContent = this.text.slice(n);
|
||||
const typing = t >= t0 && n < this.text.length;
|
||||
const blink = typing || Math.floor(t * 2.2) % 2 === 0;
|
||||
this.caret.style.opacity = t < t0 - 0.4 || t > caretUntil ? "0" : blink ? "1" : "0";
|
||||
return n >= this.text.length;
|
||||
}
|
||||
end(t0: number, cps = 28) {
|
||||
return t0 + this.text.length / cps;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import type { LogoState } from "../three/logo";
|
||||
|
||||
export interface Fx {
|
||||
flash: number; // 0..1 white flash
|
||||
flashColor: string;
|
||||
shake: number; // px amplitude
|
||||
ca: number; // chromatic aberration px
|
||||
fade: number; // 0..1 black
|
||||
zoom: number; // world zoom punch
|
||||
grain: number;
|
||||
vignette: number;
|
||||
glBlur: number;
|
||||
}
|
||||
|
||||
export interface Ctx {
|
||||
logo: LogoState;
|
||||
fx: Fx;
|
||||
frame: number;
|
||||
}
|
||||
|
||||
export type CueKind =
|
||||
| "hit" // big impact
|
||||
| "boom" // sub drop / huge impact
|
||||
| "whoosh"
|
||||
| "swish" // short whoosh
|
||||
| "riser" // build (duration)
|
||||
| "click"
|
||||
| "pop"
|
||||
| "tick" // UI tick
|
||||
| "type" // typing range (duration)
|
||||
| "zap" // electric beam
|
||||
| "chime" // success
|
||||
| "buzz" // phone buzz
|
||||
| "glitch"
|
||||
| "stamp"
|
||||
| "key" // key press
|
||||
| "reverse"; // reverse cymbal into a hit (ends at t)
|
||||
|
||||
export interface Cue {
|
||||
t: number;
|
||||
kind: CueKind;
|
||||
dur?: number;
|
||||
gain?: number;
|
||||
pitch?: number;
|
||||
pan?: number;
|
||||
}
|
||||
|
||||
export interface Scene {
|
||||
name: string;
|
||||
start: number;
|
||||
end: number;
|
||||
bg?: HTMLElement;
|
||||
fg: HTMLElement;
|
||||
cues: Cue[];
|
||||
/** Reading holds: scene-local [from, to, speed] ranges played slower than authored. */
|
||||
warp?: [number, number, number][];
|
||||
/** Push transition from the previous scene, centred on this scene's first downbeat. */
|
||||
enter?: { dir: "up" | "left"; dur: number };
|
||||
update(t: number, ctx: Ctx): void;
|
||||
}
|
||||
|
||||
/** Map between authored scene time and output time for a set of slow-motion holds. */
|
||||
export function timeWarp(warp: [number, number, number][] = []) {
|
||||
const w = [...warp].sort((a, b) => a[0] - b[0]);
|
||||
const toOut = (t: number) => {
|
||||
let u = t;
|
||||
for (const [a, b, sp] of w) if (t > a) u += (Math.min(t, b) - a) * (1 / sp - 1);
|
||||
return u;
|
||||
};
|
||||
const toLocal = (u: number) => {
|
||||
let cur = 0;
|
||||
let o = 0;
|
||||
for (const [a, b, sp] of w) {
|
||||
if (u <= o + (a - cur)) return cur + (u - o);
|
||||
o += a - cur;
|
||||
cur = a;
|
||||
const len = (b - a) / sp;
|
||||
if (u <= o + len) return a + (u - o) * sp;
|
||||
o += len;
|
||||
cur = b;
|
||||
}
|
||||
return cur + (u - o);
|
||||
};
|
||||
return { toOut, toLocal };
|
||||
}
|
||||
Reference in new issue
Block a user