# Noise Background

Tekstur grain, film, atau kertas statis di atas gradien token yang bergeser pelan. Murni CSS dengan satu tile noise SVG inline.

- Kategori: Latar
- Status: stable
- Registry: https://markas.jenderalcorp.com/r/noise-background.json
- CLI: `npx markasui@latest add noise-background`

## Kapan dipakai

Latar bertekstur untuk hero, section editorial, pendaftaran newsletter, atau promo video.

- Atur warna latar, padding, dan radius lewat class pada komponen
- Pakai variant=film di section gelap dan variant=paper di belakang teks bacaan panjang
- Jaga intensity rendah di belakang teks kecil

## Kode

### Blade

Simpan di `resources/views/components/markas/noise-background.blade.php`. Tanpa dependensi tambahan.

```blade
@props([
    'variant' => 'grain',
    'color' => 'primary',
    'intensity' => 'medium',
    'size' => 'medium',
    'speed' => 'normal',
])

@php
    $base = 'relative isolate overflow-hidden';
    $layer = 'pointer-events-none absolute inset-0 overflow-hidden';
    $wash = 'absolute -inset-1/4 animate-[markas-noise-drift_var(--markas-noise-speed)_ease-in-out_infinite_alternate] bg-[radial-gradient(36%_42%_at_30%_35%,color-mix(in_oklab,currentColor_26%,transparent),transparent),radial-gradient(40%_40%_at_70%_65%,color-mix(in_oklab,currentColor_16%,transparent),transparent)] motion-reduce:animate-none';
    $grain = 'absolute inset-0 bg-ink opacity-[var(--markas-noise-alpha)] [mask-size:var(--markas-noise-size)]';
    $vignette = 'absolute inset-0 bg-[radial-gradient(ellipse_at_center,transparent_40%,currentColor)] text-ink/20 dark:text-canvas/85';
    $content = 'relative';
    $textures = [
        'grain' => 'url("data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'200\' height=\'200\'%3E%3Cfilter id=\'n\'%3E%3CfeTurbulence type=\'fractalNoise\' baseFrequency=\'.85\' numOctaves=\'3\' stitchTiles=\'stitch\'/%3E%3CfeColorMatrix values=\'0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 -4\'/%3E%3C/filter%3E%3Crect width=\'100%25\' height=\'100%25\' filter=\'url(%23n)\'/%3E%3C/svg%3E")',
        'paper' => 'url("data:image/svg+xml,%3Csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'200\' height=\'200\'%3E%3Cfilter id=\'n\'%3E%3CfeTurbulence type=\'fractalNoise\' baseFrequency=\'.5 .12\' numOctaves=\'4\' stitchTiles=\'stitch\'/%3E%3CfeColorMatrix values=\'0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 -1.7\'/%3E%3C/filter%3E%3Crect width=\'100%25\' height=\'100%25\' filter=\'url(%23n)\'/%3E%3C/svg%3E")',
    ];
    $variants = [
        'grain' => $textures['grain'],
        'film' => $textures['grain'],
        'paper' => $textures['paper'],
    ];
    $colors = [
        'primary' => 'text-primary',
        'success' => 'text-success',
        'warning' => 'text-warning',
        'danger' => 'text-danger',
        'muted' => 'text-muted',
    ];
    $intensities = [
        'low' => '[--markas-noise-alpha:0.05]',
        'medium' => '[--markas-noise-alpha:0.09]',
        'high' => '[--markas-noise-alpha:0.15]',
    ];
    $sizes = [
        'fine' => '[--markas-noise-size:120px]',
        'medium' => '[--markas-noise-size:200px]',
        'coarse' => '[--markas-noise-size:320px]',
    ];
    $speeds = [
        'slow' => '[--markas-noise-speed:30s]',
        'normal' => '[--markas-noise-speed:18s]',
        'fast' => '[--markas-noise-speed:10s]',
    ];
    $keyframes = '@keyframes markas-noise-drift{to{transform:translate(-6%,4%) rotate(4deg) scale(1.08)}}';
@endphp

<div {{ $attributes->class([$base]) }}>
    <style>{!! $keyframes !!}</style>
    <div aria-hidden="true" @class([$layer, $colors[$color] ?? $colors['primary'], $intensities[$intensity] ?? $intensities['medium'], $sizes[$size] ?? $sizes['medium'], $speeds[$speed] ?? $speeds['normal']])>
        <div class="{{ $wash }}"></div>
        <div class="{{ $grain }}" style="mask-image: {{ $variants[$variant] ?? $variants['grain'] }}"></div>
        @if ($variant === 'film')
            <div class="{{ $vignette }}"></div>
        @endif
    </div>
    <div class="{{ $content }}">{{ $slot }}</div>
</div>
```

