Screensaver
Area where one or more elements bounce off the walls like an old DVD screensaver, switching color tokens or squashing on each hit.
Page not found
The link may be old, or the page moved somewhere else.
Page not found
The link may be old, or the page moved somewhere else.
Page not found
The link may be old, or the page moved somewhere else.
Page not found
The link may be old, or the page moved somewhere else.
Page not found
The link may be old, or the page moved somewhere else.
@php
$card = 'rounded-xl border border-line bg-surface p-5 text-center';
$area = 'h-44 rounded-lg bg-subtle';
$logo = 'flex items-center gap-2 text-3xl font-bold tabular-nums';
$icon = 'size-8';
$title = 'mt-5 text-base font-semibold text-ink';
$text = 'mt-1 text-sm text-muted';
$action = 'mt-4';
@endphp
<div class="{{ $card }}">
<x-markas.screensaver :class="$area" aria-hidden="true">
<span class="{{ $logo }}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="{{ $icon }}"><path d="M4 6h16v12H4z"></path><path d="m4 6 8 6 8-6"></path></svg>404</span>
</x-markas.screensaver>
<p class="{{ $title }}">Page not found</p>
<p class="{{ $text }}">The link may be old, or the page moved somewhere else.</p>
<x-markas.button :class="$action">Back to home</x-markas.button>
</div>import { Screensaver } from "@/components/markas/Screensaver";
import { Button } from "@/components/markas/Button";
const card = "rounded-xl border border-line bg-surface p-5 text-center";
const area = "h-44 rounded-lg bg-subtle";
const logo = "flex items-center gap-2 text-3xl font-bold tabular-nums";
const icon = "size-8";
const title = "mt-5 text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
const action = "mt-4";
export default function ScreensaverExample() {
return (
<div className={card}>
<Screensaver className={area} aria-hidden="true">
<span className={logo}>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
className={icon}
>
<path d="M4 6h16v12H4z"></path>
<path d="m4 6 8 6 8-6"></path>
</svg>
404
</span>
</Screensaver>
<p className={title}>Page not found</p>
<p className={text}>
The link may be old, or the page moved somewhere else.
</p>
<Button className={action}>Back to home</Button>
</div>
);
}<script setup lang="ts">
import Screensaver from "@/components/markas/Screensaver.vue";
import Button from "@/components/markas/Button.vue";
const card = "rounded-xl border border-line bg-surface p-5 text-center";
const area = "h-44 rounded-lg bg-subtle";
const logo = "flex items-center gap-2 text-3xl font-bold tabular-nums";
const icon = "size-8";
const title = "mt-5 text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
const action = "mt-4";
</script>
<template>
<div :class="card">
<Screensaver :class="area" aria-hidden="true">
<span :class="logo"
><svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
:class="icon"
>
<path d="M4 6h16v12H4z"></path>
<path d="m4 6 8 6 8-6"></path></svg
>404</span
>
</Screensaver>
<p :class="title">Page not found</p>
<p :class="text">The link may be old, or the page moved somewhere else.</p>
<Button :class="action">Back to home</Button>
</div>
</template><script lang="ts">
import Screensaver from "$lib/components/markas/Screensaver.svelte";
import Button from "$lib/components/markas/Button.svelte";
const card = "rounded-xl border border-line bg-surface p-5 text-center";
const area = "h-44 rounded-lg bg-subtle";
const logo = "flex items-center gap-2 text-3xl font-bold tabular-nums";
const icon = "size-8";
const title = "mt-5 text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
const action = "mt-4";
</script>
<div class={card}>
<Screensaver class={area} aria-hidden="true">
<span class={logo}
><svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
class={icon}
>
<path d="M4 6h16v12H4z"></path>
<path d="m4 6 8 6 8-6"></path></svg
>404</span
>
</Screensaver>
<p class={title}>Page not found</p>
<p class={text}>The link may be old, or the page moved somewhere else.</p>
<Button class={action}>Back to home</Button>
</div>---
import Screensaver from "@/components/markas/Screensaver.astro";
import Button from "@/components/markas/Button.astro";
const card = "rounded-xl border border-line bg-surface p-5 text-center";
const area = "h-44 rounded-lg bg-subtle";
const logo = "flex items-center gap-2 text-3xl font-bold tabular-nums";
const icon = "size-8";
const title = "mt-5 text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
const action = "mt-4";
---
<div class={card}>
<Screensaver class={area} aria-hidden="true">
<span class={logo}><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class={icon}>
<path d="M4 6h16v12H4z"></path>
<path d="m4 6 8 6 8-6"></path></svg>404</span>
</Screensaver>
<p class={title}>Page not found</p>
<p class={text}>The link may be old, or the page moved somewhere else.</p>
<Button class={action}>Back to home</Button>
</div>import { Component } from "@angular/core";
import { Screensaver } from "./markas/screensaver.component";
import { Button } from "./markas/button.component";
@Component({
selector: "markas-example",
imports: [Screensaver, Button],
template: `
<div [class]="card">
<markas-screensaver [class]="area" aria-hidden="true">
<span [class]="logo"
><svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
[class]="icon"
>
<path d="M4 6h16v12H4z"></path>
<path d="m4 6 8 6 8-6"></path></svg
>404</span
>
</markas-screensaver>
<p [class]="title">Page not found</p>
<p [class]="text">
The link may be old, or the page moved somewhere else.
</p>
<button markas-button [class]="action">Back to home</button>
</div>
`,
})
export default class ScreensaverExample {
protected readonly card =
"rounded-xl border border-line bg-surface p-5 text-center";
protected readonly area = "h-44 rounded-lg bg-subtle";
protected readonly logo =
"flex items-center gap-2 text-3xl font-bold tabular-nums";
protected readonly icon = "size-8";
protected readonly title = "mt-5 text-base font-semibold text-ink";
protected readonly text = "mt-1 text-sm text-muted";
protected readonly action = "mt-4";
}Examples
Empty state with a squashing box
No orders yet
When customers check out, their orders show up here.
No orders yet
When customers check out, their orders show up here.
No orders yet
When customers check out, their orders show up here.
No orders yet
When customers check out, their orders show up here.
No orders yet
When customers check out, their orders show up here.
@php
$card = 'flex items-center gap-5 rounded-xl border border-dashed border-line bg-surface p-5';
$area = 'h-32 w-36 shrink-0 rounded-lg bg-subtle';
$box = 'grid size-12 place-items-center rounded-xl bg-surface text-ink shadow-overlay';
$icon = 'size-6';
$title = 'text-base font-semibold text-ink';
$text = 'mt-1 text-sm text-muted';
@endphp
<div class="{{ $card }}">
<x-markas.screensaver effect="squash" :speed="50" :seed="2" :class="$area" aria-hidden="true">
<span class="{{ $box }}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="{{ $icon }}"><path d="m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"></path><path d="m4 7.5 8 4.5 8-4.5"></path><path d="M12 12v9"></path></svg></span>
</x-markas.screensaver>
<div>
<p class="{{ $title }}">No orders yet</p>
<p class="{{ $text }}">When customers check out, their orders show up here.</p>
</div>
</div>import { Screensaver } from "@/components/markas/Screensaver";
const card =
"flex items-center gap-5 rounded-xl border border-dashed border-line bg-surface p-5";
const area = "h-32 w-36 shrink-0 rounded-lg bg-subtle";
const box =
"grid size-12 place-items-center rounded-xl bg-surface text-ink shadow-overlay";
const icon = "size-6";
const title = "text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
export default function Example() {
return (
<div className={card}>
<Screensaver
effect="squash"
speed={50}
seed={2}
className={area}
aria-hidden="true"
>
<span className={box}>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
className={icon}
>
<path d="m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"></path>
<path d="m4 7.5 8 4.5 8-4.5"></path>
<path d="M12 12v9"></path>
</svg>
</span>
</Screensaver>
<div>
<p className={title}>No orders yet</p>
<p className={text}>
When customers check out, their orders show up here.
</p>
</div>
</div>
);
}<script setup lang="ts">
import Screensaver from "@/components/markas/Screensaver.vue";
const card =
"flex items-center gap-5 rounded-xl border border-dashed border-line bg-surface p-5";
const area = "h-32 w-36 shrink-0 rounded-lg bg-subtle";
const box =
"grid size-12 place-items-center rounded-xl bg-surface text-ink shadow-overlay";
const icon = "size-6";
const title = "text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
</script>
<template>
<div :class="card">
<Screensaver
effect="squash"
:speed="50"
:seed="2"
:class="area"
aria-hidden="true"
>
<span :class="box"
><svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
:class="icon"
>
<path d="m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"></path>
<path d="m4 7.5 8 4.5 8-4.5"></path>
<path d="M12 12v9"></path></svg
></span>
</Screensaver>
<div>
<p :class="title">No orders yet</p>
<p :class="text">When customers check out, their orders show up here.</p>
</div>
</div>
</template><script lang="ts">
import Screensaver from "$lib/components/markas/Screensaver.svelte";
const card =
"flex items-center gap-5 rounded-xl border border-dashed border-line bg-surface p-5";
const area = "h-32 w-36 shrink-0 rounded-lg bg-subtle";
const box =
"grid size-12 place-items-center rounded-xl bg-surface text-ink shadow-overlay";
const icon = "size-6";
const title = "text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
</script>
<div class={card}>
<Screensaver
effect="squash"
speed={50}
seed={2}
class={area}
aria-hidden="true"
>
<span class={box}
><svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
class={icon}
>
<path d="m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"></path>
<path d="m4 7.5 8 4.5 8-4.5"></path>
<path d="M12 12v9"></path></svg
></span
>
</Screensaver>
<div>
<p class={title}>No orders yet</p>
<p class={text}>When customers check out, their orders show up here.</p>
</div>
</div>---
import Screensaver from "@/components/markas/Screensaver.astro";
const card =
"flex items-center gap-5 rounded-xl border border-dashed border-line bg-surface p-5";
const area = "h-32 w-36 shrink-0 rounded-lg bg-subtle";
const box =
"grid size-12 place-items-center rounded-xl bg-surface text-ink shadow-overlay";
const icon = "size-6";
const title = "text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
---
<div class={card}>
<Screensaver effect="squash" speed={50} seed={2} class={area} aria-hidden="true">
<span class={box}><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class={icon}>
<path d="m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"></path>
<path d="m4 7.5 8 4.5 8-4.5"></path>
<path d="M12 12v9"></path></svg></span>
</Screensaver>
<div>
<p class={title}>No orders yet</p>
<p class={text}>When customers check out, their orders show up here.</p>
</div>
</div>import { Component } from "@angular/core";
import { Screensaver } from "./markas/screensaver.component";
@Component({
selector: "markas-example",
imports: [Screensaver],
template: `
<div [class]="card">
<markas-screensaver
effect="squash"
[speed]="50"
[seed]="2"
[class]="area"
aria-hidden="true"
>
<span [class]="box"
><svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
[class]="icon"
>
<path d="m12 3 8 4.5v9L12 21l-8-4.5v-9L12 3Z"></path>
<path d="m4 7.5 8 4.5 8-4.5"></path>
<path d="M12 12v9"></path></svg
></span>
</markas-screensaver>
<div>
<p [class]="title">No orders yet</p>
<p [class]="text">
When customers check out, their orders show up here.
</p>
</div>
</div>
`,
})
export default class ScreensaverEmptyExample {
protected readonly card =
"flex items-center gap-5 rounded-xl border border-dashed border-line bg-surface p-5";
protected readonly area = "h-32 w-36 shrink-0 rounded-lg bg-subtle";
protected readonly box =
"grid size-12 place-items-center rounded-xl bg-surface text-ink shadow-overlay";
protected readonly icon = "size-6";
protected readonly title = "text-base font-semibold text-ink";
protected readonly text = "mt-1 text-sm text-muted";
}Several people bouncing at once
Online now
4 people
Online now
4 people
Online now
4 people
Online now
4 people
Online now
4 people
@php
$card = 'rounded-xl border border-line bg-surface p-4';
$head = 'flex items-center justify-between text-sm';
$title = 'font-semibold text-ink';
$count = 'text-muted tabular-nums';
$area = 'mt-3 h-52 rounded-lg bg-canvas';
$chip = 'flex items-center gap-2 rounded-full border border-line bg-surface py-1 pr-3 pl-1.5 text-sm font-medium';
$dot = 'size-2.5 rounded-full bg-current';
$name = 'text-ink';
@endphp
<div class="{{ $card }}">
<div class="{{ $head }}">
<p class="{{ $title }}">Online now</p>
<p class="{{ $count }}">4 people</p>
</div>
<x-markas.screensaver :speed="60" :seed="3" :class="$area">
<span class="{{ $chip }}"><span class="{{ $dot }}"></span><span class="{{ $name }}">Rania Putri</span></span>
<span class="{{ $chip }}"><span class="{{ $dot }}"></span><span class="{{ $name }}">Bima Saputra</span></span>
<span class="{{ $chip }}"><span class="{{ $dot }}"></span><span class="{{ $name }}">Sekar Ayu</span></span>
<span class="{{ $chip }}"><span class="{{ $dot }}"></span><span class="{{ $name }}">Dimas Pratama</span></span>
</x-markas.screensaver>
</div>import { Screensaver } from "@/components/markas/Screensaver";
const card = "rounded-xl border border-line bg-surface p-4";
const head = "flex items-center justify-between text-sm";
const title = "font-semibold text-ink";
const count = "text-muted tabular-nums";
const area = "mt-3 h-52 rounded-lg bg-canvas";
const chip =
"flex items-center gap-2 rounded-full border border-line bg-surface py-1 pr-3 pl-1.5 text-sm font-medium";
const dot = "size-2.5 rounded-full bg-current";
const name = "text-ink";
export default function Example() {
return (
<div className={card}>
<div className={head}>
<p className={title}>Online now</p>
<p className={count}>4 people</p>
</div>
<Screensaver speed={60} seed={3} className={area}>
<span className={chip}>
<span className={dot}></span>
<span className={name}>Rania Putri</span>
</span>
<span className={chip}>
<span className={dot}></span>
<span className={name}>Bima Saputra</span>
</span>
<span className={chip}>
<span className={dot}></span>
<span className={name}>Sekar Ayu</span>
</span>
<span className={chip}>
<span className={dot}></span>
<span className={name}>Dimas Pratama</span>
</span>
</Screensaver>
</div>
);
}<script setup lang="ts">
import Screensaver from "@/components/markas/Screensaver.vue";
const card = "rounded-xl border border-line bg-surface p-4";
const head = "flex items-center justify-between text-sm";
const title = "font-semibold text-ink";
const count = "text-muted tabular-nums";
const area = "mt-3 h-52 rounded-lg bg-canvas";
const chip =
"flex items-center gap-2 rounded-full border border-line bg-surface py-1 pr-3 pl-1.5 text-sm font-medium";
const dot = "size-2.5 rounded-full bg-current";
const name = "text-ink";
</script>
<template>
<div :class="card">
<div :class="head">
<p :class="title">Online now</p>
<p :class="count">4 people</p>
</div>
<Screensaver :speed="60" :seed="3" :class="area">
<span :class="chip"
><span :class="dot"></span><span :class="name">Rania Putri</span></span
>
<span :class="chip"
><span :class="dot"></span><span :class="name">Bima Saputra</span></span
>
<span :class="chip"
><span :class="dot"></span><span :class="name">Sekar Ayu</span></span
>
<span :class="chip"
><span :class="dot"></span
><span :class="name">Dimas Pratama</span></span
>
</Screensaver>
</div>
</template><script lang="ts">
import Screensaver from "$lib/components/markas/Screensaver.svelte";
const card = "rounded-xl border border-line bg-surface p-4";
const head = "flex items-center justify-between text-sm";
const title = "font-semibold text-ink";
const count = "text-muted tabular-nums";
const area = "mt-3 h-52 rounded-lg bg-canvas";
const chip =
"flex items-center gap-2 rounded-full border border-line bg-surface py-1 pr-3 pl-1.5 text-sm font-medium";
const dot = "size-2.5 rounded-full bg-current";
const name = "text-ink";
</script>
<div class={card}>
<div class={head}>
<p class={title}>Online now</p>
<p class={count}>4 people</p>
</div>
<Screensaver speed={60} seed={3} class={area}>
<span class={chip}
><span class={dot}></span><span class={name}>Rania Putri</span></span
>
<span class={chip}
><span class={dot}></span><span class={name}>Bima Saputra</span></span
>
<span class={chip}
><span class={dot}></span><span class={name}>Sekar Ayu</span></span
>
<span class={chip}
><span class={dot}></span><span class={name}>Dimas Pratama</span></span
>
</Screensaver>
</div>---
import Screensaver from "@/components/markas/Screensaver.astro";
const card = "rounded-xl border border-line bg-surface p-4";
const head = "flex items-center justify-between text-sm";
const title = "font-semibold text-ink";
const count = "text-muted tabular-nums";
const area = "mt-3 h-52 rounded-lg bg-canvas";
const chip =
"flex items-center gap-2 rounded-full border border-line bg-surface py-1 pr-3 pl-1.5 text-sm font-medium";
const dot = "size-2.5 rounded-full bg-current";
const name = "text-ink";
---
<div class={card}>
<div class={head}>
<p class={title}>Online now</p>
<p class={count}>4 people</p>
</div>
<Screensaver speed={60} seed={3} class={area}>
<span class={chip}><span class={dot}></span><span class={name}>Rania Putri</span></span>
<span class={chip}><span class={dot}></span><span class={name}>Bima Saputra</span></span>
<span class={chip}><span class={dot}></span><span class={name}>Sekar Ayu</span></span>
<span class={chip}><span class={dot}></span><span class={name}>Dimas Pratama</span></span>
</Screensaver>
</div>import { Component } from "@angular/core";
import { Screensaver } from "./markas/screensaver.component";
@Component({
selector: "markas-example",
imports: [Screensaver],
template: `
<div [class]="card">
<div [class]="head">
<p [class]="title">Online now</p>
<p [class]="count">4 people</p>
</div>
<markas-screensaver [speed]="60" [seed]="3" [class]="area">
<span [class]="chip"
><span [class]="dot"></span
><span [class]="name">Rania Putri</span></span
>
<span [class]="chip"
><span [class]="dot"></span
><span [class]="name">Bima Saputra</span></span
>
<span [class]="chip"
><span [class]="dot"></span
><span [class]="name">Sekar Ayu</span></span
>
<span [class]="chip"
><span [class]="dot"></span
><span [class]="name">Dimas Pratama</span></span
>
</markas-screensaver>
</div>
`,
})
export default class ScreensaverManyExample {
protected readonly card = "rounded-xl border border-line bg-surface p-4";
protected readonly head = "flex items-center justify-between text-sm";
protected readonly title = "font-semibold text-ink";
protected readonly count = "text-muted tabular-nums";
protected readonly area = "mt-3 h-52 rounded-lg bg-canvas";
protected readonly chip =
"flex items-center gap-2 rounded-full border border-line bg-surface py-1 pr-3 pl-1.5 text-sm font-medium";
protected readonly dot = "size-2.5 rounded-full bg-current";
protected readonly name = "text-ink";
}Slim launch banner
@php
$banner = 'h-16 rounded-xl bg-primary text-on-primary';
$label = 'flex items-center gap-2 px-1 py-1 text-sm font-semibold whitespace-nowrap';
$icon = 'size-5';
@endphp
<x-markas.screensaver effect="none" :speed="45" :pause-on-hover="false" :class="$banner">
<span class="{{ $label }}"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class="{{ $icon }}"><path d="M12 15c-1.5 0-3-1.5-3-3 0-4 3-8 3-8s3 4 3 8c0 1.5-1.5 3-3 3Z"></path><path d="M9 13l-3 2 1 3 3-1"></path><path d="M15 13l3 2-1 3-3-1"></path></svg>Launching 17 August</span>
</x-markas.screensaver>import { Screensaver } from "@/components/markas/Screensaver";
const banner = "h-16 rounded-xl bg-primary text-on-primary";
const label =
"flex items-center gap-2 px-1 py-1 text-sm font-semibold whitespace-nowrap";
const icon = "size-5";
export default function Example() {
return (
<Screensaver
effect="none"
speed={45}
pauseOnHover={false}
className={banner}
>
<span className={label}>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
className={icon}
>
<path d="M12 15c-1.5 0-3-1.5-3-3 0-4 3-8 3-8s3 4 3 8c0 1.5-1.5 3-3 3Z"></path>
<path d="M9 13l-3 2 1 3 3-1"></path>
<path d="M15 13l3 2-1 3-3-1"></path>
</svg>
Launching 17 August
</span>
</Screensaver>
);
}<script setup lang="ts">
import Screensaver from "@/components/markas/Screensaver.vue";
const banner = "h-16 rounded-xl bg-primary text-on-primary";
const label =
"flex items-center gap-2 px-1 py-1 text-sm font-semibold whitespace-nowrap";
const icon = "size-5";
</script>
<template>
<Screensaver
effect="none"
:speed="45"
:pause-on-hover="false"
:class="banner"
>
<span :class="label"
><svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
:class="icon"
>
<path
d="M12 15c-1.5 0-3-1.5-3-3 0-4 3-8 3-8s3 4 3 8c0 1.5-1.5 3-3 3Z"
></path>
<path d="M9 13l-3 2 1 3 3-1"></path>
<path d="M15 13l3 2-1 3-3-1"></path></svg
>Launching 17 August</span
>
</Screensaver>
</template><script lang="ts">
import Screensaver from "$lib/components/markas/Screensaver.svelte";
const banner = "h-16 rounded-xl bg-primary text-on-primary";
const label =
"flex items-center gap-2 px-1 py-1 text-sm font-semibold whitespace-nowrap";
const icon = "size-5";
</script>
<Screensaver effect="none" speed={45} pauseOnHover={false} class={banner}>
<span class={label}
><svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
class={icon}
>
<path d="M12 15c-1.5 0-3-1.5-3-3 0-4 3-8 3-8s3 4 3 8c0 1.5-1.5 3-3 3Z"
></path>
<path d="M9 13l-3 2 1 3 3-1"></path>
<path d="M15 13l3 2-1 3-3-1"></path></svg
>Launching 17 August</span
>
</Screensaver>---
import Screensaver from "@/components/markas/Screensaver.astro";
const banner = "h-16 rounded-xl bg-primary text-on-primary";
const label =
"flex items-center gap-2 px-1 py-1 text-sm font-semibold whitespace-nowrap";
const icon = "size-5";
---
<Screensaver effect="none" speed={45} pauseOnHover={false} class={banner}>
<span class={label}><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" class={icon}>
<path d="M12 15c-1.5 0-3-1.5-3-3 0-4 3-8 3-8s3 4 3 8c0 1.5-1.5 3-3 3Z"></path>
<path d="M9 13l-3 2 1 3 3-1"></path>
<path d="M15 13l3 2-1 3-3-1"></path></svg>Launching 17 August</span>
</Screensaver>import { Component } from "@angular/core";
import { Screensaver } from "./markas/screensaver.component";
@Component({
selector: "markas-example",
imports: [Screensaver],
template: `
<markas-screensaver
effect="none"
[speed]="45"
[pauseOnHover]="false"
[class]="banner"
>
<span [class]="label"
><svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
[class]="icon"
>
<path
d="M12 15c-1.5 0-3-1.5-3-3 0-4 3-8 3-8s3 4 3 8c0 1.5-1.5 3-3 3Z"
></path>
<path d="M9 13l-3 2 1 3 3-1"></path>
<path d="M15 13l3 2-1 3-3-1"></path></svg
>Launching 17 August</span
>
</markas-screensaver>
`,
})
export default class ScreensaverBannerExample {
protected readonly banner = "h-16 rounded-xl bg-primary text-on-primary";
protected readonly label =
"flex items-center gap-2 px-1 py-1 text-sm font-semibold whitespace-nowrap";
protected readonly icon = "size-5";
}Installation
npx markasui@latest add screensaverpnpm dlx markasui@latest add screensaveryarn dlx markasui@latest add screensaverbunx --bun markasui@latest add screensaver- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Install the dependency:
npm install alpinejs - Copy the component source below to
resources/views/components/markas/screensaver.blade.php.
@props([
'speed' => 80,
'effect' => 'tone',
'tones' => ['primary', 'success', 'warning', 'danger'],
'seed' => 1,
'pauseOnHover' => true,
])
@php
$base = 'relative overflow-hidden [&>*]:absolute [&>*]:top-0 [&>*]:left-0 [&>*]:transition-colors [&>*]:duration-300 motion-reduce:[&>*]:transition-none';
$toneClasses = '[&>[data-tone=primary]]:text-primary [&>[data-tone=success]]:text-success [&>[data-tone=warning]]:text-warning [&>[data-tone=danger]]:text-danger [&>[data-tone=ink]]:text-ink [&>[data-tone=muted]]:text-muted';
@endphp
{{-- Places each child at a seeded spot, then bounces it off the walls at speed px per second. Runs only while the area is on screen, the tab is visible, and nothing inside is hovered or focused. --}}
<div
x-data="{
stop: null,
init() {
const o = { speed: @js((float) $speed), effect: @js($effect), tones: @js(array_values((array) $tones)), seed: @js((float) $seed), pauseOnHover: @js((bool) $pauseOnHover) };
const root = this.$el;
const quarter = Math.PI / 2;
const rand = (seed, n) => {
const x = Math.sin(seed * 78.233 + n * 12.9898) * 43758.5453;
return x - Math.floor(x);
};
const tones = o.tones.filter((t) => ['primary', 'success', 'warning', 'danger', 'ink', 'muted'].includes(t));
const items = [...root.children].map((el, i) => {
const angle = (0.2 + 0.6 * rand(o.seed, i * 4)) * quarter + Math.floor(rand(o.seed, i * 4 + 1) * 4) * quarter;
const x = rand(o.seed, i * 4 + 2) * (root.clientWidth - el.offsetWidth);
const y = rand(o.seed, i * 4 + 3) * (root.clientHeight - el.offsetHeight);
const item = { el, x: Math.max(0, Math.round(x)), y: Math.max(0, Math.round(y)), vx: Math.cos(angle) * o.speed, vy: Math.sin(angle) * o.speed, tone: i };
if (o.effect === 'tone' && tones.length) el.dataset.tone = tones[i % tones.length];
else delete el.dataset.tone;
el.style.translate = `${item.x}px ${item.y}px`;
return item;
});
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
const bump = (item, sideways) => {
if (o.effect === 'tone' && tones.length) item.el.dataset.tone = tones[++item.tone % tones.length];
if (o.effect === 'squash') item.el.animate?.([{ scale: '1' }, { scale: sideways ? '0.8 1.15' : '1.15 0.8' }, { scale: '1' }], { duration: 260, easing: 'ease-out' });
};
let frame = 0;
let last = 0;
const tick = (now) => {
const dt = last ? Math.min((now - last) / 1000, 0.05) : 0;
last = now;
for (const item of items) {
const maxX = Math.max(0, root.clientWidth - item.el.offsetWidth);
const maxY = Math.max(0, root.clientHeight - item.el.offsetHeight);
item.x += item.vx * dt;
item.y += item.vy * dt;
const sideways = (item.x <= 0 && item.vx < 0) || (item.x >= maxX && item.vx > 0);
const upright = (item.y <= 0 && item.vy < 0) || (item.y >= maxY && item.vy > 0);
if (sideways) item.vx = -item.vx;
if (upright) item.vy = -item.vy;
if (sideways || upright) bump(item, sideways);
item.x = Math.min(Math.max(item.x, 0), maxX);
item.y = Math.min(Math.max(item.y, 0), maxY);
item.el.style.translate = `${item.x}px ${item.y}px`;
}
frame = requestAnimationFrame(tick);
};
const state = { hover: false, focus: false, visible: true };
const sync = () => {
const run = state.visible && ! state.focus && ! (o.pauseOnHover && state.hover) && ! document.hidden;
cancelAnimationFrame(frame);
last = 0;
if (run) frame = requestAnimationFrame(tick);
};
const on = (key, value) => () => {
state[key] = value;
sync();
};
const listeners = [['pointerenter', on('hover', true)], ['pointerleave', on('hover', false)], ['focusin', on('focus', true)], ['focusout', on('focus', false)]];
for (const [type, fn] of listeners) root.addEventListener(type, fn);
document.addEventListener('visibilitychange', sync);
const observer = typeof IntersectionObserver === 'undefined' ? null : new IntersectionObserver(([entry]) => {
state.visible = !! entry?.isIntersecting;
sync();
});
observer?.observe(root);
sync();
this.stop = () => {
cancelAnimationFrame(frame);
observer?.disconnect();
document.removeEventListener('visibilitychange', sync);
for (const [type, fn] of listeners) root.removeEventListener(type, fn);
};
},
destroy() {
this.stop?.();
},
}"
{{ $attributes->class([$base, $toneClasses]) }}
>
{{ $slot }}
</div>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Screensaver.tsx.
"use client";
import { useLayoutEffect, useRef, type ComponentProps } from "react";
const base =
"relative overflow-hidden [&>*]:absolute [&>*]:top-0 [&>*]:left-0 [&>*]:transition-colors [&>*]:duration-300 motion-reduce:[&>*]:transition-none";
const toneClasses =
"[&>[data-tone=primary]]:text-primary [&>[data-tone=success]]:text-success [&>[data-tone=warning]]:text-warning [&>[data-tone=danger]]:text-danger [&>[data-tone=ink]]:text-ink [&>[data-tone=muted]]:text-muted";
export type ScreensaverEffect = "tone" | "squash" | "none";
export type ScreensaverTone =
"primary" | "success" | "warning" | "danger" | "ink" | "muted";
type Options = {
speed: number;
effect: ScreensaverEffect;
tones: ScreensaverTone[];
seed: number;
pauseOnHover: boolean;
};
const KNOWN_TONES = ["primary", "success", "warning", "danger", "ink", "muted"];
const QUARTER = Math.PI / 2;
const MAX_STEP_S = 0.05;
const SQUASH_MS = 260;
const cx = (...c: (string | false | null | undefined)[]) =>
c.filter(Boolean).join(" ");
/** Same number for the same seed and index in every framework. */
const rand = (seed: number, n: number) => {
const x = Math.sin(seed * 78.233 + n * 12.9898) * 43758.5453;
return x - Math.floor(x);
};
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
/**
* Place each child at a seeded spot, then bounce it off the walls at `speed` px per second.
* Runs only while the area is on screen, the tab is visible, and nothing inside is hovered or focused.
*/
export function startScreensaver(root: HTMLElement, o: Options) {
const tones = o.tones.filter((t) => KNOWN_TONES.includes(t));
const items = ([...root.children] as HTMLElement[]).map((el, i) => {
const angle =
(0.2 + 0.6 * rand(o.seed, i * 4)) * QUARTER +
Math.floor(rand(o.seed, i * 4 + 1) * 4) * QUARTER;
const x = rand(o.seed, i * 4 + 2) * (root.clientWidth - el.offsetWidth);
const y = rand(o.seed, i * 4 + 3) * (root.clientHeight - el.offsetHeight);
const item = {
el,
x: Math.max(0, Math.round(x)),
y: Math.max(0, Math.round(y)),
vx: Math.cos(angle) * o.speed,
vy: Math.sin(angle) * o.speed,
tone: i,
};
if (o.effect === "tone" && tones.length)
el.dataset.tone = tones[i % tones.length];
else delete el.dataset.tone;
el.style.translate = `${item.x}px ${item.y}px`;
return item;
});
if (still()) return () => {};
const bump = (item: (typeof items)[number], sideways: boolean) => {
if (o.effect === "tone" && tones.length)
item.el.dataset.tone = tones[++item.tone % tones.length];
if (o.effect === "squash")
item.el.animate?.(
[
{ scale: "1" },
{ scale: sideways ? "0.8 1.15" : "1.15 0.8" },
{ scale: "1" },
],
{ duration: SQUASH_MS, easing: "ease-out" },
);
};
let frame = 0;
let last = 0;
const tick = (now: number) => {
const dt = last ? Math.min((now - last) / 1000, MAX_STEP_S) : 0;
last = now;
for (const item of items) {
const maxX = Math.max(0, root.clientWidth - item.el.offsetWidth);
const maxY = Math.max(0, root.clientHeight - item.el.offsetHeight);
item.x += item.vx * dt;
item.y += item.vy * dt;
const sideways =
(item.x <= 0 && item.vx < 0) || (item.x >= maxX && item.vx > 0);
const upright =
(item.y <= 0 && item.vy < 0) || (item.y >= maxY && item.vy > 0);
if (sideways) item.vx = -item.vx;
if (upright) item.vy = -item.vy;
if (sideways || upright) bump(item, sideways);
item.x = Math.min(Math.max(item.x, 0), maxX);
item.y = Math.min(Math.max(item.y, 0), maxY);
item.el.style.translate = `${item.x}px ${item.y}px`;
}
frame = requestAnimationFrame(tick);
};
const state = { hover: false, focus: false, visible: true };
const sync = () => {
const run =
state.visible &&
!state.focus &&
!(o.pauseOnHover && state.hover) &&
!document.hidden;
cancelAnimationFrame(frame);
last = 0;
if (run) frame = requestAnimationFrame(tick);
};
const on = (key: "hover" | "focus", value: boolean) => () => {
state[key] = value;
sync();
};
const listeners = [
["pointerenter", on("hover", true)],
["pointerleave", on("hover", false)],
["focusin", on("focus", true)],
["focusout", on("focus", false)],
] as [string, (e: Event) => void][];
for (const [type, fn] of listeners) root.addEventListener(type, fn);
document.addEventListener("visibilitychange", sync);
const observer =
typeof IntersectionObserver === "undefined"
? undefined
: new IntersectionObserver(([entry]) => {
state.visible = !!entry?.isIntersecting;
sync();
});
observer?.observe(root);
sync();
return () => {
cancelAnimationFrame(frame);
observer?.disconnect();
document.removeEventListener("visibilitychange", sync);
for (const [type, fn] of listeners) root.removeEventListener(type, fn);
};
}
export type ScreensaverProps = ComponentProps<"div"> & {
/** Travel speed in px per second. */
speed?: number;
/** What happens on each wall hit: switch to the next tone, squash and stretch, or nothing. */
effect?: ScreensaverEffect;
/** Color tokens cycled by the tone effect. Children should use currentColor. */
tones?: ScreensaverTone[];
/** Changes the starting spots and directions. */
seed?: number;
/** Stops while the pointer is over the area. */
pauseOnHover?: boolean;
};
const DEFAULT_TONES: ScreensaverTone[] = [
"primary",
"success",
"warning",
"danger",
];
export function Screensaver({
speed = 80,
effect = "tone",
tones = DEFAULT_TONES,
seed = 1,
pauseOnHover = true,
className,
children,
...props
}: ScreensaverProps) {
const ref = useRef<HTMLDivElement>(null);
const toneKey = tones.join(" ");
useLayoutEffect(() => {
if (!ref.current) return;
return startScreensaver(ref.current, {
speed,
effect,
tones: toneKey.split(" ") as ScreensaverTone[],
seed,
pauseOnHover,
});
}, [speed, effect, toneKey, seed, pauseOnHover]);
return (
<div ref={ref} {...props} className={cx(base, toneClasses, className)}>
{children}
</div>
);
}- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Screensaver.vue.
<script setup lang="ts">
import { onBeforeUnmount, onMounted, useTemplateRef, watch } from "vue";
const props = withDefaults(
defineProps<{
/** Travel speed in px per second. */
speed?: number;
/** What happens on each wall hit: switch to the next tone, squash and stretch, or nothing. */
effect?: "tone" | "squash" | "none";
/** Color tokens cycled by the tone effect. Children should use currentColor. */
tones?: ("primary" | "success" | "warning" | "danger" | "ink" | "muted")[];
/** Changes the starting spots and directions. */
seed?: number;
/** Stops while the pointer is over the area. */
pauseOnHover?: boolean;
}>(),
{
speed: 80,
effect: "tone",
tones: () => ["primary", "success", "warning", "danger"],
seed: 1,
pauseOnHover: true,
},
);
const base =
"relative overflow-hidden [&>*]:absolute [&>*]:top-0 [&>*]:left-0 [&>*]:transition-colors [&>*]:duration-300 motion-reduce:[&>*]:transition-none";
const toneClasses =
"[&>[data-tone=primary]]:text-primary [&>[data-tone=success]]:text-success [&>[data-tone=warning]]:text-warning [&>[data-tone=danger]]:text-danger [&>[data-tone=ink]]:text-ink [&>[data-tone=muted]]:text-muted";
type ScreensaverEffect = "tone" | "squash" | "none";
type ScreensaverTone =
"primary" | "success" | "warning" | "danger" | "ink" | "muted";
type Options = {
speed: number;
effect: ScreensaverEffect;
tones: ScreensaverTone[];
seed: number;
pauseOnHover: boolean;
};
const KNOWN_TONES = ["primary", "success", "warning", "danger", "ink", "muted"];
const QUARTER = Math.PI / 2;
const MAX_STEP_S = 0.05;
const SQUASH_MS = 260;
/** Same number for the same seed and index in every framework. */
const rand = (seed: number, n: number) => {
const x = Math.sin(seed * 78.233 + n * 12.9898) * 43758.5453;
return x - Math.floor(x);
};
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
/**
* Place each child at a seeded spot, then bounce it off the walls at `speed` px per second.
* Runs only while the area is on screen, the tab is visible, and nothing inside is hovered or focused.
*/
function startScreensaver(root: HTMLElement, o: Options) {
const tones = o.tones.filter((t) => KNOWN_TONES.includes(t));
const items = ([...root.children] as HTMLElement[]).map((el, i) => {
const angle =
(0.2 + 0.6 * rand(o.seed, i * 4)) * QUARTER +
Math.floor(rand(o.seed, i * 4 + 1) * 4) * QUARTER;
const x = rand(o.seed, i * 4 + 2) * (root.clientWidth - el.offsetWidth);
const y = rand(o.seed, i * 4 + 3) * (root.clientHeight - el.offsetHeight);
const item = {
el,
x: Math.max(0, Math.round(x)),
y: Math.max(0, Math.round(y)),
vx: Math.cos(angle) * o.speed,
vy: Math.sin(angle) * o.speed,
tone: i,
};
if (o.effect === "tone" && tones.length)
el.dataset.tone = tones[i % tones.length];
else delete el.dataset.tone;
el.style.translate = `${item.x}px ${item.y}px`;
return item;
});
if (still()) return () => {};
const bump = (item: (typeof items)[number], sideways: boolean) => {
if (o.effect === "tone" && tones.length)
item.el.dataset.tone = tones[++item.tone % tones.length];
if (o.effect === "squash")
item.el.animate?.(
[
{ scale: "1" },
{ scale: sideways ? "0.8 1.15" : "1.15 0.8" },
{ scale: "1" },
],
{ duration: SQUASH_MS, easing: "ease-out" },
);
};
let frame = 0;
let last = 0;
const tick = (now: number) => {
const dt = last ? Math.min((now - last) / 1000, MAX_STEP_S) : 0;
last = now;
for (const item of items) {
const maxX = Math.max(0, root.clientWidth - item.el.offsetWidth);
const maxY = Math.max(0, root.clientHeight - item.el.offsetHeight);
item.x += item.vx * dt;
item.y += item.vy * dt;
const sideways =
(item.x <= 0 && item.vx < 0) || (item.x >= maxX && item.vx > 0);
const upright =
(item.y <= 0 && item.vy < 0) || (item.y >= maxY && item.vy > 0);
if (sideways) item.vx = -item.vx;
if (upright) item.vy = -item.vy;
if (sideways || upright) bump(item, sideways);
item.x = Math.min(Math.max(item.x, 0), maxX);
item.y = Math.min(Math.max(item.y, 0), maxY);
item.el.style.translate = `${item.x}px ${item.y}px`;
}
frame = requestAnimationFrame(tick);
};
const state = { hover: false, focus: false, visible: true };
const sync = () => {
const run =
state.visible &&
!state.focus &&
!(o.pauseOnHover && state.hover) &&
!document.hidden;
cancelAnimationFrame(frame);
last = 0;
if (run) frame = requestAnimationFrame(tick);
};
const on = (key: "hover" | "focus", value: boolean) => () => {
state[key] = value;
sync();
};
const listeners = [
["pointerenter", on("hover", true)],
["pointerleave", on("hover", false)],
["focusin", on("focus", true)],
["focusout", on("focus", false)],
] as [string, (e: Event) => void][];
for (const [type, fn] of listeners) root.addEventListener(type, fn);
document.addEventListener("visibilitychange", sync);
const observer =
typeof IntersectionObserver === "undefined"
? undefined
: new IntersectionObserver(([entry]) => {
state.visible = !!entry?.isIntersecting;
sync();
});
observer?.observe(root);
sync();
return () => {
cancelAnimationFrame(frame);
observer?.disconnect();
document.removeEventListener("visibilitychange", sync);
for (const [type, fn] of listeners) root.removeEventListener(type, fn);
};
}
const rootEl = useTemplateRef<HTMLDivElement>("rootRef");
let stop = () => {};
function start() {
stop();
stop = () => {};
if (rootEl.value)
stop = startScreensaver(rootEl.value, {
...props,
tones: [...props.tones],
});
}
onMounted(start);
watch(
() => [
props.speed,
props.effect,
props.tones.join(" "),
props.seed,
props.pauseOnHover,
],
start,
{
flush: "post",
},
);
onBeforeUnmount(() => stop());
</script>
<template>
<div ref="rootRef" :class="[base, toneClasses]">
<slot />
</div>
</template>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/Screensaver.svelte.
<script lang="ts">
import type { Snippet } from "svelte";
import type { HTMLAttributes } from "svelte/elements";
const base =
"relative overflow-hidden [&>*]:absolute [&>*]:top-0 [&>*]:left-0 [&>*]:transition-colors [&>*]:duration-300 motion-reduce:[&>*]:transition-none";
const toneClasses =
"[&>[data-tone=primary]]:text-primary [&>[data-tone=success]]:text-success [&>[data-tone=warning]]:text-warning [&>[data-tone=danger]]:text-danger [&>[data-tone=ink]]:text-ink [&>[data-tone=muted]]:text-muted";
type ScreensaverEffect = "tone" | "squash" | "none";
type ScreensaverTone =
"primary" | "success" | "warning" | "danger" | "ink" | "muted";
type Options = {
speed: number;
effect: ScreensaverEffect;
tones: ScreensaverTone[];
seed: number;
pauseOnHover: boolean;
};
const KNOWN_TONES = [
"primary",
"success",
"warning",
"danger",
"ink",
"muted",
];
const QUARTER = Math.PI / 2;
const MAX_STEP_S = 0.05;
const SQUASH_MS = 260;
/** Same number for the same seed and index in every framework. */
const rand = (seed: number, n: number) => {
const x = Math.sin(seed * 78.233 + n * 12.9898) * 43758.5453;
return x - Math.floor(x);
};
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
/**
* Place each child at a seeded spot, then bounce it off the walls at `speed` px per second.
* Runs only while the area is on screen, the tab is visible, and nothing inside is hovered or focused.
*/
function startScreensaver(root: HTMLElement, o: Options) {
const tones = o.tones.filter((t) => KNOWN_TONES.includes(t));
const items = ([...root.children] as HTMLElement[]).map((el, i) => {
const angle =
(0.2 + 0.6 * rand(o.seed, i * 4)) * QUARTER +
Math.floor(rand(o.seed, i * 4 + 1) * 4) * QUARTER;
const x = rand(o.seed, i * 4 + 2) * (root.clientWidth - el.offsetWidth);
const y = rand(o.seed, i * 4 + 3) * (root.clientHeight - el.offsetHeight);
const item = {
el,
x: Math.max(0, Math.round(x)),
y: Math.max(0, Math.round(y)),
vx: Math.cos(angle) * o.speed,
vy: Math.sin(angle) * o.speed,
tone: i,
};
if (o.effect === "tone" && tones.length)
el.dataset.tone = tones[i % tones.length];
else delete el.dataset.tone;
el.style.translate = `${item.x}px ${item.y}px`;
return item;
});
if (still()) return () => {};
const bump = (item: (typeof items)[number], sideways: boolean) => {
if (o.effect === "tone" && tones.length)
item.el.dataset.tone = tones[++item.tone % tones.length];
if (o.effect === "squash")
item.el.animate?.(
[
{ scale: "1" },
{ scale: sideways ? "0.8 1.15" : "1.15 0.8" },
{ scale: "1" },
],
{ duration: SQUASH_MS, easing: "ease-out" },
);
};
let frame = 0;
let last = 0;
const tick = (now: number) => {
const dt = last ? Math.min((now - last) / 1000, MAX_STEP_S) : 0;
last = now;
for (const item of items) {
const maxX = Math.max(0, root.clientWidth - item.el.offsetWidth);
const maxY = Math.max(0, root.clientHeight - item.el.offsetHeight);
item.x += item.vx * dt;
item.y += item.vy * dt;
const sideways =
(item.x <= 0 && item.vx < 0) || (item.x >= maxX && item.vx > 0);
const upright =
(item.y <= 0 && item.vy < 0) || (item.y >= maxY && item.vy > 0);
if (sideways) item.vx = -item.vx;
if (upright) item.vy = -item.vy;
if (sideways || upright) bump(item, sideways);
item.x = Math.min(Math.max(item.x, 0), maxX);
item.y = Math.min(Math.max(item.y, 0), maxY);
item.el.style.translate = `${item.x}px ${item.y}px`;
}
frame = requestAnimationFrame(tick);
};
const state = { hover: false, focus: false, visible: true };
const sync = () => {
const run =
state.visible &&
!state.focus &&
!(o.pauseOnHover && state.hover) &&
!document.hidden;
cancelAnimationFrame(frame);
last = 0;
if (run) frame = requestAnimationFrame(tick);
};
const on = (key: "hover" | "focus", value: boolean) => () => {
state[key] = value;
sync();
};
const listeners = [
["pointerenter", on("hover", true)],
["pointerleave", on("hover", false)],
["focusin", on("focus", true)],
["focusout", on("focus", false)],
] as [string, (e: Event) => void][];
for (const [type, fn] of listeners) root.addEventListener(type, fn);
document.addEventListener("visibilitychange", sync);
const observer =
typeof IntersectionObserver === "undefined"
? undefined
: new IntersectionObserver(([entry]) => {
state.visible = !!entry?.isIntersecting;
sync();
});
observer?.observe(root);
sync();
return () => {
cancelAnimationFrame(frame);
observer?.disconnect();
document.removeEventListener("visibilitychange", sync);
for (const [type, fn] of listeners) root.removeEventListener(type, fn);
};
}
const DEFAULT_TONES: ScreensaverTone[] = [
"primary",
"success",
"warning",
"danger",
];
type Props = HTMLAttributes<HTMLDivElement> & {
/** Travel speed in px per second. */
speed?: number;
/** What happens on each wall hit: switch to the next tone, squash and stretch, or nothing. */
effect?: ScreensaverEffect;
/** Color tokens cycled by the tone effect. Children should use currentColor. */
tones?: ScreensaverTone[];
/** Changes the starting spots and directions. */
seed?: number;
/** Stops while the pointer is over the area. */
pauseOnHover?: boolean;
children?: Snippet;
};
let {
speed = 80,
effect: wallEffect = "tone",
tones = DEFAULT_TONES,
seed = 1,
pauseOnHover = true,
class: className,
children,
...rest
}: Props = $props();
let root = $state<HTMLDivElement>();
$effect(() => {
const options = {
speed,
effect: wallEffect,
tones: [...tones],
seed,
pauseOnHover,
};
if (root) return startScreensaver(root, options);
});
</script>
<div bind:this={root} {...rest} class={[base, toneClasses, className]}>
{@render children?.()}
</div>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Screensaver.astro.
---
import type { HTMLAttributes } from "astro/types";
const base =
"relative overflow-hidden [&>*]:absolute [&>*]:top-0 [&>*]:left-0 [&>*]:transition-colors [&>*]:duration-300 motion-reduce:[&>*]:transition-none";
const toneClasses =
"[&>[data-tone=primary]]:text-primary [&>[data-tone=success]]:text-success [&>[data-tone=warning]]:text-warning [&>[data-tone=danger]]:text-danger [&>[data-tone=ink]]:text-ink [&>[data-tone=muted]]:text-muted";
type ScreensaverTone =
| "primary"
| "success"
| "warning"
| "danger"
| "ink"
| "muted";
type Props = HTMLAttributes<"div"> & {
/** Travel speed in px per second. */
speed?: number;
/** What happens on each wall hit: switch to the next tone, squash and stretch, or nothing. */
effect?: "tone" | "squash" | "none";
/** Color tokens cycled by the tone effect. Children should use currentColor. */
tones?: ScreensaverTone[];
/** Changes the starting spots and directions. */
seed?: number;
/** Stops while the pointer is over the area. */
pauseOnHover?: boolean;
};
const {
speed = 80,
effect = "tone",
tones = ["primary", "success", "warning", "danger"],
seed = 1,
pauseOnHover = true,
class: className,
...rest
} = Astro.props;
const options = JSON.stringify({
speed: Number(speed),
effect,
tones,
seed: Number(seed),
pauseOnHover: Boolean(pauseOnHover),
});
---
<markas-screensaver class="contents" data-options={options}>
<div {...rest} class:list={[base, toneClasses, className]}><slot /></div>
</markas-screensaver>
<script>
type ScreensaverEffect = "tone" | "squash" | "none";
type ScreensaverTone =
"primary" | "success" | "warning" | "danger" | "ink" | "muted";
type Options = {
speed: number;
effect: ScreensaverEffect;
tones: ScreensaverTone[];
seed: number;
pauseOnHover: boolean;
};
const KNOWN_TONES = ["primary", "success", "warning", "danger", "ink", "muted"];
const QUARTER = Math.PI / 2;
const MAX_STEP_S = 0.05;
const SQUASH_MS = 260;
/** Same number for the same seed and index in every framework. */
const rand = (seed: number, n: number) => {
const x = Math.sin(seed * 78.233 + n * 12.9898) * 43758.5453;
return x - Math.floor(x);
};
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
/**
* Place each child at a seeded spot, then bounce it off the walls at `speed` px per second.
* Runs only while the area is on screen, the tab is visible, and nothing inside is hovered or focused.
*/
function startScreensaver(root: HTMLElement, o: Options) {
const tones = o.tones.filter((t) => KNOWN_TONES.includes(t));
const items = ([...root.children] as HTMLElement[]).map((el, i) => {
const angle =
(0.2 + 0.6 * rand(o.seed, i * 4)) * QUARTER +
Math.floor(rand(o.seed, i * 4 + 1) * 4) * QUARTER;
const x = rand(o.seed, i * 4 + 2) * (root.clientWidth - el.offsetWidth);
const y = rand(o.seed, i * 4 + 3) * (root.clientHeight - el.offsetHeight);
const item = {
el,
x: Math.max(0, Math.round(x)),
y: Math.max(0, Math.round(y)),
vx: Math.cos(angle) * o.speed,
vy: Math.sin(angle) * o.speed,
tone: i,
};
if (o.effect === "tone" && tones.length)
el.dataset.tone = tones[i % tones.length];
else delete el.dataset.tone;
el.style.translate = `${item.x}px ${item.y}px`;
return item;
});
if (still()) return () => {};
const bump = (item: (typeof items)[number], sideways: boolean) => {
if (o.effect === "tone" && tones.length)
item.el.dataset.tone = tones[++item.tone % tones.length];
if (o.effect === "squash")
item.el.animate?.(
[
{ scale: "1" },
{ scale: sideways ? "0.8 1.15" : "1.15 0.8" },
{ scale: "1" },
],
{ duration: SQUASH_MS, easing: "ease-out" },
);
};
let frame = 0;
let last = 0;
const tick = (now: number) => {
const dt = last ? Math.min((now - last) / 1000, MAX_STEP_S) : 0;
last = now;
for (const item of items) {
const maxX = Math.max(0, root.clientWidth - item.el.offsetWidth);
const maxY = Math.max(0, root.clientHeight - item.el.offsetHeight);
item.x += item.vx * dt;
item.y += item.vy * dt;
const sideways =
(item.x <= 0 && item.vx < 0) || (item.x >= maxX && item.vx > 0);
const upright =
(item.y <= 0 && item.vy < 0) || (item.y >= maxY && item.vy > 0);
if (sideways) item.vx = -item.vx;
if (upright) item.vy = -item.vy;
if (sideways || upright) bump(item, sideways);
item.x = Math.min(Math.max(item.x, 0), maxX);
item.y = Math.min(Math.max(item.y, 0), maxY);
item.el.style.translate = `${item.x}px ${item.y}px`;
}
frame = requestAnimationFrame(tick);
};
const state = { hover: false, focus: false, visible: true };
const sync = () => {
const run =
state.visible &&
!state.focus &&
!(o.pauseOnHover && state.hover) &&
!document.hidden;
cancelAnimationFrame(frame);
last = 0;
if (run) frame = requestAnimationFrame(tick);
};
const on = (key: "hover" | "focus", value: boolean) => () => {
state[key] = value;
sync();
};
const listeners = [
["pointerenter", on("hover", true)],
["pointerleave", on("hover", false)],
["focusin", on("focus", true)],
["focusout", on("focus", false)],
] as [string, (e: Event) => void][];
for (const [type, fn] of listeners) root.addEventListener(type, fn);
document.addEventListener("visibilitychange", sync);
const observer =
typeof IntersectionObserver === "undefined"
? undefined
: new IntersectionObserver(([entry]) => {
state.visible = !!entry?.isIntersecting;
sync();
});
observer?.observe(root);
sync();
return () => {
cancelAnimationFrame(frame);
observer?.disconnect();
document.removeEventListener("visibilitychange", sync);
for (const [type, fn] of listeners) root.removeEventListener(type, fn);
};
}
// Per instance: each area runs its own loop while on screen and not hovered or focused.
class Screensaver extends HTMLElement {
#stop = () => {};
connectedCallback() {
const root = this.firstElementChild as HTMLElement | null;
if (!root) return;
this.#stop = startScreensaver(
root,
JSON.parse(this.dataset.options ?? "{}") as Options,
);
}
disconnectedCallback() {
this.#stop();
}
}
if (!customElements.get("markas-screensaver"))
customElements.define("markas-screensaver", Screensaver);
</script>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/screensaver.component.ts.
import {
afterRenderEffect,
booleanAttribute,
ChangeDetectionStrategy,
Component,
computed,
type ElementRef,
input,
numberAttribute,
viewChild,
} from "@angular/core";
const base =
"relative overflow-hidden [&>*]:absolute [&>*]:top-0 [&>*]:left-0 [&>*]:transition-colors [&>*]:duration-300 motion-reduce:[&>*]:transition-none";
const toneClasses =
"[&>[data-tone=primary]]:text-primary [&>[data-tone=success]]:text-success [&>[data-tone=warning]]:text-warning [&>[data-tone=danger]]:text-danger [&>[data-tone=ink]]:text-ink [&>[data-tone=muted]]:text-muted";
export type ScreensaverEffect = "tone" | "squash" | "none";
export type ScreensaverTone =
"primary" | "success" | "warning" | "danger" | "ink" | "muted";
type Options = {
speed: number;
effect: ScreensaverEffect;
tones: ScreensaverTone[];
seed: number;
pauseOnHover: boolean;
};
const KNOWN_TONES = ["primary", "success", "warning", "danger", "ink", "muted"];
const QUARTER = Math.PI / 2;
const MAX_STEP_S = 0.05;
const SQUASH_MS = 260;
/** Same number for the same seed and index in every framework. */
const rand = (seed: number, n: number) => {
const x = Math.sin(seed * 78.233 + n * 12.9898) * 43758.5453;
return x - Math.floor(x);
};
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
/**
* Place each child at a seeded spot, then bounce it off the walls at `speed` px per second.
* Runs only while the area is on screen, the tab is visible, and nothing inside is hovered or focused.
*/
function startScreensaver(root: HTMLElement, o: Options) {
const tones = o.tones.filter((t) => KNOWN_TONES.includes(t));
const items = ([...root.children] as HTMLElement[]).map((el, i) => {
const angle =
(0.2 + 0.6 * rand(o.seed, i * 4)) * QUARTER +
Math.floor(rand(o.seed, i * 4 + 1) * 4) * QUARTER;
const x = rand(o.seed, i * 4 + 2) * (root.clientWidth - el.offsetWidth);
const y = rand(o.seed, i * 4 + 3) * (root.clientHeight - el.offsetHeight);
const item = {
el,
x: Math.max(0, Math.round(x)),
y: Math.max(0, Math.round(y)),
vx: Math.cos(angle) * o.speed,
vy: Math.sin(angle) * o.speed,
tone: i,
};
if (o.effect === "tone" && tones.length)
el.dataset.tone = tones[i % tones.length];
else delete el.dataset.tone;
el.style.translate = `${item.x}px ${item.y}px`;
return item;
});
if (still()) return () => {};
const bump = (item: (typeof items)[number], sideways: boolean) => {
if (o.effect === "tone" && tones.length)
item.el.dataset.tone = tones[++item.tone % tones.length];
if (o.effect === "squash")
item.el.animate?.(
[
{ scale: "1" },
{ scale: sideways ? "0.8 1.15" : "1.15 0.8" },
{ scale: "1" },
],
{ duration: SQUASH_MS, easing: "ease-out" },
);
};
let frame = 0;
let last = 0;
const tick = (now: number) => {
const dt = last ? Math.min((now - last) / 1000, MAX_STEP_S) : 0;
last = now;
for (const item of items) {
const maxX = Math.max(0, root.clientWidth - item.el.offsetWidth);
const maxY = Math.max(0, root.clientHeight - item.el.offsetHeight);
item.x += item.vx * dt;
item.y += item.vy * dt;
const sideways =
(item.x <= 0 && item.vx < 0) || (item.x >= maxX && item.vx > 0);
const upright =
(item.y <= 0 && item.vy < 0) || (item.y >= maxY && item.vy > 0);
if (sideways) item.vx = -item.vx;
if (upright) item.vy = -item.vy;
if (sideways || upright) bump(item, sideways);
item.x = Math.min(Math.max(item.x, 0), maxX);
item.y = Math.min(Math.max(item.y, 0), maxY);
item.el.style.translate = `${item.x}px ${item.y}px`;
}
frame = requestAnimationFrame(tick);
};
const state = { hover: false, focus: false, visible: true };
const sync = () => {
const run =
state.visible &&
!state.focus &&
!(o.pauseOnHover && state.hover) &&
!document.hidden;
cancelAnimationFrame(frame);
last = 0;
if (run) frame = requestAnimationFrame(tick);
};
const on = (key: "hover" | "focus", value: boolean) => () => {
state[key] = value;
sync();
};
const listeners = [
["pointerenter", on("hover", true)],
["pointerleave", on("hover", false)],
["focusin", on("focus", true)],
["focusout", on("focus", false)],
] as [string, (e: Event) => void][];
for (const [type, fn] of listeners) root.addEventListener(type, fn);
document.addEventListener("visibilitychange", sync);
const observer =
typeof IntersectionObserver === "undefined"
? undefined
: new IntersectionObserver(([entry]) => {
state.visible = !!entry?.isIntersecting;
sync();
});
observer?.observe(root);
sync();
return () => {
cancelAnimationFrame(frame);
observer?.disconnect();
document.removeEventListener("visibilitychange", sync);
for (const [type, fn] of listeners) root.removeEventListener(type, fn);
};
}
const DEFAULT_TONES: ScreensaverTone[] = [
"primary",
"success",
"warning",
"danger",
];
/**
* Every projected element travels. The host stays out of layout; the user's class and aria-hidden
* land on the area.
*/
@Component({
selector: "markas-screensaver",
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: "contents", "[attr.aria-hidden]": "null" },
template: `<div #rootEl [class]="classes()" [attr.aria-hidden]="ariaHidden()">
<ng-content />
</div>`,
})
export class Screensaver {
/** Travel speed in px per second. */
readonly speed = input(80, { transform: numberAttribute });
/** What happens on each wall hit: switch to the next tone, squash and stretch, or nothing. */
readonly effect = input<ScreensaverEffect>("tone");
/** Color tokens cycled by the tone effect. Children should use currentColor. */
readonly tones = input<ScreensaverTone[]>(DEFAULT_TONES);
/** Changes the starting spots and directions. */
readonly seed = input(1, { transform: numberAttribute });
/** Stops while the pointer is over the area. */
readonly pauseOnHover = input(true, { transform: booleanAttribute });
/** Decorative areas pass aria-hidden="true"; it lands on the area, not the host. */
readonly ariaHidden = input<string>(undefined, { alias: "aria-hidden" });
readonly userClass = input("", { alias: "class" });
protected readonly classes = computed(() =>
[base, toneClasses, this.userClass()].filter(Boolean).join(" "),
);
private readonly root = viewChild.required<ElementRef<HTMLElement>>("rootEl");
constructor() {
afterRenderEffect((onCleanup) => {
const options = {
speed: this.speed(),
effect: this.effect(),
tones: [...this.tones()],
seed: this.seed(),
pauseOnHover: this.pauseOnHover(),
};
onCleanup(startScreensaver(this.root().nativeElement, options));
});
}
}Usage
<x-markas.screensaver class="h-44 rounded-lg bg-subtle" aria-hidden="true">
<span class="flex items-center gap-2 text-3xl font-bold">
<svg class="size-8" aria-hidden="true">...</svg>404
</span>
</x-markas.screensaver>Needs Alpine.js.
import { Screensaver } from "@/components/markas/Screensaver";
<Screensaver
effect="squash"
speed={50}
className="h-32 w-36 rounded-lg bg-subtle"
aria-hidden="true"
>
<span className="grid size-12 place-items-center rounded-xl bg-surface">
...
</span>
</Screensaver>;<template>
<Screensaver
:speed="60"
:tones="['success', 'warning']"
class="h-52 rounded-lg bg-canvas"
>
<span class="flex items-center gap-2 rounded-full bg-surface px-3 py-1">
<span class="size-2.5 rounded-full bg-current"></span>
<span class="text-ink">Rania Putri</span>
</span>
</Screensaver>
</template><script lang="ts">
import Screensaver from "$lib/components/markas/Screensaver.svelte";
</script>
<Screensaver class="h-56 rounded-xl border border-line" aria-hidden="true">
<span class="text-3xl font-bold">Markas</span>
</Screensaver>---
import Screensaver from "@/components/markas/Screensaver.astro";
---
<Screensaver class="h-56 rounded-xl border border-line" aria-hidden="true">
<span class="text-3xl font-bold">Markas</span>
</Screensaver>A small bundled script runs each area through the markas-screensaver element.
import { Component } from "@angular/core";
import { Screensaver } from "./markas/screensaver.component";
@Component({
selector: "app-idle",
imports: [Screensaver],
template: `
<markas-screensaver
effect="squash"
class="h-56 rounded-xl border border-line"
aria-hidden="true"
>
<span class="text-3xl font-bold">Markas</span>
</markas-screensaver>
`,
})
export class Idle {}- Each direct child starts at a seeded spot and bounces off the walls at
speedpx per second. Give the area a height. effect="tone"switches each element to the next token intoneson every wall hit; color the parts that should change withcurrentColor(such asbg-currentor an SVG stroke).effect="squash"squashes and stretches instead,"none"just bounces.- Motion pauses while the area is off screen, the tab is hidden, something inside has focus, or (with
pauseOnHover) the pointer is over it. - With reduced motion every element rests at its seeded spot in its first tone.
Props
| Name | Type | Default | Description |
|---|---|---|---|
speed | number | 80 | Travel speed in px per second. 40 to 60 feels lazy, 120 and up feels busy. |
effect | "tone" | "squash" | "none" | "tone" | What happens on each wall hit: switch to the next color token, squash and stretch like a rubber ball, or nothing. |
tones | ("primary" | "success" | "warning" | "danger" | "ink" | "muted")[] | ["primary", "success", "warning", "danger"] | Color tokens the tone effect cycles through. Each element starts on its own tone; style the parts that should change with currentColor. |
seed | number | 1 | Changes the starting spots and directions. The same seed always gives the same start. |
pauseOnHover | boolean | true | Stops the motion while the pointer is over the area. |
children / slot | ReactNode / slot | - | The bouncing elements. Each direct child moves on its own. Give the area a height, such as h-44. |
Accessibility
- Motion runs only while the area is on screen and the tab is visible, and stops while anything inside has keyboard focus.
- Mark a purely decorative area with aria-hidden="true"; text inside a bouncing element is otherwise read as usual.
- With reduced motion each element rests at its seeded spot in its first tone.
Related components
More markasui components with the same classes in every framework.
- Bottom NavigationMobile app style bottom bar. A pill glides to the selected item, its label rises in, and the bar can shrink to icons while content scrolls.
- Card StackLayered stack of cards. Swipe, arrow keys, or buttons throw the top card away and the next one rises. Loops, with a position indicator.
- Chat MessageMessage in an AI conversation. User bubbles on the right, assistant replies with an avatar, hover actions, a typing indicator, and optional token streaming.
- Currency InputMoney field that formats as you type (Rp 12.500.000), keeps the caret in place, and posts the plain number. Optional quick amount chips.
- DockmacOS style dock. Icons grow smoothly toward the pointer or focus, show a label above, mark open items with a dot, and bounce on launch.
- Drag ElementsArea of cards or stickers you can drag around with light momentum, kept inside its bounds. Arrow keys move a focused item, Escape puts it back.