Screensaver
Area tempat satu atau beberapa elemen memantul di dinding seperti screensaver DVD lama, berganti token warna atau memipih di setiap benturan.
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";
}Contoh
Empty state dengan kotak yang memipih
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";
}Beberapa orang memantul sekaligus
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";
}Banner peluncuran tipis
@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";
}Instalasi
npx markasui@latest add screensaverpnpm dlx markasui@latest add screensaveryarn dlx markasui@latest add screensaverbunx --bun markasui@latest add screensaver- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Pasang dependensi:
npm install alpinejs - Salin source komponen di bawah ini ke
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>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
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>
);
}- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
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>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
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>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
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>- Pastikan Tailwind CSS v4 dan markas.css sudah terpasang. Lihat Instalasi.
- Salin source komponen di bawah ini ke
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));
});
}
}Pemakaian
<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>Butuh 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>Satu script kecil yang dibundel menjalankan setiap area lewat elemen markas-screensaver.
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 {}- Setiap anak langsung mulai di posisi seed dan memantul di dinding dengan kecepatan
speedpx per detik. Beri area tinggi. effect="tone"memindahkan setiap elemen ke token berikutnya ditonespada setiap benturan; warnai bagian yang ikut berubah dengancurrentColor(misalnyabg-currentatau stroke SVG).effect="squash"membuatnya memipih dan memanjang,"none"hanya memantul.- Gerakan berhenti saat area di luar layar, tab tersembunyi, ada yang difokus di dalamnya, atau (dengan
pauseOnHover) kursor berada di atasnya. - Dengan reduced motion setiap elemen diam di posisi seed dengan tone pertamanya.
Props
| Nama | Tipe | Default | Keterangan |
|---|---|---|---|
speed | number | 80 | Kecepatan gerak dalam px per detik. 40 sampai 60 terasa santai, 120 ke atas terasa ramai. |
effect | "tone" | "squash" | "none" | "tone" | Yang terjadi di setiap benturan dinding: pindah ke token warna berikutnya, memipih dan memanjang seperti bola karet, atau tidak ada. |
tones | ("primary" | "success" | "warning" | "danger" | "ink" | "muted")[] | ["primary", "success", "warning", "danger"] | Token warna yang diputar oleh efek tone. Setiap elemen mulai dengan tone-nya sendiri; beri gaya currentColor pada bagian yang ikut berubah. |
seed | number | 1 | Mengubah posisi dan arah awal. Seed yang sama selalu menghasilkan awal yang sama. |
pauseOnHover | boolean | true | Menghentikan gerakan saat kursor berada di atas area. |
children / slot | ReactNode / slot | - | Elemen yang memantul. Setiap anak langsung bergerak sendiri. Beri area tinggi, misalnya h-44. |
Aksesibilitas
- Gerakan hanya berjalan saat area terlihat di layar dan tab aktif, dan berhenti saat ada yang memegang fokus keyboard di dalamnya.
- Tandai area yang murni dekoratif dengan aria-hidden="true"; teks di dalam elemen yang memantul tetap dibaca seperti biasa.
- Dengan reduced motion setiap elemen diam di posisi seed dengan tone pertamanya.
Komponen terkait
Komponen markasui lain dengan class yang sama di setiap framework.
- Bottom NavigationBar bawah gaya aplikasi mobile. Pill meluncur ke item terpilih, labelnya muncul, dan bar bisa menciut jadi ikon saat konten discroll.
- Card StackTumpukan kartu bertingkat. Geser, tombol panah, atau tombol navigasi membuang kartu teratas lalu kartu berikutnya naik. Berputar, dengan indikator posisi.
- Chat MessagePesan dalam percakapan AI. Gelembung user di kanan, balasan asisten dengan avatar, aksi saat hover, indikator mengetik, dan efek streaming token opsional.
- Currency InputKolom uang yang memformat saat mengetik (Rp 12.500.000), menjaga posisi kursor, dan mengirim angka murni. Opsional chip nominal cepat.
- DockDock ala macOS. Ikon membesar halus mengikuti kursor atau fokus, label muncul di atas, item terbuka bertitik, dan memantul saat dibuka.
- Drag ElementsArea kartu atau stiker yang bisa diseret dengan momentum ringan di dalam batasnya. Panah menggeser item yang fokus, Escape mengembalikannya.