```blade
<x-markas.noise-background color="warning" class="rounded-xl border border-line bg-surface px-6 py-14">
    <h2 class="text-3xl font-semibold text-ink">Alat desain dengan sedikit tekstur</h2>
    <x-markas.button>Unduh kit</x-markas.button>
</x-markas.noise-background>
```

Tidak butuh JavaScript atau Alpine.js.

### React

Simpan di `src/components/markas/NoiseBackground.tsx`. Tanpa dependensi tambahan.

```tsx
import type { ComponentProps } from "react";

const base = "relative isolate overflow-hidden";
const layer = "pointer-events-none absolute inset-0 overflow-hidden";
const wash =
  "absolute -inset-1/4 animate-[markas-noise-drift_var(--markas-noise-speed)_ease-in-out_infinite_alternate] bg-[radial-gradient(36%_42%_at_30%_35%,color-mix(in_oklab,currentColor_26%,transparent),transparent),radial-gradient(40%_40%_at_70%_65%,color-mix(in_oklab,currentColor_16%,transparent),transparent)] motion-reduce:animate-none";
const grain =
  "absolute inset-0 bg-ink opacity-[var(--markas-noise-alpha)] [mask-size:var(--markas-noise-size)]";
const vignette =
  "absolute inset-0 bg-[radial-gradient(ellipse_at_center,transparent_40%,currentColor)] text-ink/20 dark:text-canvas/85";
const content = "relative";
const textures = {
  grain:
    "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 -4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
  paper:
    "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.5 .12' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 -1.7'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
};
const variants = {
  grain: textures.grain,
  film: textures.grain,
  paper: textures.paper,
};
const colors = {
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
  muted: "text-muted",
};
const intensities = {
  low: "[--markas-noise-alpha:0.05]",
  medium: "[--markas-noise-alpha:0.09]",
  high: "[--markas-noise-alpha:0.15]",
};
const sizes = {
  fine: "[--markas-noise-size:120px]",
  medium: "[--markas-noise-size:200px]",
  coarse: "[--markas-noise-size:320px]",
};
const speeds = {
  slow: "[--markas-noise-speed:30s]",
  normal: "[--markas-noise-speed:18s]",
  fast: "[--markas-noise-speed:10s]",
};
const keyframes =
  "@keyframes markas-noise-drift{to{transform:translate(-6%,4%) rotate(4deg) scale(1.08)}}";
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

export type NoiseBackgroundProps = ComponentProps<"div"> & {
  /** grain: fine grain; film: stronger grain with a vignette; paper: soft paper fibers. */
  variant?: keyof typeof variants;
  color?: keyof typeof colors;
  intensity?: keyof typeof intensities;
  /** Size of one grain tile: smaller is finer. */
  size?: keyof typeof sizes;
  speed?: keyof typeof speeds;
};

export function NoiseBackground({
  variant = "grain",
  color = "primary",
  intensity = "medium",
  size = "medium",
  speed = "normal",
  className,
  children,
  ...props
}: NoiseBackgroundProps) {
  return (
    <div {...props} className={cx(base, className)}>
      <style>{keyframes}</style>
      <div
        aria-hidden="true"
        className={cx(
          layer,
          colors[color],
          intensities[intensity],
          sizes[size],
          speeds[speed],
        )}
      >
        <div className={wash} />
        <div
          className={grain}
          style={{ maskImage: variants[variant] ?? variants.grain }}
        />
        {variant === "film" && <div className={vignette} />}
      </div>
      <div className={content}>{children}</div>
    </div>
  );
}
```

```tsx
import { Button } from "@/components/markas/Button";
import { NoiseBackground } from "@/components/markas/NoiseBackground";

<NoiseBackground
  color="warning"
  className="rounded-xl border border-line bg-surface px-6 py-14"
>
  <h2 className="text-3xl font-semibold text-ink">
    Alat desain dengan sedikit tekstur
  </h2>
  <Button>Unduh kit</Button>
</NoiseBackground>;
```

