Background Beams
Berkas cahaya tipis melengkung yang mengalir, berdenyut, atau jatuh dan memercik di belakang konten. Murni SVG dan CSS, tanpa JavaScript.
Light up your launch
Release notes, waitlists, and changelogs that people actually read.
Light up your launch
Release notes, waitlists, and changelogs that people actually read.
Light up your launch
Release notes, waitlists, and changelogs that people actually read.
Light up your launch
Release notes, waitlists, and changelogs that people actually read.
Light up your launch
Release notes, waitlists, and changelogs that people actually read.
<x-markas.background-beams class="rounded-xl border border-line bg-surface px-6 py-16">
<div class="grid justify-items-center gap-4 text-center">
<h2 class="text-4xl font-bold tracking-tight text-ink">
Light up your launch
</h2>
<p class="max-w-72 text-sm text-muted">
Release notes, waitlists, and changelogs that people actually read.
</p>
<x-markas.button>Join the waitlist</x-markas.button>
</div>
</x-markas.background-beams>import { BackgroundBeams } from "@/components/markas/BackgroundBeams";
import { Button } from "@/components/markas/Button";
export default function BackgroundBeamsExample() {
return (
<BackgroundBeams className="rounded-xl border border-line bg-surface px-6 py-16">
<div className="grid justify-items-center gap-4 text-center">
<h2 className="text-4xl font-bold tracking-tight text-ink">
Light up your launch
</h2>
<p className="max-w-72 text-sm text-muted">
Release notes, waitlists, and changelogs that people actually read.
</p>
<Button>Join the waitlist</Button>
</div>
</BackgroundBeams>
);
}<script setup lang="ts">
import BackgroundBeams from "@/components/markas/BackgroundBeams.vue";
import Button from "@/components/markas/Button.vue";
</script>
<template>
<BackgroundBeams class="rounded-xl border border-line bg-surface px-6 py-16">
<div class="grid justify-items-center gap-4 text-center">
<h2 class="text-4xl font-bold tracking-tight text-ink">
Light up your launch
</h2>
<p class="max-w-72 text-sm text-muted">
Release notes, waitlists, and changelogs that people actually read.
</p>
<Button>Join the waitlist</Button>
</div>
</BackgroundBeams>
</template><script lang="ts">
import BackgroundBeams from "$lib/components/markas/BackgroundBeams.svelte";
import Button from "$lib/components/markas/Button.svelte";
</script>
<BackgroundBeams class="rounded-xl border border-line bg-surface px-6 py-16">
<div class="grid justify-items-center gap-4 text-center">
<h2 class="text-4xl font-bold tracking-tight text-ink">
Light up your launch
</h2>
<p class="max-w-72 text-sm text-muted">
Release notes, waitlists, and changelogs that people actually read.
</p>
<Button>Join the waitlist</Button>
</div>
</BackgroundBeams>---
import BackgroundBeams from "@/components/markas/BackgroundBeams.astro";
import Button from "@/components/markas/Button.astro";
---
<BackgroundBeams class="rounded-xl border border-line bg-surface px-6 py-16">
<div class="grid justify-items-center gap-4 text-center">
<h2 class="text-4xl font-bold tracking-tight text-ink">
Light up your launch
</h2>
<p class="max-w-72 text-sm text-muted">
Release notes, waitlists, and changelogs that people actually read.
</p>
<Button>Join the waitlist</Button>
</div>
</BackgroundBeams>import { Component } from "@angular/core";
import { BackgroundBeams } from "./markas/background-beams.component";
import { Button } from "./markas/button.component";
@Component({
selector: "markas-example",
imports: [BackgroundBeams, Button],
template: `
<div
markas-background-beams
class="rounded-xl border border-line bg-surface px-6 py-16"
>
<div class="grid justify-items-center gap-4 text-center">
<h2 class="text-4xl font-bold tracking-tight text-ink">
Light up your launch
</h2>
<p class="max-w-72 text-sm text-muted">
Release notes, waitlists, and changelogs that people actually read.
</p>
<button markas-button>Join the waitlist</button>
</div>
</div>
`,
})
export default class BackgroundBeamsFixture {}Contoh
Kartu newsletter berdenyut
<x-markas.background-beams
variant="pulse"
:count="10"
class="rounded-xl border border-line bg-canvas p-6"
>
<form class="grid gap-4">
<div class="grid gap-1">
<h3 class="text-xl font-semibold text-ink">The Friday digest</h3>
<p class="text-sm text-muted">
One email a week with the best product updates. No spam.
</p>
</div>
<div class="flex items-end gap-2">
<div class="flex-1">
<x-markas.input label="Email" type="email" placeholder="you@company.com" />
</div>
<x-markas.button type="submit">Subscribe</x-markas.button>
</div>
</form>
</x-markas.background-beams>import { BackgroundBeams } from "@/components/markas/BackgroundBeams";
import { Button } from "@/components/markas/Button";
import { Input } from "@/components/markas/Input";
export default function Example() {
return (
<BackgroundBeams
variant="pulse"
count={10}
className="rounded-xl border border-line bg-canvas p-6"
>
<form className="grid gap-4">
<div className="grid gap-1">
<h3 className="text-xl font-semibold text-ink">The Friday digest</h3>
<p className="text-sm text-muted">
One email a week with the best product updates. No spam.
</p>
</div>
<div className="flex items-end gap-2">
<div className="flex-1">
<Input label="Email" type="email" placeholder="you@company.com" />
</div>
<Button type="submit">Subscribe</Button>
</div>
</form>
</BackgroundBeams>
);
}<script setup lang="ts">
import BackgroundBeams from "@/components/markas/BackgroundBeams.vue";
import Button from "@/components/markas/Button.vue";
import Input from "@/components/markas/Input.vue";
</script>
<template>
<BackgroundBeams
variant="pulse"
:count="10"
class="rounded-xl border border-line bg-canvas p-6"
>
<form class="grid gap-4">
<div class="grid gap-1">
<h3 class="text-xl font-semibold text-ink">The Friday digest</h3>
<p class="text-sm text-muted">
One email a week with the best product updates. No spam.
</p>
</div>
<div class="flex items-end gap-2">
<div class="flex-1">
<Input label="Email" type="email" placeholder="you@company.com" />
</div>
<Button type="submit">Subscribe</Button>
</div>
</form>
</BackgroundBeams>
</template><script lang="ts">
import BackgroundBeams from "$lib/components/markas/BackgroundBeams.svelte";
import Button from "$lib/components/markas/Button.svelte";
import Input from "$lib/components/markas/Input.svelte";
</script>
<BackgroundBeams
variant="pulse"
count={10}
class="rounded-xl border border-line bg-canvas p-6"
>
<form class="grid gap-4">
<div class="grid gap-1">
<h3 class="text-xl font-semibold text-ink">The Friday digest</h3>
<p class="text-sm text-muted">
One email a week with the best product updates. No spam.
</p>
</div>
<div class="flex items-end gap-2">
<div class="flex-1">
<Input label="Email" type="email" placeholder="you@company.com" />
</div>
<Button type="submit">Subscribe</Button>
</div>
</form>
</BackgroundBeams>---
import BackgroundBeams from "@/components/markas/BackgroundBeams.astro";
import Button from "@/components/markas/Button.astro";
import Input from "@/components/markas/Input.astro";
---
<BackgroundBeams
variant="pulse"
count={10}
class="rounded-xl border border-line bg-canvas p-6"
>
<form class="grid gap-4">
<div class="grid gap-1">
<h3 class="text-xl font-semibold text-ink">The Friday digest</h3>
<p class="text-sm text-muted">
One email a week with the best product updates. No spam.
</p>
</div>
<div class="flex items-end gap-2">
<div class="flex-1">
<Input label="Email" type="email" placeholder="you@company.com" />
</div>
<Button type="submit">Subscribe</Button>
</div>
</form>
</BackgroundBeams>import { Component } from "@angular/core";
import { BackgroundBeams } from "./markas/background-beams.component";
import { Button } from "./markas/button.component";
import { Input } from "./markas/input.component";
@Component({
selector: "markas-example",
imports: [BackgroundBeams, Button, Input],
template: `
<div
markas-background-beams
variant="pulse"
[count]="10"
class="rounded-xl border border-line bg-canvas p-6"
>
<form class="grid gap-4">
<div class="grid gap-1">
<h3 class="text-xl font-semibold text-ink">The Friday digest</h3>
<p class="text-sm text-muted">
One email a week with the best product updates. No spam.
</p>
</div>
<div class="flex items-end gap-2">
<div class="flex-1">
<markas-input
label="Email"
type="email"
placeholder="you@company.com"
/>
</div>
<button markas-button type="submit">Subscribe</button>
</div>
</form>
</div>
`,
})
export default class BackgroundBeamsNewsletterExample {}Section fitur berkas bertabrakan
Built for impact
Every deploy lands safely, no matter how fast you ship.
-
99.99%
Uptime
-
40 ms
Edge latency
-
1 click
Rollback
Built for impact
Every deploy lands safely, no matter how fast you ship.
99.99%
Uptime
40 ms
Edge latency
1 click
Rollback
Built for impact
Every deploy lands safely, no matter how fast you ship.
99.99%
Uptime
40 ms
Edge latency
1 click
Rollback
Built for impact
Every deploy lands safely, no matter how fast you ship.
99.99%
Uptime
40 ms
Edge latency
1 click
Rollback
Built for impact
Every deploy lands safely, no matter how fast you ship.
99.99%
Uptime
40 ms
Edge latency
1 click
Rollback
<x-markas.background-beams
variant="collide"
:count="10"
class="rounded-xl border border-line bg-surface px-6 pt-8 pb-16"
>
<div class="grid gap-6">
<div class="grid gap-1 text-center">
<h3 class="text-2xl font-semibold text-ink">Built for impact</h3>
<p class="text-sm text-muted">
Every deploy lands safely, no matter how fast you ship.
</p>
</div>
<ul class="grid grid-cols-3 gap-3 text-center">
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">99.99%</p>
<p class="text-xs text-muted">Uptime</p>
</li>
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">40 ms</p>
<p class="text-xs text-muted">Edge latency</p>
</li>
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">1 click</p>
<p class="text-xs text-muted">Rollback</p>
</li>
</ul>
</div>
</x-markas.background-beams>import { BackgroundBeams } from "@/components/markas/BackgroundBeams";
export default function Example() {
return (
<BackgroundBeams
variant="collide"
count={10}
className="rounded-xl border border-line bg-surface px-6 pt-8 pb-16"
>
<div className="grid gap-6">
<div className="grid gap-1 text-center">
<h3 className="text-2xl font-semibold text-ink">Built for impact</h3>
<p className="text-sm text-muted">
Every deploy lands safely, no matter how fast you ship.
</p>
</div>
<ul className="grid grid-cols-3 gap-3 text-center">
<li className="rounded-lg border border-line bg-surface p-3">
<p className="text-lg font-semibold text-ink">99.99%</p>
<p className="text-xs text-muted">Uptime</p>
</li>
<li className="rounded-lg border border-line bg-surface p-3">
<p className="text-lg font-semibold text-ink">40 ms</p>
<p className="text-xs text-muted">Edge latency</p>
</li>
<li className="rounded-lg border border-line bg-surface p-3">
<p className="text-lg font-semibold text-ink">1 click</p>
<p className="text-xs text-muted">Rollback</p>
</li>
</ul>
</div>
</BackgroundBeams>
);
}<script setup lang="ts">
import BackgroundBeams from "@/components/markas/BackgroundBeams.vue";
</script>
<template>
<BackgroundBeams
variant="collide"
:count="10"
class="rounded-xl border border-line bg-surface px-6 pt-8 pb-16"
>
<div class="grid gap-6">
<div class="grid gap-1 text-center">
<h3 class="text-2xl font-semibold text-ink">Built for impact</h3>
<p class="text-sm text-muted">
Every deploy lands safely, no matter how fast you ship.
</p>
</div>
<ul class="grid grid-cols-3 gap-3 text-center">
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">99.99%</p>
<p class="text-xs text-muted">Uptime</p>
</li>
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">40 ms</p>
<p class="text-xs text-muted">Edge latency</p>
</li>
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">1 click</p>
<p class="text-xs text-muted">Rollback</p>
</li>
</ul>
</div>
</BackgroundBeams>
</template><script lang="ts">
import BackgroundBeams from "$lib/components/markas/BackgroundBeams.svelte";
</script>
<BackgroundBeams
variant="collide"
count={10}
class="rounded-xl border border-line bg-surface px-6 pt-8 pb-16"
>
<div class="grid gap-6">
<div class="grid gap-1 text-center">
<h3 class="text-2xl font-semibold text-ink">Built for impact</h3>
<p class="text-sm text-muted">
Every deploy lands safely, no matter how fast you ship.
</p>
</div>
<ul class="grid grid-cols-3 gap-3 text-center">
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">99.99%</p>
<p class="text-xs text-muted">Uptime</p>
</li>
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">40 ms</p>
<p class="text-xs text-muted">Edge latency</p>
</li>
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">1 click</p>
<p class="text-xs text-muted">Rollback</p>
</li>
</ul>
</div>
</BackgroundBeams>---
import BackgroundBeams from "@/components/markas/BackgroundBeams.astro";
---
<BackgroundBeams
variant="collide"
count={10}
class="rounded-xl border border-line bg-surface px-6 pt-8 pb-16"
>
<div class="grid gap-6">
<div class="grid gap-1 text-center">
<h3 class="text-2xl font-semibold text-ink">Built for impact</h3>
<p class="text-sm text-muted">
Every deploy lands safely, no matter how fast you ship.
</p>
</div>
<ul class="grid grid-cols-3 gap-3 text-center">
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">99.99%</p>
<p class="text-xs text-muted">Uptime</p>
</li>
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">40 ms</p>
<p class="text-xs text-muted">Edge latency</p>
</li>
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">1 click</p>
<p class="text-xs text-muted">Rollback</p>
</li>
</ul>
</div>
</BackgroundBeams>import { Component } from "@angular/core";
import { BackgroundBeams } from "./markas/background-beams.component";
@Component({
selector: "markas-example",
imports: [BackgroundBeams],
template: `
<div
markas-background-beams
variant="collide"
[count]="10"
class="rounded-xl border border-line bg-surface px-6 pt-8 pb-16"
>
<div class="grid gap-6">
<div class="grid gap-1 text-center">
<h3 class="text-2xl font-semibold text-ink">Built for impact</h3>
<p class="text-sm text-muted">
Every deploy lands safely, no matter how fast you ship.
</p>
</div>
<ul class="grid grid-cols-3 gap-3 text-center">
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">99.99%</p>
<p class="text-xs text-muted">Uptime</p>
</li>
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">40 ms</p>
<p class="text-xs text-muted">Edge latency</p>
</li>
<li class="rounded-lg border border-line bg-surface p-3">
<p class="text-lg font-semibold text-ink">1 click</p>
<p class="text-xs text-muted">Rollback</p>
</li>
</ul>
</div>
</div>
`,
})
export default class BackgroundBeamsFeaturesExample {}Hero selalu gelap
Every signal, one view
Logs, traces, and alerts flow into a single timeline your team can trust.
Every signal, one view
Logs, traces, and alerts flow into a single timeline your team can trust.
Every signal, one view
Logs, traces, and alerts flow into a single timeline your team can trust.
Every signal, one view
Logs, traces, and alerts flow into a single timeline your team can trust.
Every signal, one view
Logs, traces, and alerts flow into a single timeline your team can trust.
<x-markas.background-beams
color="success"
:count="12"
speed="slow"
class="dark rounded-xl bg-canvas px-6 py-14 text-ink"
>
<div class="grid justify-items-center gap-4 text-center">
<h3 class="text-3xl font-bold tracking-tight text-ink">
Every signal, one view
</h3>
<p class="max-w-72 text-sm text-muted">
Logs, traces, and alerts flow into a single timeline your team can
trust.
</p>
<div class="flex gap-2">
<x-markas.button>Start monitoring</x-markas.button>
<x-markas.button variant="secondary">View demo</x-markas.button>
</div>
</div>
</x-markas.background-beams>import { BackgroundBeams } from "@/components/markas/BackgroundBeams";
import { Button } from "@/components/markas/Button";
export default function Example() {
return (
<BackgroundBeams
color="success"
count={12}
speed="slow"
className="dark rounded-xl bg-canvas px-6 py-14 text-ink"
>
<div className="grid justify-items-center gap-4 text-center">
<h3 className="text-3xl font-bold tracking-tight text-ink">
Every signal, one view
</h3>
<p className="max-w-72 text-sm text-muted">
Logs, traces, and alerts flow into a single timeline your team can
trust.
</p>
<div className="flex gap-2">
<Button>Start monitoring</Button>
<Button variant="secondary">View demo</Button>
</div>
</div>
</BackgroundBeams>
);
}<script setup lang="ts">
import BackgroundBeams from "@/components/markas/BackgroundBeams.vue";
import Button from "@/components/markas/Button.vue";
</script>
<template>
<BackgroundBeams
color="success"
:count="12"
speed="slow"
class="dark rounded-xl bg-canvas px-6 py-14 text-ink"
>
<div class="grid justify-items-center gap-4 text-center">
<h3 class="text-3xl font-bold tracking-tight text-ink">
Every signal, one view
</h3>
<p class="max-w-72 text-sm text-muted">
Logs, traces, and alerts flow into a single timeline your team can
trust.
</p>
<div class="flex gap-2">
<Button>Start monitoring</Button>
<Button variant="secondary">View demo</Button>
</div>
</div>
</BackgroundBeams>
</template><script lang="ts">
import BackgroundBeams from "$lib/components/markas/BackgroundBeams.svelte";
import Button from "$lib/components/markas/Button.svelte";
</script>
<BackgroundBeams
color="success"
count={12}
speed="slow"
class="dark rounded-xl bg-canvas px-6 py-14 text-ink"
>
<div class="grid justify-items-center gap-4 text-center">
<h3 class="text-3xl font-bold tracking-tight text-ink">
Every signal, one view
</h3>
<p class="max-w-72 text-sm text-muted">
Logs, traces, and alerts flow into a single timeline your team can trust.
</p>
<div class="flex gap-2">
<Button>Start monitoring</Button>
<Button variant="secondary">View demo</Button>
</div>
</div>
</BackgroundBeams>---
import BackgroundBeams from "@/components/markas/BackgroundBeams.astro";
import Button from "@/components/markas/Button.astro";
---
<BackgroundBeams
color="success"
count={12}
speed="slow"
class="dark rounded-xl bg-canvas px-6 py-14 text-ink"
>
<div class="grid justify-items-center gap-4 text-center">
<h3 class="text-3xl font-bold tracking-tight text-ink">
Every signal, one view
</h3>
<p class="max-w-72 text-sm text-muted">
Logs, traces, and alerts flow into a single timeline your team can
trust.
</p>
<div class="flex gap-2">
<Button>Start monitoring</Button>
<Button variant="secondary">View demo</Button>
</div>
</div>
</BackgroundBeams>import { Component } from "@angular/core";
import { BackgroundBeams } from "./markas/background-beams.component";
import { Button } from "./markas/button.component";
@Component({
selector: "markas-example",
imports: [BackgroundBeams, Button],
template: `
<div
markas-background-beams
color="success"
[count]="12"
speed="slow"
class="dark rounded-xl bg-canvas px-6 py-14 text-ink"
>
<div class="grid justify-items-center gap-4 text-center">
<h3 class="text-3xl font-bold tracking-tight text-ink">
Every signal, one view
</h3>
<p class="max-w-72 text-sm text-muted">
Logs, traces, and alerts flow into a single timeline your team can
trust.
</p>
<div class="flex gap-2">
<button markas-button>Start monitoring</button>
<button markas-button variant="secondary">View demo</button>
</div>
</div>
</div>
`,
})
export default class BackgroundBeamsDarkHeroExample {}Instalasi
npx markasui@latest add background-beamspnpm dlx markasui@latest add background-beamsyarn dlx markasui@latest add background-beamsbunx --bun markasui@latest add background-beams- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
resources/views/components/markas/background-beams.blade.php.
@props([
'variant' => 'flow',
'count' => 8,
'speed' => 'normal',
'color' => 'primary',
])
@php
$base = 'relative isolate overflow-hidden';
$layer = 'pointer-events-none absolute inset-0 size-full [mask-image:radial-gradient(ellipse_at_center,black_30%,transparent_80%)]';
$track = 'opacity-15';
$beams = [
'flow' => 'animate-[markas-beams-flow_var(--markas-beams-duration)_linear_infinite] motion-reduce:animate-none',
'pulse' => 'animate-[markas-beams-pulse_var(--markas-beams-duration)_ease-in-out_infinite] motion-reduce:animate-none',
];
$rainLayer = 'pointer-events-none absolute inset-0';
$floor = 'absolute inset-x-0 bottom-0 h-px bg-current opacity-30';
$drop = 'absolute top-0 h-full w-px animate-[markas-beams-fall_var(--markas-beams-duration)_linear_infinite] bg-[linear-gradient(to_bottom,transparent_75%,currentColor)] motion-reduce:animate-none';
$splash = 'absolute bottom-0 size-10 -translate-x-1/2 translate-y-1/2 animate-[markas-beams-splash_var(--markas-beams-duration)_linear_infinite] rounded-full bg-[radial-gradient(circle,currentColor,transparent_65%)] opacity-0 motion-reduce:animate-none';
$content = 'relative';
$colors = [
'muted' => 'text-muted',
'primary' => 'text-primary',
'success' => 'text-success',
'warning' => 'text-warning',
'danger' => 'text-danger',
];
$speeds = ['slow' => '12s', 'normal' => '7s', 'fast' => '4s'];
$keyframes = '@keyframes markas-beams-flow{from{stroke-dashoffset:14}to{stroke-dashoffset:-100}}@keyframes markas-beams-pulse{0%,100%{opacity:.1}50%{opacity:.9}}@keyframes markas-beams-fall{0%{translate:0 -100%;opacity:1}70%{translate:0 0;opacity:1}71%,100%{translate:0 0;opacity:0}}@keyframes markas-beams-splash{0%,69%{opacity:0;scale:.3}72%{opacity:1}100%{opacity:0;scale:1.6}}';
$maxBeams = 16;
$beamDelayMs = 900;
$rates = ['1', '1.3', '0.8', '1.15', '0.9'];
$total = max(0, min((int) $count, $maxBeams));
$tone = $colors[$color] ?? $colors['primary'];
$isCollide = $variant === 'collide';
$isPulse = $variant === 'pulse';
// Berkas vertikal ke-i: posisi, tinggi awal, laju, dan jeda dari rumus supaya tiga framework sama.
$drops = [];
// Kurva ke-i di kanvas 800x400, menyapu dari kiri atas ke kanan bawah. Bilangan bulat saja.
$curves = [];
for ($i = 0; $i < $total; $i++) {
$delay = 'animation-delay: '.($i * -$beamDelayMs).'ms';
if ($isCollide) {
$left = 'left: '.((intdiv((2 * $i + 1) * 500, max(1, $total)) + (($i * 37) % 11) - 5) / 10).'%';
$timing = 'animation-duration: calc(var(--markas-beams-duration) * '.$rates[$i % count($rates)].'); '.$delay;
$drops[] = [
'drop' => $timing.'; '.$left.'; translate: 0 -'.(($i * 23) % 80).'%',
'splash' => $timing.'; '.$left,
];
} else {
$shift = intdiv($i * 640, max(1, $total));
$bend = ($i % 3) * 30;
$curves[] = [
'd' => 'M '.($shift - 200).' -20 C '.$shift.' '.(120 + $bend).', '.($shift + 160).' '.(260 - $bend).', '.($shift + 620).' 420',
'style' => $isPulse ? 'opacity: '.((($i % 4) + 3) / 10).'; '.$delay : 'stroke-dashoffset: '.(-(($i * 37) % 90)).'; '.$delay,
];
}
}
@endphp
<div {{ $attributes->merge(['style' => '--markas-beams-duration: '.($speeds[$speed] ?? $speeds['normal'])])->class([$base]) }}>
<style>{!! $keyframes !!}</style>
@if ($isCollide)
<div aria-hidden="true" wire:ignore @class([$rainLayer, $tone])>
<span class="{{ $floor }}"></span>
@foreach ($drops as $item)
<span><span class="{{ $drop }}" style="{{ $item['drop'] }}"></span><span class="{{ $splash }}" style="{{ $item['splash'] }}"></span></span>
@endforeach
</div>
@else
<svg aria-hidden="true" wire:ignore @class([$layer, $tone]) viewBox="0 0 800 400" preserveAspectRatio="xMidYMid slice" fill="none" stroke="currentColor" stroke-linecap="round">
@foreach ($curves as $item)
<g>
<path class="{{ $track }}" d="{{ $item['d'] }}" stroke-width="1"></path>
<path class="{{ $isPulse ? $beams['pulse'] : $beams['flow'] }}" d="{{ $item['d'] }}" stroke-width="2" pathLength="100" @if (! $isPulse) stroke-dasharray="14 186" @endif style="{{ $item['style'] }}"></path>
</g>
@endforeach
</svg>
@endif
<div class="{{ $content }}">{{ $slot }}</div>
</div>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/components/markas/BackgroundBeams.tsx.
import type { ComponentProps, CSSProperties } from "react";
const base = "relative isolate overflow-hidden";
const layer =
"pointer-events-none absolute inset-0 size-full [mask-image:radial-gradient(ellipse_at_center,black_30%,transparent_80%)]";
const track = "opacity-15";
const beams = {
flow: "animate-[markas-beams-flow_var(--markas-beams-duration)_linear_infinite] motion-reduce:animate-none",
pulse:
"animate-[markas-beams-pulse_var(--markas-beams-duration)_ease-in-out_infinite] motion-reduce:animate-none",
};
const rainLayer = "pointer-events-none absolute inset-0";
const floor = "absolute inset-x-0 bottom-0 h-px bg-current opacity-30";
const drop =
"absolute top-0 h-full w-px animate-[markas-beams-fall_var(--markas-beams-duration)_linear_infinite] bg-[linear-gradient(to_bottom,transparent_75%,currentColor)] motion-reduce:animate-none";
const splash =
"absolute bottom-0 size-10 -translate-x-1/2 translate-y-1/2 animate-[markas-beams-splash_var(--markas-beams-duration)_linear_infinite] rounded-full bg-[radial-gradient(circle,currentColor,transparent_65%)] opacity-0 motion-reduce:animate-none";
const content = "relative";
const colors = {
muted: "text-muted",
primary: "text-primary",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const speeds = { slow: "12s", normal: "7s", fast: "4s" };
const keyframes =
"@keyframes markas-beams-flow{from{stroke-dashoffset:14}to{stroke-dashoffset:-100}}@keyframes markas-beams-pulse{0%,100%{opacity:.1}50%{opacity:.9}}@keyframes markas-beams-fall{0%{translate:0 -100%;opacity:1}70%{translate:0 0;opacity:1}71%,100%{translate:0 0;opacity:0}}@keyframes markas-beams-splash{0%,69%{opacity:0;scale:.3}72%{opacity:1}100%{opacity:0;scale:1.6}}";
const MAX_BEAMS = 16;
const BEAM_DELAY_MS = 900;
const RATES = ["1", "1.3", "0.8", "1.15", "0.9"];
const cx = (...c: (string | false | null | undefined)[]) =>
c.filter(Boolean).join(" ");
type Variant = "flow" | "pulse" | "collide";
const clamp = (count: number) =>
Math.max(0, Math.min(Math.trunc(count), MAX_BEAMS));
/** Kurva ke-i di kanvas 800x400, menyapu dari kiri atas ke kanan bawah. Bilangan bulat saja. */
function makeCurves(variant: Variant, count: number) {
const total = clamp(count);
return Array.from({ length: total }, (_, index) => {
const shift = Math.floor((index * 640) / Math.max(1, total));
const bend = (index % 3) * 30;
return {
d: `M ${shift - 200} -20 C ${shift} ${120 + bend}, ${shift + 160} ${260 - bend}, ${shift + 620} 420`,
style:
variant === "pulse"
? {
opacity: ((index % 4) + 3) / 10,
animationDelay: `${index * -BEAM_DELAY_MS}ms`,
}
: {
strokeDashoffset: -((index * 37) % 90),
animationDelay: `${index * -BEAM_DELAY_MS}ms`,
},
};
});
}
/** Berkas vertikal ke-i: posisi, tinggi awal, laju, dan jeda dari rumus supaya tiga framework sama. */
function makeDrops(count: number) {
const total = clamp(count);
return Array.from({ length: total }, (_, index) => {
const left = `${(Math.floor(((2 * index + 1) * 500) / Math.max(1, total)) + ((index * 37) % 11) - 5) / 10}%`;
const timing = {
animationDuration: `calc(var(--markas-beams-duration) * ${RATES[index % RATES.length]})`,
animationDelay: `${index * -BEAM_DELAY_MS}ms`,
};
return {
drop: { ...timing, left, translate: `0 -${(index * 23) % 80}%` },
splash: { ...timing, left },
};
});
}
export type BackgroundBeamsProps = ComponentProps<"div"> & {
variant?: Variant;
count?: number;
speed?: keyof typeof speeds;
color?: keyof typeof colors;
};
export function BackgroundBeams({
variant = "flow",
count = 8,
speed = "normal",
color = "primary",
className,
style,
children,
...props
}: BackgroundBeamsProps) {
const vars = { "--markas-beams-duration": speeds[speed] } as CSSProperties;
return (
<div
{...props}
className={cx(base, className)}
style={{ ...vars, ...style }}
>
<style>{keyframes}</style>
{variant === "collide" ? (
<div aria-hidden="true" className={cx(rainLayer, colors[color])}>
<span className={floor} />
{makeDrops(count).map((item, index) => (
<span key={index}>
<span className={drop} style={item.drop} />
<span className={splash} style={item.splash} />
</span>
))}
</div>
) : (
<svg
aria-hidden="true"
className={cx(layer, colors[color])}
viewBox="0 0 800 400"
preserveAspectRatio="xMidYMid slice"
fill="none"
stroke="currentColor"
strokeLinecap="round"
>
{makeCurves(variant, count).map((item, index) => (
<g key={index}>
<path className={track} d={item.d} strokeWidth="1" />
<path
className={beams[variant]}
d={item.d}
strokeWidth="2"
pathLength={100}
strokeDasharray={variant === "flow" ? "14 186" : undefined}
style={item.style}
/>
</g>
))}
</svg>
)}
<div className={content}>{children}</div>
</div>
);
}- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/components/markas/BackgroundBeams.vue.
<script setup lang="ts">
import { computed } from "vue";
const base = "relative isolate overflow-hidden";
const layer =
"pointer-events-none absolute inset-0 size-full [mask-image:radial-gradient(ellipse_at_center,black_30%,transparent_80%)]";
const track = "opacity-15";
const beams = {
flow: "animate-[markas-beams-flow_var(--markas-beams-duration)_linear_infinite] motion-reduce:animate-none",
pulse:
"animate-[markas-beams-pulse_var(--markas-beams-duration)_ease-in-out_infinite] motion-reduce:animate-none",
};
const rainLayer = "pointer-events-none absolute inset-0";
const floor = "absolute inset-x-0 bottom-0 h-px bg-current opacity-30";
const drop =
"absolute top-0 h-full w-px animate-[markas-beams-fall_var(--markas-beams-duration)_linear_infinite] bg-[linear-gradient(to_bottom,transparent_75%,currentColor)] motion-reduce:animate-none";
const splash =
"absolute bottom-0 size-10 -translate-x-1/2 translate-y-1/2 animate-[markas-beams-splash_var(--markas-beams-duration)_linear_infinite] rounded-full bg-[radial-gradient(circle,currentColor,transparent_65%)] opacity-0 motion-reduce:animate-none";
const content = "relative";
const colors = {
muted: "text-muted",
primary: "text-primary",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const speeds = { slow: "12s", normal: "7s", fast: "4s" };
const keyframes =
"@keyframes markas-beams-flow{from{stroke-dashoffset:14}to{stroke-dashoffset:-100}}@keyframes markas-beams-pulse{0%,100%{opacity:.1}50%{opacity:.9}}@keyframes markas-beams-fall{0%{translate:0 -100%;opacity:1}70%{translate:0 0;opacity:1}71%,100%{translate:0 0;opacity:0}}@keyframes markas-beams-splash{0%,69%{opacity:0;scale:.3}72%{opacity:1}100%{opacity:0;scale:1.6}}";
const MAX_BEAMS = 16;
const BEAM_DELAY_MS = 900;
const RATES = ["1", "1.3", "0.8", "1.15", "0.9"];
type Variant = "flow" | "pulse" | "collide";
const clamp = (count: number) =>
Math.max(0, Math.min(Math.trunc(count), MAX_BEAMS));
/** Kurva ke-i di kanvas 800x400, menyapu dari kiri atas ke kanan bawah. Bilangan bulat saja. */
function makeCurves(variant: Variant, count: number) {
const total = clamp(count);
return Array.from({ length: total }, (_, index) => {
const shift = Math.floor((index * 640) / Math.max(1, total));
const bend = (index % 3) * 30;
return {
d: `M ${shift - 200} -20 C ${shift} ${120 + bend}, ${shift + 160} ${260 - bend}, ${shift + 620} 420`,
style:
variant === "pulse"
? {
opacity: ((index % 4) + 3) / 10,
animationDelay: `${index * -BEAM_DELAY_MS}ms`,
}
: {
strokeDashoffset: -((index * 37) % 90),
animationDelay: `${index * -BEAM_DELAY_MS}ms`,
},
};
});
}
/** Berkas vertikal ke-i: posisi, tinggi awal, laju, dan jeda dari rumus supaya tiga framework sama. */
function makeDrops(count: number) {
const total = clamp(count);
return Array.from({ length: total }, (_, index) => {
const left = `${(Math.floor(((2 * index + 1) * 500) / Math.max(1, total)) + ((index * 37) % 11) - 5) / 10}%`;
const timing = {
animationDuration: `calc(var(--markas-beams-duration) * ${RATES[index % RATES.length]})`,
animationDelay: `${index * -BEAM_DELAY_MS}ms`,
};
return {
drop: { ...timing, left, translate: `0 -${(index * 23) % 80}%` },
splash: { ...timing, left },
};
});
}
const props = withDefaults(
defineProps<{
variant?: Variant;
count?: number;
speed?: keyof typeof speeds;
color?: keyof typeof colors;
}>(),
{ variant: "flow", count: 8, speed: "normal", color: "primary" },
);
const vars = computed(() => ({
"--markas-beams-duration": speeds[props.speed],
}));
const curves = computed(() =>
props.variant === "collide" ? [] : makeCurves(props.variant, props.count),
);
const drops = computed(() =>
props.variant === "collide" ? makeDrops(props.count) : [],
);
</script>
<template>
<div :class="base" :style="vars">
<component :is="'style'">{{ keyframes }}</component>
<div
v-if="props.variant === 'collide'"
aria-hidden="true"
:class="[rainLayer, colors[props.color]]"
>
<span :class="floor" />
<span v-for="(item, index) in drops" :key="index">
<span :class="drop" :style="item.drop" />
<span :class="splash" :style="item.splash" />
</span>
</div>
<svg
v-else
aria-hidden="true"
:class="[layer, colors[props.color]]"
viewBox="0 0 800 400"
preserveAspectRatio="xMidYMid slice"
fill="none"
stroke="currentColor"
stroke-linecap="round"
>
<g v-for="(item, index) in curves" :key="index">
<path :class="track" :d="item.d" stroke-width="1" />
<path
:class="beams[props.variant === 'pulse' ? 'pulse' : 'flow']"
:d="item.d"
stroke-width="2"
pathLength="100"
:stroke-dasharray="props.variant === 'flow' ? '14 186' : undefined"
:style="item.style"
/>
</g>
</svg>
<div :class="content"><slot /></div>
</div>
</template>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/lib/components/markas/BackgroundBeams.svelte.
<script lang="ts">
import type { Snippet } from "svelte";
import type { HTMLAttributes } from "svelte/elements";
const base = "relative isolate overflow-hidden";
const layer =
"pointer-events-none absolute inset-0 size-full [mask-image:radial-gradient(ellipse_at_center,black_30%,transparent_80%)]";
const track = "opacity-15";
const beams = {
flow: "animate-[markas-beams-flow_var(--markas-beams-duration)_linear_infinite] motion-reduce:animate-none",
pulse:
"animate-[markas-beams-pulse_var(--markas-beams-duration)_ease-in-out_infinite] motion-reduce:animate-none",
};
const rainLayer = "pointer-events-none absolute inset-0";
const floor = "absolute inset-x-0 bottom-0 h-px bg-current opacity-30";
const drop =
"absolute top-0 h-full w-px animate-[markas-beams-fall_var(--markas-beams-duration)_linear_infinite] bg-[linear-gradient(to_bottom,transparent_75%,currentColor)] motion-reduce:animate-none";
const splash =
"absolute bottom-0 size-10 -translate-x-1/2 translate-y-1/2 animate-[markas-beams-splash_var(--markas-beams-duration)_linear_infinite] rounded-full bg-[radial-gradient(circle,currentColor,transparent_65%)] opacity-0 motion-reduce:animate-none";
const content = "relative";
const colors = {
muted: "text-muted",
primary: "text-primary",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const speeds = { slow: "12s", normal: "7s", fast: "4s" };
const keyframes =
"@keyframes markas-beams-flow{from{stroke-dashoffset:14}to{stroke-dashoffset:-100}}@keyframes markas-beams-pulse{0%,100%{opacity:.1}50%{opacity:.9}}@keyframes markas-beams-fall{0%{translate:0 -100%;opacity:1}70%{translate:0 0;opacity:1}71%,100%{translate:0 0;opacity:0}}@keyframes markas-beams-splash{0%,69%{opacity:0;scale:.3}72%{opacity:1}100%{opacity:0;scale:1.6}}";
const MAX_BEAMS = 16;
const BEAM_DELAY_MS = 900;
const RATES = ["1", "1.3", "0.8", "1.15", "0.9"];
type Variant = "flow" | "pulse" | "collide";
const clamp = (count: number) =>
Math.max(0, Math.min(Math.trunc(count), MAX_BEAMS));
/** Kurva ke-i di kanvas 800x400, menyapu dari kiri atas ke kanan bawah. Bilangan bulat saja. */
function makeCurves(variant: Variant, count: number) {
const total = clamp(count);
return Array.from({ length: total }, (_, index) => {
const shift = Math.floor((index * 640) / Math.max(1, total));
const bend = (index % 3) * 30;
const delay = `animation-delay:${index * -BEAM_DELAY_MS}ms`;
return {
d: `M ${shift - 200} -20 C ${shift} ${120 + bend}, ${shift + 160} ${260 - bend}, ${shift + 620} 420`,
style:
variant === "pulse"
? `opacity:${((index % 4) + 3) / 10};${delay}`
: `stroke-dashoffset:${-((index * 37) % 90)};${delay}`,
};
});
}
/** Berkas vertikal ke-i: posisi, tinggi awal, laju, dan jeda dari rumus supaya semua framework sama. */
function makeDrops(count: number) {
const total = clamp(count);
return Array.from({ length: total }, (_, index) => {
const left = `left:${(Math.floor(((2 * index + 1) * 500) / Math.max(1, total)) + ((index * 37) % 11) - 5) / 10}%`;
const timing = `animation-duration:calc(var(--markas-beams-duration) * ${RATES[index % RATES.length]});animation-delay:${index * -BEAM_DELAY_MS}ms`;
return {
drop: `${timing};${left};translate:0 -${(index * 23) % 80}%`,
splash: `${timing};${left}`,
};
});
}
type Props = HTMLAttributes<HTMLDivElement> & {
variant?: Variant;
count?: number;
speed?: keyof typeof speeds;
color?: keyof typeof colors;
children?: Snippet;
};
let {
variant = "flow",
count = 8,
speed = "normal",
color = "primary",
class: className,
style,
children,
...rest
}: Props = $props();
const curves = $derived(
variant === "collide" ? [] : makeCurves(variant, count),
);
const drops = $derived(variant === "collide" ? makeDrops(count) : []);
</script>
<div
{...rest}
class={[base, className]}
style="--markas-beams-duration:{speeds[speed]};{style ?? ''}"
>
{@html `<style>${keyframes}</style>`}
{#if variant === "collide"}
<div aria-hidden="true" class={[rainLayer, colors[color]]}>
<span class={floor}></span>
{#each drops as item, index (index)}
<span>
<span class={drop} style={item.drop}></span>
<span class={splash} style={item.splash}></span>
</span>
{/each}
</div>
{:else}
<svg
aria-hidden="true"
class={[layer, colors[color]]}
viewBox="0 0 800 400"
preserveAspectRatio="xMidYMid slice"
fill="none"
stroke="currentColor"
stroke-linecap="round"
>
{#each curves as item, index (index)}
<g>
<path class={track} d={item.d} stroke-width="1" />
<path
class={beams[variant === "pulse" ? "pulse" : "flow"]}
d={item.d}
stroke-width="2"
pathLength="100"
stroke-dasharray={variant === "flow" ? "14 186" : undefined}
style={item.style}
/>
</g>
{/each}
</svg>
{/if}
<div class={content}>{@render children?.()}</div>
</div>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/components/markas/BackgroundBeams.astro.
---
import type { HTMLAttributes } from "astro/types";
const base = "relative isolate overflow-hidden";
const layer =
"pointer-events-none absolute inset-0 size-full [mask-image:radial-gradient(ellipse_at_center,black_30%,transparent_80%)]";
const track = "opacity-15";
const beams = {
flow: "animate-[markas-beams-flow_var(--markas-beams-duration)_linear_infinite] motion-reduce:animate-none",
pulse:
"animate-[markas-beams-pulse_var(--markas-beams-duration)_ease-in-out_infinite] motion-reduce:animate-none",
};
const rainLayer = "pointer-events-none absolute inset-0";
const floor = "absolute inset-x-0 bottom-0 h-px bg-current opacity-30";
const drop =
"absolute top-0 h-full w-px animate-[markas-beams-fall_var(--markas-beams-duration)_linear_infinite] bg-[linear-gradient(to_bottom,transparent_75%,currentColor)] motion-reduce:animate-none";
const splash =
"absolute bottom-0 size-10 -translate-x-1/2 translate-y-1/2 animate-[markas-beams-splash_var(--markas-beams-duration)_linear_infinite] rounded-full bg-[radial-gradient(circle,currentColor,transparent_65%)] opacity-0 motion-reduce:animate-none";
const content = "relative";
const colors = {
muted: "text-muted",
primary: "text-primary",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const speeds = { slow: "12s", normal: "7s", fast: "4s" };
const keyframes =
"@keyframes markas-beams-flow{from{stroke-dashoffset:14}to{stroke-dashoffset:-100}}@keyframes markas-beams-pulse{0%,100%{opacity:.1}50%{opacity:.9}}@keyframes markas-beams-fall{0%{translate:0 -100%;opacity:1}70%{translate:0 0;opacity:1}71%,100%{translate:0 0;opacity:0}}@keyframes markas-beams-splash{0%,69%{opacity:0;scale:.3}72%{opacity:1}100%{opacity:0;scale:1.6}}";
const MAX_BEAMS = 16;
const BEAM_DELAY_MS = 900;
const RATES = ["1", "1.3", "0.8", "1.15", "0.9"];
type Variant = "flow" | "pulse" | "collide";
const clamp = (count: number) =>
Math.max(0, Math.min(Math.trunc(count), MAX_BEAMS));
/** Kurva ke-i di kanvas 800x400, menyapu dari kiri atas ke kanan bawah. Bilangan bulat saja. */
function makeCurves(variant: Variant, count: number) {
const total = clamp(count);
return Array.from({ length: total }, (_, index) => {
const shift = Math.floor((index * 640) / Math.max(1, total));
const bend = (index % 3) * 30;
const delay = `animation-delay:${index * -BEAM_DELAY_MS}ms`;
return {
d: `M ${shift - 200} -20 C ${shift} ${120 + bend}, ${shift + 160} ${260 - bend}, ${shift + 620} 420`,
style:
variant === "pulse"
? `opacity:${((index % 4) + 3) / 10};${delay}`
: `stroke-dashoffset:${-((index * 37) % 90)};${delay}`,
};
});
}
/** Berkas vertikal ke-i: posisi, tinggi awal, laju, dan jeda dari rumus supaya semua framework sama. */
function makeDrops(count: number) {
const total = clamp(count);
return Array.from({ length: total }, (_, index) => {
const left = `left:${(Math.floor(((2 * index + 1) * 500) / Math.max(1, total)) + ((index * 37) % 11) - 5) / 10}%`;
const timing = `animation-duration:calc(var(--markas-beams-duration) * ${RATES[index % RATES.length]});animation-delay:${index * -BEAM_DELAY_MS}ms`;
return {
drop: `${timing};${left};translate:0 -${(index * 23) % 80}%`,
splash: `${timing};${left}`,
};
});
}
type Props = Omit<HTMLAttributes<"div">, "style"> & {
variant?: Variant;
count?: number;
speed?: keyof typeof speeds;
color?: keyof typeof colors;
style?: string;
};
const {
variant = "flow",
count = 8,
speed = "normal",
color = "primary",
class: className,
style,
...rest
} = Astro.props;
---
<div
{...rest}
class:list={[base, className]}
style={`--markas-beams-duration:${speeds[speed]};${style ?? ""}`}
>
<style is:inline set:html={keyframes} />
{
variant === "collide" ? (
<div aria-hidden="true" class:list={[rainLayer, colors[color]]}>
<span class={floor} />
{makeDrops(count).map((item) => (
<span>
<span class={drop} style={item.drop} />
<span class={splash} style={item.splash} />
</span>
))}
</div>
) : (
<svg
aria-hidden="true"
class:list={[layer, colors[color]]}
viewBox="0 0 800 400"
preserveAspectRatio="xMidYMid slice"
fill="none"
stroke="currentColor"
stroke-linecap="round"
>
{makeCurves(variant, count).map((item) => (
<g>
<path class={track} d={item.d} stroke-width="1" />
<path
class={beams[variant === "pulse" ? "pulse" : "flow"]}
d={item.d}
stroke-width="2"
pathLength="100"
stroke-dasharray={variant === "flow" ? "14 186" : undefined}
style={item.style}
/>
</g>
))}
</svg>
)
}
<div class={content}><slot /></div>
</div>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
src/app/markas/background-beams.component.ts.
import {
ChangeDetectionStrategy,
Component,
computed,
input,
numberAttribute,
ViewEncapsulation,
} from "@angular/core";
const base = "relative isolate overflow-hidden";
const layer =
"pointer-events-none absolute inset-0 size-full [mask-image:radial-gradient(ellipse_at_center,black_30%,transparent_80%)]";
const track = "opacity-15";
const beams = {
flow: "animate-[markas-beams-flow_var(--markas-beams-duration)_linear_infinite] motion-reduce:animate-none",
pulse:
"animate-[markas-beams-pulse_var(--markas-beams-duration)_ease-in-out_infinite] motion-reduce:animate-none",
};
const rainLayer = "pointer-events-none absolute inset-0";
const floor = "absolute inset-x-0 bottom-0 h-px bg-current opacity-30";
const drop =
"absolute top-0 h-full w-px animate-[markas-beams-fall_var(--markas-beams-duration)_linear_infinite] bg-[linear-gradient(to_bottom,transparent_75%,currentColor)] motion-reduce:animate-none";
const splash =
"absolute bottom-0 size-10 -translate-x-1/2 translate-y-1/2 animate-[markas-beams-splash_var(--markas-beams-duration)_linear_infinite] rounded-full bg-[radial-gradient(circle,currentColor,transparent_65%)] opacity-0 motion-reduce:animate-none";
const content = "relative";
const colors = {
muted: "text-muted",
primary: "text-primary",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const speeds = { slow: "12s", normal: "7s", fast: "4s" };
const keyframes =
"@keyframes markas-beams-flow{from{stroke-dashoffset:14}to{stroke-dashoffset:-100}}@keyframes markas-beams-pulse{0%,100%{opacity:.1}50%{opacity:.9}}@keyframes markas-beams-fall{0%{translate:0 -100%;opacity:1}70%{translate:0 0;opacity:1}71%,100%{translate:0 0;opacity:0}}@keyframes markas-beams-splash{0%,69%{opacity:0;scale:.3}72%{opacity:1}100%{opacity:0;scale:1.6}}";
const MAX_BEAMS = 16;
const BEAM_DELAY_MS = 900;
const RATES = ["1", "1.3", "0.8", "1.15", "0.9"];
export type BackgroundBeamsVariant = "flow" | "pulse" | "collide";
export type BackgroundBeamsSpeed = keyof typeof speeds;
export type BackgroundBeamsColor = keyof typeof colors;
const clamp = (count: number) =>
Math.max(0, Math.min(Math.trunc(count), MAX_BEAMS));
/** Kurva ke-i di kanvas 800x400, menyapu dari kiri atas ke kanan bawah. Bilangan bulat saja. */
function makeCurves(variant: BackgroundBeamsVariant, count: number) {
const total = clamp(count);
return Array.from({ length: total }, (_, index) => {
const shift = Math.floor((index * 640) / Math.max(1, total));
const bend = (index % 3) * 30;
const delay = `animation-delay:${index * -BEAM_DELAY_MS}ms`;
return {
d: `M ${shift - 200} -20 C ${shift} ${120 + bend}, ${shift + 160} ${260 - bend}, ${shift + 620} 420`,
style:
variant === "pulse"
? `opacity:${((index % 4) + 3) / 10};${delay}`
: `stroke-dashoffset:${-((index * 37) % 90)};${delay}`,
};
});
}
/** Berkas vertikal ke-i: posisi, tinggi awal, laju, dan jeda dari rumus supaya semua framework sama. */
function makeDrops(count: number) {
const total = clamp(count);
return Array.from({ length: total }, (_, index) => {
const left = `left:${(Math.floor(((2 * index + 1) * 500) / Math.max(1, total)) + ((index * 37) % 11) - 5) / 10}%`;
const timing = `animation-duration:calc(var(--markas-beams-duration) * ${RATES[index % RATES.length]});animation-delay:${index * -BEAM_DELAY_MS}ms`;
return {
drop: `${timing};${left};translate:0 -${(index * 23) % 80}%`,
splash: `${timing};${left}`,
};
});
}
/**
* Attribute selector on a native div: the user's class, style, and attributes stay on the
* root. The keyframes are a global style, so encapsulation is off.
*/
@Component({
selector: "div[markas-background-beams]",
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
styles: [keyframes],
host: {
"[class]": "base",
"[style.--markas-beams-duration]": "duration()",
},
template: `
@if (variant() === "collide") {
<div aria-hidden="true" [class]="layerClasses(rainLayer)">
<span [class]="floor"></span>
@for (item of drops(); track $index) {
<span>
<span [class]="drop" [style]="item.drop"></span>
<span [class]="splash" [style]="item.splash"></span>
</span>
}
</div>
} @else {
<svg
aria-hidden="true"
[class]="layerClasses(layer)"
viewBox="0 0 800 400"
preserveAspectRatio="xMidYMid slice"
fill="none"
stroke="currentColor"
stroke-linecap="round"
>
@for (item of curves(); track $index) {
<g>
<path [class]="track" [attr.d]="item.d" stroke-width="1" />
<path
[class]="beamClasses()"
[attr.d]="item.d"
stroke-width="2"
pathLength="100"
[attr.stroke-dasharray]="variant() === 'flow' ? '14 186' : null"
[style]="item.style"
/>
</g>
}
</svg>
}
<div [class]="content"><ng-content /></div>
`,
})
export class BackgroundBeams {
readonly variant = input<BackgroundBeamsVariant>("flow");
readonly count = input(8, { transform: numberAttribute });
readonly speed = input<BackgroundBeamsSpeed>("normal");
readonly color = input<BackgroundBeamsColor>("primary");
protected readonly base = base;
protected readonly layer = layer;
protected readonly rainLayer = rainLayer;
protected readonly track = track;
protected readonly floor = floor;
protected readonly drop = drop;
protected readonly splash = splash;
protected readonly content = content;
protected readonly duration = computed(() => speeds[this.speed()]);
protected readonly beamClasses = computed(() =>
this.variant() === "pulse" ? beams.pulse : beams.flow,
);
protected readonly curves = computed(() => {
const variant = this.variant();
return variant === "collide" ? [] : makeCurves(variant, this.count());
});
protected readonly drops = computed(() =>
this.variant() === "collide" ? makeDrops(this.count()) : [],
);
protected layerClasses(layerClass: string) {
return `${layerClass} ${colors[this.color()]}`;
}
}Pemakaian
<x-markas.background-beams variant="flow" :count="10" class="rounded-xl bg-surface px-6 py-16">
<h2 class="text-center text-3xl font-bold text-ink">Luncurkan dengan gemerlap</h2>
</x-markas.background-beams>Tidak butuh JavaScript atau Alpine.js.
import { BackgroundBeams } from "@/components/markas/BackgroundBeams";
<BackgroundBeams
variant="flow"
count={10}
className="rounded-xl bg-surface px-6 py-16"
>
<h2 className="text-center text-3xl font-bold text-ink">
Luncurkan dengan gemerlap
</h2>
</BackgroundBeams>;<template>
<BackgroundBeams
variant="flow"
:count="10"
class="rounded-xl bg-surface px-6 py-16"
>
<h2 class="text-center text-3xl font-bold text-ink">
Luncurkan dengan gemerlap
</h2>
</BackgroundBeams>
</template><script lang="ts">
import BackgroundBeams from "$lib/components/markas/BackgroundBeams.svelte";
</script>
<BackgroundBeams
variant="flow"
count={10}
class="rounded-xl bg-surface px-6 py-16"
>
<h2 class="text-center text-3xl font-bold text-ink">
Luncurkan dengan gemerlap
</h2>
</BackgroundBeams>---
import BackgroundBeams from "@/components/markas/BackgroundBeams.astro";
---
<BackgroundBeams
variant="flow"
count={10}
class="rounded-xl bg-surface px-6 py-16"
>
<h2 class="text-center text-3xl font-bold text-ink">
Luncurkan dengan gemerlap
</h2>
</BackgroundBeams>Tanpa JavaScript di browser; markup dirender di server.
import { Component } from "@angular/core";
import { BackgroundBeams } from "./markas/background-beams.component";
@Component({
selector: "app-hero",
imports: [BackgroundBeams],
template: `
<div
markas-background-beams
variant="flow"
[count]="10"
class="rounded-xl bg-surface px-6 py-16"
>
<h2 class="text-center text-3xl font-bold text-ink">
Luncurkan dengan gemerlap
</h2>
</div>
`,
})
export class Hero {}Komponen ini berupa atribut pada div, jadi class, style, dan atribut lain tetap di elemen akar.
flowmengalirkan kilau di sepanjang kurva,pulsememudarkan kurva bergantian,collidemenjatuhkan berkas vertikal yang memercik di tepi bawah.- Dengan
collide, beri padding bawah (misalnyapb-16) supaya percikan jatuh di bawah konten. - Posisi berkas berasal dari rumus, jadi semua framework menghasilkan gambar yang sama.
- Komponen ini tidak punya teks bawaan, jadi tidak ada prop label yang perlu diterjemahkan.
Props
| Nama | Tipe | Default | Keterangan |
|---|---|---|---|
variant | flow | pulse | collide | flow | flow mengalirkan kilau di sepanjang kurva, pulse memudarkan kurva bergantian, collide menjatuhkan berkas vertikal yang memercik di dasar. |
count | number | 8 | Jumlah berkas, maksimal 16. |
speed | slow | normal | fast | normal | Panjang satu siklus animasi: 12s, 7s, atau 4s. |
color | muted | primary | success | warning | danger | primary | Warna token berkas. |
children / slot | slot / ReactNode / snippet | - | Konten yang tampil di atas berkas. |
Aksesibilitas
- Lapisan berkas memakai aria-hidden dan mengabaikan pointer.
- Dengan reduced motion, berkas diam di posisi tetap yang mudah dibaca.
- Posisi berasal dari rumus, jadi server dan klien merender markup yang sama.
Komponen terkait
Komponen latar lain dengan class yang sama di setiap framework.
- Aurora BackgroundBidang warna bercahaya yang bergeser pelan di belakang konten, dari token primary dan satu token aksen.
- Background BoxesGrid kotak miring, datar, atau berperspektif yang menyala di bawah kursor lalu memudar, hanya dengan CSS hover.
- Background LinesGaris SVG yang tergambar lalu menghilang bergantian, berupa gelombang, sinar dari satu titik, atau kisi. Dibuat untuk hero.
- Dot PatternGrid titik kecil di belakang konten, dengan pudar radial atau linear opsional. Murni CSS, tanpa JavaScript.
- Gradient BorderMembungkus kartu, tombol, atau kolom dengan border gradien bergerak yang berputar, berkilau, atau berdenyut, dengan pendar lembut opsional.
- Grid PatternGaris grid tipis di belakang konten, dengan sel sorotan yang berdenyut lembut dan pudar opsional.