# Background Beams

Thin curved light beams that flow, pulse, or fall and splash behind your content. Pure SVG and CSS, no JavaScript.

- Category: Backgrounds
- Status: stable
- Registry: https://markas.jenderalcorp.com/r/background-beams.json
- CLI: `npx markasui@latest add background-beams`

## When to use

A hero, launch banner, or feature section that needs a sense of motion without competing with the text.

- Set background color, padding, and radius with class on the component
- Use collide with bottom padding so the splashes do not sit under text
- Keep text on solid colors like bg-surface or bg-canvas for contrast

## Code

### Blade

Save at `resources/views/components/markas/background-beams.blade.php`. No extra dependencies.

```blade
@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>
```

```blade
<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">Light up your launch</h2>
</x-markas.background-beams>
```

No JavaScript or Alpine.js needed.

### React

Save at `src/components/markas/BackgroundBeams.tsx`. No extra dependencies.

```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>
  );
}
```

```tsx
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">
    Light up your launch
  </h2>
</BackgroundBeams>;
```

### Vue

Save at `src/components/markas/BackgroundBeams.vue`. No extra dependencies.

```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>
```

```vue
<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">
      Light up your launch
    </h2>
  </BackgroundBeams>
</template>
```

### Svelte

Save at `src/lib/components/markas/BackgroundBeams.svelte`. No extra dependencies.

```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>
```

```svelte
<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">Light up your launch</h2>
</BackgroundBeams>
```

### Astro

Save at `src/components/markas/BackgroundBeams.astro`. No extra dependencies.

```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>
```

```astro
---
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">
    Light up your launch
  </h2>
</BackgroundBeams>
```

No client-side JavaScript; the markup is rendered on the server.

### Angular

Save at `src/app/markas/background-beams.component.ts`. No extra dependencies.

```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()]}`;
  }
}
```

```ts
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">
        Light up your launch
      </h2>
    </div>
  `,
})
export class Hero {}
```

The component is an attribute on a div, so class, style, and other attributes stay on the root element.

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `flow \| pulse \| collide` | flow | flow sends a glint along each curve, pulse fades whole curves in and out, collide drops vertical beams that splash at the bottom. |
| `count` | `number` | 8 | Number of beams, up to 16. |
| `speed` | `slow \| normal \| fast` | normal | Length of one animation cycle: 12s, 7s, or 4s. |
| `color` | `muted \| primary \| success \| warning \| danger` | primary | Token color of the beams. |
| `children / slot` | `slot / ReactNode / snippet` | - | Content shown on top of the beams. |

## Accessibility

- The beam layer is aria-hidden and ignores pointer events.
- With reduced motion, beams stay still in a fixed, readable position.
- Positions come from a formula, so the server and client render the same markup.

## Notes

- `flow` sends a glint along each curve, `pulse` fades curves in turn, `collide` drops vertical beams that splash at the bottom edge.
- With `collide`, add bottom padding (for example `pb-16`) so the splashes land below your content.
- Beam positions come from a formula, so every framework renders the same picture.
- The component has no built-in text, so there are no label props to translate.