### Vue

Simpan di `src/components/markas/NoiseBackground.vue`. Tanpa dependensi tambahan.

```vue
<script setup lang="ts">
const base = "relative isolate overflow-hidden";
const layer = "pointer-events-none absolute inset-0 overflow-hidden";
const wash =
  "absolute -inset-1/4 animate-[markas-noise-drift_var(--markas-noise-speed)_ease-in-out_infinite_alternate] bg-[radial-gradient(36%_42%_at_30%_35%,color-mix(in_oklab,currentColor_26%,transparent),transparent),radial-gradient(40%_40%_at_70%_65%,color-mix(in_oklab,currentColor_16%,transparent),transparent)] motion-reduce:animate-none";
const grain =
  "absolute inset-0 bg-ink opacity-[var(--markas-noise-alpha)] [mask-size:var(--markas-noise-size)]";
const vignette =
  "absolute inset-0 bg-[radial-gradient(ellipse_at_center,transparent_40%,currentColor)] text-ink/20 dark:text-canvas/85";
const content = "relative";
const textures = {
  grain:
    "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 -4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
  paper:
    "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.5 .12' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 -1.7'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
};
const variants = {
  grain: textures.grain,
  film: textures.grain,
  paper: textures.paper,
};
const colors = {
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
  muted: "text-muted",
};
const intensities = {
  low: "[--markas-noise-alpha:0.05]",
  medium: "[--markas-noise-alpha:0.09]",
  high: "[--markas-noise-alpha:0.15]",
};
const sizes = {
  fine: "[--markas-noise-size:120px]",
  medium: "[--markas-noise-size:200px]",
  coarse: "[--markas-noise-size:320px]",
};
const speeds = {
  slow: "[--markas-noise-speed:30s]",
  normal: "[--markas-noise-speed:18s]",
  fast: "[--markas-noise-speed:10s]",
};
const keyframes =
  "@keyframes markas-noise-drift{to{transform:translate(-6%,4%) rotate(4deg) scale(1.08)}}";

const props = withDefaults(
  defineProps<{
    /** grain: fine grain; film: stronger grain with a vignette; paper: soft paper fibers. */
    variant?: keyof typeof variants;
    color?: keyof typeof colors;
    intensity?: keyof typeof intensities;
    /** Size of one grain tile: smaller is finer. */
    size?: keyof typeof sizes;
    speed?: keyof typeof speeds;
  }>(),
  {
    variant: "grain",
    color: "primary",
    intensity: "medium",
    size: "medium",
    speed: "normal",
  },
);
</script>

<template>
  <div :class="base">
    <component :is="'style'">{{ keyframes }}</component>
    <div
      aria-hidden="true"
      :class="[
        layer,
        colors[props.color],
        intensities[props.intensity],
        sizes[props.size],
        speeds[props.speed],
      ]"
    >
      <div :class="wash" />
      <div
        :class="grain"
        :style="{ maskImage: variants[props.variant] ?? variants.grain }"
      />
      <div v-if="props.variant === 'film'" :class="vignette" />
    </div>
    <div :class="content"><slot /></div>
  </div>
</template>
```

```vue
<template>
  <NoiseBackground
    color="warning"
    class="rounded-xl border border-line bg-surface px-6 py-14"
  >
    <h2 class="text-3xl font-semibold text-ink">
      Alat desain dengan sedikit tekstur
    </h2>
    <Button>Unduh kit</Button>
  </NoiseBackground>
</template>
```

### Svelte

Simpan di `src/lib/components/markas/NoiseBackground.svelte`. Tanpa dependensi tambahan.

```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 overflow-hidden";
  const wash =
    "absolute -inset-1/4 animate-[markas-noise-drift_var(--markas-noise-speed)_ease-in-out_infinite_alternate] bg-[radial-gradient(36%_42%_at_30%_35%,color-mix(in_oklab,currentColor_26%,transparent),transparent),radial-gradient(40%_40%_at_70%_65%,color-mix(in_oklab,currentColor_16%,transparent),transparent)] motion-reduce:animate-none";
  const grain =
    "absolute inset-0 bg-ink opacity-[var(--markas-noise-alpha)] [mask-size:var(--markas-noise-size)]";
  const vignette =
    "absolute inset-0 bg-[radial-gradient(ellipse_at_center,transparent_40%,currentColor)] text-ink/20 dark:text-canvas/85";
  const content = "relative";
  const textures = {
    grain:
      "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 -4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
    paper:
      "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.5 .12' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 -1.7'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
  };
  const variants = {
    grain: textures.grain,
    film: textures.grain,
    paper: textures.paper,
  };
  const colors = {
    primary: "text-primary",
    success: "text-success",
    warning: "text-warning",
    danger: "text-danger",
    muted: "text-muted",
  };
  const intensities = {
    low: "[--markas-noise-alpha:0.05]",
    medium: "[--markas-noise-alpha:0.09]",
    high: "[--markas-noise-alpha:0.15]",
  };
  const sizes = {
    fine: "[--markas-noise-size:120px]",
    medium: "[--markas-noise-size:200px]",
    coarse: "[--markas-noise-size:320px]",
  };
  const speeds = {
    slow: "[--markas-noise-speed:30s]",
    normal: "[--markas-noise-speed:18s]",
    fast: "[--markas-noise-speed:10s]",
  };
  const keyframes =
    "@keyframes markas-noise-drift{to{transform:translate(-6%,4%) rotate(4deg) scale(1.08)}}";

  type Props = HTMLAttributes<HTMLDivElement> & {
    /** grain: fine grain; film: stronger grain with a vignette; paper: soft paper fibers. */
    variant?: keyof typeof variants;
    color?: keyof typeof colors;
    intensity?: keyof typeof intensities;
    /** Size of one grain tile: smaller is finer. */
    size?: keyof typeof sizes;
    speed?: keyof typeof speeds;
    children?: Snippet;
  };

  let {
    variant = "grain",
    color = "primary",
    intensity = "medium",
    size = "medium",
    speed = "normal",
    class: className,
    children,
    ...rest
  }: Props = $props();
</script>

<div {...rest} class={[base, className]}>
  {@html `<style>${keyframes}</style>`}
  <div
    aria-hidden="true"
    class={[
      layer,
      colors[color],
      intensities[intensity],
      sizes[size],
      speeds[speed],
    ]}
  >
    <div class={wash}></div>
    <div
      class={grain}
      style:mask-image={variants[variant] ?? variants.grain}
    ></div>
    {#if variant === "film"}<div class={vignette}></div>{/if}
  </div>
  <div class={content}>{@render children?.()}</div>
</div>
```

```svelte
<script lang="ts">
  import Button from "$lib/components/markas/Button.svelte";
  import NoiseBackground from "$lib/components/markas/NoiseBackground.svelte";
</script>

<NoiseBackground
  color="warning"
  class="rounded-xl border border-line bg-surface px-6 py-14"
>
  <h2 class="text-3xl font-semibold text-ink">
    Design tools with a little texture
  </h2>
  <Button>Download the kit</Button>
</NoiseBackground>
```

### Astro

Simpan di `src/components/markas/NoiseBackground.astro`. Tanpa dependensi tambahan.

```astro
---
import type { HTMLAttributes } from "astro/types";

const base = "relative isolate overflow-hidden";
const layer = "pointer-events-none absolute inset-0 overflow-hidden";
const wash =
  "absolute -inset-1/4 animate-[markas-noise-drift_var(--markas-noise-speed)_ease-in-out_infinite_alternate] bg-[radial-gradient(36%_42%_at_30%_35%,color-mix(in_oklab,currentColor_26%,transparent),transparent),radial-gradient(40%_40%_at_70%_65%,color-mix(in_oklab,currentColor_16%,transparent),transparent)] motion-reduce:animate-none";
const grain =
  "absolute inset-0 bg-ink opacity-[var(--markas-noise-alpha)] [mask-size:var(--markas-noise-size)]";
const vignette =
  "absolute inset-0 bg-[radial-gradient(ellipse_at_center,transparent_40%,currentColor)] text-ink/20 dark:text-canvas/85";
const content = "relative";
const textures = {
  grain:
    "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 -4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
  paper:
    "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.5 .12' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 -1.7'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
};
const variants = {
  grain: textures.grain,
  film: textures.grain,
  paper: textures.paper,
};
const colors = {
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
  muted: "text-muted",
};
const intensities = {
  low: "[--markas-noise-alpha:0.05]",
  medium: "[--markas-noise-alpha:0.09]",
  high: "[--markas-noise-alpha:0.15]",
};
const sizes = {
  fine: "[--markas-noise-size:120px]",
  medium: "[--markas-noise-size:200px]",
  coarse: "[--markas-noise-size:320px]",
};
const speeds = {
  slow: "[--markas-noise-speed:30s]",
  normal: "[--markas-noise-speed:18s]",
  fast: "[--markas-noise-speed:10s]",
};
const keyframes =
  "@keyframes markas-noise-drift{to{transform:translate(-6%,4%) rotate(4deg) scale(1.08)}}";

type Props = HTMLAttributes<"div"> & {
  /** grain: fine grain; film: stronger grain with a vignette; paper: soft paper fibers. */
  variant?: keyof typeof variants;
  color?: keyof typeof colors;
  intensity?: keyof typeof intensities;
  /** Size of one grain tile: smaller is finer. */
  size?: keyof typeof sizes;
  speed?: keyof typeof speeds;
};

const {
  variant = "grain",
  color = "primary",
  intensity = "medium",
  size = "medium",
  speed = "normal",
  class: className,
  ...rest
} = Astro.props;
---

<div {...rest} class:list={[base, className]}>
  <style is:inline set:html={keyframes} />
  <div
    aria-hidden="true"
    class:list={[
      layer,
      colors[color],
      intensities[intensity],
      sizes[size],
      speeds[speed],
    ]}
  >
    <div class={wash}></div>
    <div
      class={grain}
      style={{ maskImage: variants[variant] ?? variants.grain }}
    >
    </div>
    {variant === "film" && <div class={vignette} />}
  </div>
  <div class={content}><slot /></div>
</div>
```

```astro
---
import Button from "@/components/markas/Button.astro";
import NoiseBackground from "@/components/markas/NoiseBackground.astro";
---

<NoiseBackground
  color="warning"
  class="rounded-xl border border-line bg-surface px-6 py-14"
>
  <h2 class="text-3xl font-semibold text-ink">
    Design tools with a little texture
  </h2>
  <Button>Download the kit</Button>
</NoiseBackground>
```

### Angular

Simpan di `src/app/markas/noise-background.component.ts`. Tanpa dependensi tambahan.

```ts
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  input,
  ViewEncapsulation,
} from "@angular/core";

const base = "relative isolate overflow-hidden";
const layer = "pointer-events-none absolute inset-0 overflow-hidden";
const wash =
  "absolute -inset-1/4 animate-[markas-noise-drift_var(--markas-noise-speed)_ease-in-out_infinite_alternate] bg-[radial-gradient(36%_42%_at_30%_35%,color-mix(in_oklab,currentColor_26%,transparent),transparent),radial-gradient(40%_40%_at_70%_65%,color-mix(in_oklab,currentColor_16%,transparent),transparent)] motion-reduce:animate-none";
const grain =
  "absolute inset-0 bg-ink opacity-[var(--markas-noise-alpha)] [mask-size:var(--markas-noise-size)]";
const vignette =
  "absolute inset-0 bg-[radial-gradient(ellipse_at_center,transparent_40%,currentColor)] text-ink/20 dark:text-canvas/85";
const content = "relative";
const textures = {
  grain:
    "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 -4'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
  paper:
    "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.5 .12' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 -1.7'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\")",
};
const variants = {
  grain: textures.grain,
  film: textures.grain,
  paper: textures.paper,
};
const colors = {
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
  muted: "text-muted",
};
const intensities = {
  low: "[--markas-noise-alpha:0.05]",
  medium: "[--markas-noise-alpha:0.09]",
  high: "[--markas-noise-alpha:0.15]",
};
const sizes = {
  fine: "[--markas-noise-size:120px]",
  medium: "[--markas-noise-size:200px]",
  coarse: "[--markas-noise-size:320px]",
};
const speeds = {
  slow: "[--markas-noise-speed:30s]",
  normal: "[--markas-noise-speed:18s]",
  fast: "[--markas-noise-speed:10s]",
};
const keyframes =
  "@keyframes markas-noise-drift{to{transform:translate(-6%,4%) rotate(4deg) scale(1.08)}}";

/** grain: fine grain; film: stronger grain with a vignette; paper: soft paper fibers. */
export type NoiseBackgroundVariant = keyof typeof variants;
export type NoiseBackgroundColor = keyof typeof colors;
export type NoiseBackgroundIntensity = keyof typeof intensities;
export type NoiseBackgroundSize = keyof typeof sizes;
export type NoiseBackgroundSpeed = keyof typeof speeds;

/**
 * Attribute selector on the native root div: the user's class and attributes stay on it.
 * The keyframes are a global style, so encapsulation is off.
 */
@Component({
  selector: "div[markas-noise-background]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None,
  styles: [keyframes],
  host: { "[class]": "base" },
  template: `
    <div aria-hidden="true" [class]="layerClasses()">
      <div [class]="wash"></div>
      <div [class]="grain" [style.mask-image]="texture()"></div>
      @if (variant() === "film") {
        <div [class]="vignette"></div>
      }
    </div>
    <div [class]="content"><ng-content /></div>
  `,
})
export class NoiseBackground {
  readonly variant = input<NoiseBackgroundVariant>("grain");
  readonly color = input<NoiseBackgroundColor>("primary");
  readonly intensity = input<NoiseBackgroundIntensity>("medium");
  /** Size of one grain tile: smaller is finer. */
  readonly size = input<NoiseBackgroundSize>("medium");
  readonly speed = input<NoiseBackgroundSpeed>("normal");

  protected readonly base = base;
  protected readonly wash = wash;
  protected readonly grain = grain;
  protected readonly vignette = vignette;
  protected readonly content = content;
  protected readonly texture = computed(
    () => variants[this.variant()] ?? variants.grain,
  );
  protected readonly layerClasses = computed(() =>
    [
      layer,
      colors[this.color()],
      intensities[this.intensity()],
      sizes[this.size()],
      speeds[this.speed()],
    ].join(" "),
  );
}
```

```ts
import { Component } from "@angular/core";
import { Button } from "./markas/button.component";
import { NoiseBackground } from "./markas/noise-background.component";

@Component({
  selector: "app-kit",
  imports: [Button, NoiseBackground],
  template: `
    <div
      markas-noise-background
      color="warning"
      class="rounded-xl border border-line bg-surface px-6 py-14"
    >
      <h2 class="text-3xl font-semibold text-ink">
        Design tools with a little texture
      </h2>
      <button markas-button>Download the kit</button>
    </div>
  `,
})
export class Kit {}
```

Angular memakai attribute selector pada div native, jadi `class`, `aria-*`, dan atribut lain tetap di elemen akar.

## Props

| Nama | Tipe | Default | Keterangan |
| --- | --- | --- | --- |
| `variant` | `grain \| film \| paper` | grain | grain: butiran halus. film: butiran dengan vignette gelap di tepi. paper: serat kertas bergaris yang lembut. |
| `color` | `primary \| success \| warning \| danger \| muted` | primary | Token untuk gradien di bawah tekstur. |
| `intensity` | `low \| medium \| high` | medium | Seberapa terlihat teksturnya. |
| `size` | `fine \| medium \| coarse` | medium | Ukuran satu tile noise: 120px, 200px, atau 320px. Tile lebih besar memberi butiran lebih kasar. |
| `speed` | `slow \| normal \| fast` | normal | Kecepatan gradien bergeser: 30s, 18s, atau 10s per siklus. Teksturnya sendiri tidak bergerak. |
| `children / slot` | `slot / ReactNode` | - | Konten yang tampil di atas tekstur. |

## Aksesibilitas

- Lapisan tekstur memakai aria-hidden dan mengabaikan pointer.
- Butiran memakai token ink dengan opacity rendah, jadi teks ink dan muted tetap kontras.
- Dengan reduced motion, gradien berhenti bergeser.

## Catatan

- Tekstur berupa satu tile SVG `feTurbulence` yang disisipkan sebagai data URL dan dipakai sebagai mask CSS di atas token `ink`, jadi ikut mode terang dan gelap. Browser merendernya sekali lalu mengulangnya.
- Hanya gradien di bawah tekstur yang bergerak, lewat transform pelan. Butirannya statis, jadi tidak ada kerja per frame.
- `variant="film"` menambah vignette yang menggelapkan tepi di kedua tema.
- Komponen ini tidak punya teks bawaan, jadi tidak ada prop label yang perlu diterjemahkan.
