Elastic Line
SVG line that bends toward, away from, or with the pointer when it comes close, then springs back. Works as a divider or a heading underline.
Release 2.4
Stacking cards, pixel trails, and a faster CLI.
Release 2.3
Indonesian docs and Rupiah currency input.
Release 2.4
Stacking cards, pixel trails, and a faster CLI.
Release 2.3
Indonesian docs and Rupiah currency input.
Release 2.4
Stacking cards, pixel trails, and a faster CLI.
Release 2.3
Indonesian docs and Rupiah currency input.
Release 2.4
Stacking cards, pixel trails, and a faster CLI.
Release 2.3
Indonesian docs and Rupiah currency input.
Release 2.4
Stacking cards, pixel trails, and a faster CLI.
Release 2.3
Indonesian docs and Rupiah currency input.
@php
$wrap = 'grid rounded-xl border border-line bg-surface px-6 py-4';
$section = 'py-2';
$title = 'text-base font-semibold text-ink';
$text = 'mt-1 text-sm text-muted';
@endphp
<div class="{{ $wrap }}">
<section class="{{ $section }}">
<h3 class="{{ $title }}">Release 2.4</h3>
<p class="{{ $text }}">Stacking cards, pixel trails, and a faster CLI.</p>
</section>
<x-markas.elastic-line />
<section class="{{ $section }}">
<h3 class="{{ $title }}">Release 2.3</h3>
<p class="{{ $text }}">Indonesian docs and Rupiah currency input.</p>
</section>
</div>import { ElasticLine } from "@/components/markas/ElasticLine";
const wrap = "grid rounded-xl border border-line bg-surface px-6 py-4";
const section = "py-2";
const title = "text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
export default function ElasticLineExample() {
return (
<div className={wrap}>
<section className={section}>
<h3 className={title}>Release 2.4</h3>
<p className={text}>Stacking cards, pixel trails, and a faster CLI.</p>
</section>
<ElasticLine />
<section className={section}>
<h3 className={title}>Release 2.3</h3>
<p className={text}>Indonesian docs and Rupiah currency input.</p>
</section>
</div>
);
}<script setup lang="ts">
import ElasticLine from "@/components/markas/ElasticLine.vue";
const wrap = "grid rounded-xl border border-line bg-surface px-6 py-4";
const section = "py-2";
const title = "text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
</script>
<template>
<div :class="wrap">
<section :class="section">
<h3 :class="title">Release 2.4</h3>
<p :class="text">Stacking cards, pixel trails, and a faster CLI.</p>
</section>
<ElasticLine />
<section :class="section">
<h3 :class="title">Release 2.3</h3>
<p :class="text">Indonesian docs and Rupiah currency input.</p>
</section>
</div>
</template><script lang="ts">
import ElasticLine from "$lib/components/markas/ElasticLine.svelte";
const wrap = "grid rounded-xl border border-line bg-surface px-6 py-4";
const section = "py-2";
const title = "text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
</script>
<div class={wrap}>
<section class={section}>
<h3 class={title}>Release 2.4</h3>
<p class={text}>Stacking cards, pixel trails, and a faster CLI.</p>
</section>
<ElasticLine />
<section class={section}>
<h3 class={title}>Release 2.3</h3>
<p class={text}>Indonesian docs and Rupiah currency input.</p>
</section>
</div>---
import ElasticLine from "@/components/markas/ElasticLine.astro";
const wrap = "grid rounded-xl border border-line bg-surface px-6 py-4";
const section = "py-2";
const title = "text-base font-semibold text-ink";
const text = "mt-1 text-sm text-muted";
---
<div class={wrap}>
<section class={section}>
<h3 class={title}>Release 2.4</h3>
<p class={text}>Stacking cards, pixel trails, and a faster CLI.</p>
</section>
<ElasticLine />
<section class={section}>
<h3 class={title}>Release 2.3</h3>
<p class={text}>Indonesian docs and Rupiah currency input.</p>
</section>
</div>import { Component } from "@angular/core";
import { ElasticLine } from "./markas/elastic-line.component";
@Component({
selector: "markas-example",
imports: [ElasticLine],
template: `
<div [class]="wrap">
<section [class]="section">
<h3 [class]="title">Release 2.4</h3>
<p [class]="text">Stacking cards, pixel trails, and a faster CLI.</p>
</section>
<markas-elastic-line />
<section [class]="section">
<h3 [class]="title">Release 2.3</h3>
<p [class]="text">Indonesian docs and Rupiah currency input.</p>
</section>
</div>
`,
})
export default class ElasticLineExample {
protected readonly wrap =
"grid rounded-xl border border-line bg-surface px-6 py-4";
protected readonly section = "py-2";
protected readonly title = "text-base font-semibold text-ink";
protected readonly text = "mt-1 text-sm text-muted";
}Examples
Plucked underline under a heading
New in Markas
Build faster, ship calmer
Touch the underline and pull: it slips free and vibrates like a string.
New in Markas
Build faster, ship calmer
Touch the underline and pull: it slips free and vibrates like a string.
New in Markas
Build faster, ship calmer
Touch the underline and pull: it slips free and vibrates like a string.
New in Markas
Build faster, ship calmer
Touch the underline and pull: it slips free and vibrates like a string.
New in Markas
Build faster, ship calmer
Touch the underline and pull: it slips free and vibrates like a string.
@php
$wrap = 'grid justify-items-start py-4';
$eyebrow = 'text-sm font-medium text-primary';
$title = 'mt-1 text-3xl font-semibold text-ink';
$line = 'w-48';
$text = 'max-w-80 text-sm text-muted';
@endphp
<div class="{{ $wrap }}">
<p class="{{ $eyebrow }}">New in Markas</p>
<h3 class="{{ $title }}">Build faster, ship calmer</h3>
<x-markas.elastic-line variant="pluck" color="primary" :stroke-width="3" :reach="16" play-on-view decorative :class="$line" />
<p class="{{ $text }}">Touch the underline and pull: it slips free and vibrates like a string.</p>
</div>import { ElasticLine } from "@/components/markas/ElasticLine";
const wrap = "grid justify-items-start py-4";
const eyebrow = "text-sm font-medium text-primary";
const title = "mt-1 text-3xl font-semibold text-ink";
const line = "w-48";
const text = "max-w-80 text-sm text-muted";
export default function Example() {
return (
<div className={wrap}>
<p className={eyebrow}>New in Markas</p>
<h3 className={title}>Build faster, ship calmer</h3>
<ElasticLine
variant="pluck"
color="primary"
strokeWidth={3}
reach={16}
playOnView
decorative
className={line}
/>
<p className={text}>
Touch the underline and pull: it slips free and vibrates like a string.
</p>
</div>
);
}<script setup lang="ts">
import ElasticLine from "@/components/markas/ElasticLine.vue";
const wrap = "grid justify-items-start py-4";
const eyebrow = "text-sm font-medium text-primary";
const title = "mt-1 text-3xl font-semibold text-ink";
const line = "w-48";
const text = "max-w-80 text-sm text-muted";
</script>
<template>
<div :class="wrap">
<p :class="eyebrow">New in Markas</p>
<h3 :class="title">Build faster, ship calmer</h3>
<ElasticLine
variant="pluck"
color="primary"
:stroke-width="3"
:reach="16"
play-on-view
decorative
:class="line"
/>
<p :class="text">
Touch the underline and pull: it slips free and vibrates like a string.
</p>
</div>
</template><script lang="ts">
import ElasticLine from "$lib/components/markas/ElasticLine.svelte";
const wrap = "grid justify-items-start py-4";
const eyebrow = "text-sm font-medium text-primary";
const title = "mt-1 text-3xl font-semibold text-ink";
const line = "w-48";
const text = "max-w-80 text-sm text-muted";
</script>
<div class={wrap}>
<p class={eyebrow}>New in Markas</p>
<h3 class={title}>Build faster, ship calmer</h3>
<ElasticLine
variant="pluck"
color="primary"
strokeWidth={3}
reach={16}
playOnView
decorative
class={line}
/>
<p class={text}>
Touch the underline and pull: it slips free and vibrates like a string.
</p>
</div>---
import ElasticLine from "@/components/markas/ElasticLine.astro";
const wrap = "grid justify-items-start py-4";
const eyebrow = "text-sm font-medium text-primary";
const title = "mt-1 text-3xl font-semibold text-ink";
const line = "w-48";
const text = "max-w-80 text-sm text-muted";
---
<div class={wrap}>
<p class={eyebrow}>New in Markas</p>
<h3 class={title}>Build faster, ship calmer</h3>
<ElasticLine
variant="pluck"
color="primary"
strokeWidth={3}
reach={16}
playOnView
decorative
class={line}
/>
<p class={text}>
Touch the underline and pull: it slips free and vibrates like a string.
</p>
</div>import { Component } from "@angular/core";
import { ElasticLine } from "./markas/elastic-line.component";
@Component({
selector: "markas-example",
imports: [ElasticLine],
template: `
<div [class]="wrap">
<p [class]="eyebrow">New in Markas</p>
<h3 [class]="title">Build faster, ship calmer</h3>
<markas-elastic-line
variant="pluck"
color="primary"
[strokeWidth]="3"
[reach]="16"
playOnView
decorative
[class]="line"
/>
<p [class]="text">
Touch the underline and pull: it slips free and vibrates like a string.
</p>
</div>
`,
})
export default class ElasticLineHeadingExample {
protected readonly wrap = "grid justify-items-start py-4";
protected readonly eyebrow = "text-sm font-medium text-primary";
protected readonly title = "mt-1 text-3xl font-semibold text-ink";
protected readonly line = "w-48";
protected readonly text = "max-w-80 text-sm text-muted";
}Vertical dividers between stats
61
Components
3
Frameworks
12k
Weekly installs
61
Components
3
Frameworks
12k
Weekly installs
61
Components
3
Frameworks
12k
Weekly installs
61
Components
3
Frameworks
12k
Weekly installs
61
Components
3
Frameworks
12k
Weekly installs
@php
$row = 'flex rounded-xl border border-line bg-surface py-5';
$stat = 'flex-1 text-center';
$value = 'text-2xl font-semibold text-ink tabular-nums';
$label = 'mt-1 text-sm text-muted';
@endphp
<div class="{{ $row }}">
<div class="{{ $stat }}">
<p class="{{ $value }}">61</p>
<p class="{{ $label }}">Components</p>
</div>
<x-markas.elastic-line variant="push" orientation="vertical" :reach="12" />
<div class="{{ $stat }}">
<p class="{{ $value }}">3</p>
<p class="{{ $label }}">Frameworks</p>
</div>
<x-markas.elastic-line variant="push" orientation="vertical" :reach="12" />
<div class="{{ $stat }}">
<p class="{{ $value }}">12k</p>
<p class="{{ $label }}">Weekly installs</p>
</div>
</div>import { ElasticLine } from "@/components/markas/ElasticLine";
const row = "flex rounded-xl border border-line bg-surface py-5";
const stat = "flex-1 text-center";
const value = "text-2xl font-semibold text-ink tabular-nums";
const label = "mt-1 text-sm text-muted";
export default function Example() {
return (
<div className={row}>
<div className={stat}>
<p className={value}>61</p>
<p className={label}>Components</p>
</div>
<ElasticLine variant="push" orientation="vertical" reach={12} />
<div className={stat}>
<p className={value}>3</p>
<p className={label}>Frameworks</p>
</div>
<ElasticLine variant="push" orientation="vertical" reach={12} />
<div className={stat}>
<p className={value}>12k</p>
<p className={label}>Weekly installs</p>
</div>
</div>
);
}<script setup lang="ts">
import ElasticLine from "@/components/markas/ElasticLine.vue";
const row = "flex rounded-xl border border-line bg-surface py-5";
const stat = "flex-1 text-center";
const value = "text-2xl font-semibold text-ink tabular-nums";
const label = "mt-1 text-sm text-muted";
</script>
<template>
<div :class="row">
<div :class="stat">
<p :class="value">61</p>
<p :class="label">Components</p>
</div>
<ElasticLine variant="push" orientation="vertical" :reach="12" />
<div :class="stat">
<p :class="value">3</p>
<p :class="label">Frameworks</p>
</div>
<ElasticLine variant="push" orientation="vertical" :reach="12" />
<div :class="stat">
<p :class="value">12k</p>
<p :class="label">Weekly installs</p>
</div>
</div>
</template><script lang="ts">
import ElasticLine from "$lib/components/markas/ElasticLine.svelte";
const row = "flex rounded-xl border border-line bg-surface py-5";
const stat = "flex-1 text-center";
const value = "text-2xl font-semibold text-ink tabular-nums";
const label = "mt-1 text-sm text-muted";
</script>
<div class={row}>
<div class={stat}>
<p class={value}>61</p>
<p class={label}>Components</p>
</div>
<ElasticLine variant="push" orientation="vertical" reach={12} />
<div class={stat}>
<p class={value}>3</p>
<p class={label}>Frameworks</p>
</div>
<ElasticLine variant="push" orientation="vertical" reach={12} />
<div class={stat}>
<p class={value}>12k</p>
<p class={label}>Weekly installs</p>
</div>
</div>---
import ElasticLine from "@/components/markas/ElasticLine.astro";
const row = "flex rounded-xl border border-line bg-surface py-5";
const stat = "flex-1 text-center";
const value = "text-2xl font-semibold text-ink tabular-nums";
const label = "mt-1 text-sm text-muted";
---
<div class={row}>
<div class={stat}>
<p class={value}>61</p>
<p class={label}>Components</p>
</div>
<ElasticLine variant="push" orientation="vertical" reach={12} />
<div class={stat}>
<p class={value}>3</p>
<p class={label}>Frameworks</p>
</div>
<ElasticLine variant="push" orientation="vertical" reach={12} />
<div class={stat}>
<p class={value}>12k</p>
<p class={label}>Weekly installs</p>
</div>
</div>import { Component } from "@angular/core";
import { ElasticLine } from "./markas/elastic-line.component";
@Component({
selector: "markas-example",
imports: [ElasticLine],
template: `
<div [class]="row">
<div [class]="stat">
<p [class]="value">61</p>
<p [class]="label">Components</p>
</div>
<markas-elastic-line variant="push" orientation="vertical" [reach]="12" />
<div [class]="stat">
<p [class]="value">3</p>
<p [class]="label">Frameworks</p>
</div>
<markas-elastic-line variant="push" orientation="vertical" [reach]="12" />
<div [class]="stat">
<p [class]="value">12k</p>
<p [class]="label">Weekly installs</p>
</div>
</div>
`,
})
export default class ElasticLineStatsExample {
protected readonly row = "flex rounded-xl border border-line bg-surface py-5";
protected readonly stat = "flex-1 text-center";
protected readonly value = "text-2xl font-semibold text-ink tabular-nums";
protected readonly label = "mt-1 text-sm text-muted";
}Footer divider
@php
$footer = 'grid gap-1';
$row = 'flex items-center justify-between gap-4 text-sm text-muted';
$links = 'flex gap-4';
$link = 'rounded-sm hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary';
$pages = [
['label' => 'Docs', 'href' => '/docs'],
['label' => 'Templates', 'href' => '/templates'],
['label' => 'GitHub', 'href' => 'https://github.com/markasui/markasui'],
];
@endphp
<footer class="{{ $footer }}">
<x-markas.elastic-line color="muted" :stroke-width="1" :reach="20" />
<div class="{{ $row }}">
<p>2026 MarkasUI, Bandung</p>
<nav aria-label="Footer">
<ul class="{{ $links }}">
@foreach ($pages as $page)
<li><a href="{{ $page['href'] }}" class="{{ $link }}">{{ $page['label'] }}</a></li>
@endforeach
</ul>
</nav>
</div>
</footer>import { ElasticLine } from "@/components/markas/ElasticLine";
const footer = "grid gap-1";
const row = "flex items-center justify-between gap-4 text-sm text-muted";
const links = "flex gap-4";
const link =
"rounded-sm hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
const pages = [
{ label: "Docs", href: "/docs" },
{ label: "Templates", href: "/templates" },
{ label: "GitHub", href: "https://github.com/markasui/markasui" },
];
export default function Example() {
return (
<footer className={footer}>
<ElasticLine color="muted" strokeWidth={1} reach={20} />
<div className={row}>
<p>2026 MarkasUI, Bandung</p>
<nav aria-label="Footer">
<ul className={links}>
{pages.map((page) => (
<li key={page.label}>
<a href={page.href} className={link}>
{page.label}
</a>
</li>
))}
</ul>
</nav>
</div>
</footer>
);
}<script setup lang="ts">
import ElasticLine from "@/components/markas/ElasticLine.vue";
const footer = "grid gap-1";
const row = "flex items-center justify-between gap-4 text-sm text-muted";
const links = "flex gap-4";
const link =
"rounded-sm hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
const pages = [
{ label: "Docs", href: "/docs" },
{ label: "Templates", href: "/templates" },
{ label: "GitHub", href: "https://github.com/markasui/markasui" },
];
</script>
<template>
<footer :class="footer">
<ElasticLine color="muted" :stroke-width="1" :reach="20" />
<div :class="row">
<p>2026 MarkasUI, Bandung</p>
<nav aria-label="Footer">
<ul :class="links">
<li v-for="page in pages" :key="page.label">
<a :href="page.href" :class="link">{{ page.label }}</a>
</li>
</ul>
</nav>
</div>
</footer>
</template><script lang="ts">
import ElasticLine from "$lib/components/markas/ElasticLine.svelte";
const footer = "grid gap-1";
const row = "flex items-center justify-between gap-4 text-sm text-muted";
const links = "flex gap-4";
const link =
"rounded-sm hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
const pages = [
{ label: "Docs", href: "/docs" },
{ label: "Templates", href: "/templates" },
{ label: "GitHub", href: "https://github.com/markasui/markasui" },
];
</script>
<footer class={footer}>
<ElasticLine color="muted" strokeWidth={1} reach={20} />
<div class={row}>
<p>2026 MarkasUI, Bandung</p>
<nav aria-label="Footer">
<ul class={links}>
{#each pages as page (page.label)}
<li>
<a href={page.href} class={link}>{page.label}</a>
</li>
{/each}
</ul>
</nav>
</div>
</footer>---
import ElasticLine from "@/components/markas/ElasticLine.astro";
const footer = "grid gap-1";
const row = "flex items-center justify-between gap-4 text-sm text-muted";
const links = "flex gap-4";
const link =
"rounded-sm hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
const pages = [
{ label: "Docs", href: "/docs" },
{ label: "Templates", href: "/templates" },
{ label: "GitHub", href: "https://github.com/markasui/markasui" },
];
---
<footer class={footer}>
<ElasticLine color="muted" strokeWidth={1} reach={20} />
<div class={row}>
<p>2026 MarkasUI, Bandung</p>
<nav aria-label="Footer">
<ul class={links}>
{
pages.map((page) => (
<li>
<a href={page.href} class={link}>{page.label}</a>
</li>
))
}
</ul>
</nav>
</div>
</footer>import { Component } from "@angular/core";
import { ElasticLine } from "./markas/elastic-line.component";
@Component({
selector: "markas-example",
imports: [ElasticLine],
template: `
<footer [class]="footer">
<markas-elastic-line color="muted" [strokeWidth]="1" [reach]="20" />
<div [class]="row">
<p>2026 MarkasUI, Bandung</p>
<nav aria-label="Footer">
<ul [class]="links">
@for (page of pages; track page.label) {
<li>
<a [href]="page.href" [class]="link">{{ page.label }}</a>
</li>
}
</ul>
</nav>
</div>
</footer>
`,
})
export default class ElasticLineFooterExample {
protected readonly footer = "grid gap-1";
protected readonly row =
"flex items-center justify-between gap-4 text-sm text-muted";
protected readonly links = "flex gap-4";
protected readonly link =
"rounded-sm hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary";
protected readonly pages = [
{ label: "Docs", href: "/docs" },
{ label: "Templates", href: "/templates" },
{ label: "GitHub", href: "https://github.com/markasui/markasui" },
];
}Installation
npx markasui@latest add elastic-linepnpm dlx markasui@latest add elastic-lineyarn dlx markasui@latest add elastic-linebunx --bun markasui@latest add elastic-line- 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/elastic-line.blade.php.
@props([
'variant' => 'pull',
'orientation' => 'horizontal',
'reach' => 24,
'color' => 'line',
'strokeWidth' => 1.5,
'playOnView' => false,
'decorative' => false,
])
@php
$base = 'relative block';
$orientations = [
'horizontal' => 'h-[calc(var(--reach)*2)]',
'vertical' => 'w-[calc(var(--reach)*2)] self-stretch',
];
$colors = [
'line' => 'text-line',
'muted' => 'text-muted',
'ink' => 'text-ink',
'primary' => 'text-primary',
'success' => 'text-success',
'warning' => 'text-warning',
'danger' => 'text-danger',
];
$svgClass = 'pointer-events-none absolute inset-0 size-full overflow-visible';
$pathClass = 'fill-none stroke-current [vector-effect:non-scaling-stroke]';
$vertical = $orientation === 'vertical';
$options = [
'vertical' => $vertical,
'variant' => in_array($variant, ['pull', 'push', 'pluck'], true) ? $variant : 'pull',
'playOnView' => (bool) $playOnView,
];
$a11y = $decorative ? ['aria-hidden' => 'true'] : ['role' => 'separator', 'aria-orientation' => $vertical ? 'vertical' : 'horizontal'];
@endphp
{{-- Bends toward (pull), away from (push), or with the pointer until it slips (pluck), then springs back. rAF only runs while active. --}}
<div
x-data="{
stop: null,
curve(vertical, along = 50, bend = 0) {
return vertical ? `M50 0Q${50 + 2 * bend} ${along} 50 100` : `M0 50Q${along} ${50 + 2 * bend} 100 50`;
},
init() {
const { vertical, variant, playOnView } = @js($options);
const springs = { pull: { k: 0.12, d: 0.82 }, push: { k: 0.1, d: 0.8 }, pluck: { k: 0.3, d: 0.6 }, release: { k: 0.18, d: 0.93 } };
const root = this.$root;
const path = this.$refs.path;
const still = () => window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
let pointer = null;
let along = 50;
let bend = 0;
let speed = 0;
let grabbed = false;
let frame = 0;
const reach = () => {
const rect = root.getBoundingClientRect();
return (vertical ? rect.width : rect.height) / 2 || 1;
};
const step = () => {
const half = reach();
let target = 0;
let spring = springs.release;
if (pointer) {
along = Math.min(Math.max(pointer.along, 10), 90);
const perp = pointer.perp;
if (variant === 'pull') target = perp;
if (variant === 'push') target = -Math.sign(perp || 1) * (half - Math.abs(perp)) * 0.6;
if (variant === 'pluck') {
if (Math.abs(perp) > half * 0.8) grabbed = false;
if (grabbed) target = perp;
}
if (variant !== 'pluck') spring = springs[variant];
else if (grabbed) spring = springs.pluck;
}
speed = (speed + (target - bend) * spring.k) * spring.d;
bend += speed;
const settled = ! pointer && Math.abs(bend) < 0.05 && Math.abs(speed) < 0.05;
if (settled) bend = speed = 0;
path.setAttribute('d', this.curve(vertical, along, (bend / half) * 50));
frame = settled ? 0 : requestAnimationFrame(step);
};
const wake = () => {
frame ||= requestAnimationFrame(step);
};
const move = (event) => {
if (still()) return;
const rect = root.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const next = vertical ? { along: (y / rect.height) * 100, perp: x - rect.width / 2 } : { along: (x / rect.width) * 100, perp: y - rect.height / 2 };
{{-- Pluck grabs when the pointer touches or crosses the line, even between two frames. --}}
const crossed = pointer && Math.sign(pointer.perp) !== Math.sign(next.perp);
if (Math.abs(next.perp) < 6 || crossed) grabbed = true;
pointer = next;
wake();
};
const leave = () => {
pointer = null;
grabbed = false;
wake();
};
root.addEventListener('pointermove', move);
root.addEventListener('pointerleave', leave);
{{-- Twang once when the line first scrolls into view. --}}
let observer = null;
if (playOnView && ! still() && typeof IntersectionObserver === 'function') {
observer = new IntersectionObserver(([entry]) => {
if (! entry?.isIntersecting) return;
observer.disconnect();
speed = reach() * 0.5;
wake();
});
observer.observe(root);
}
this.stop = () => {
root.removeEventListener('pointermove', move);
root.removeEventListener('pointerleave', leave);
observer?.disconnect();
cancelAnimationFrame(frame);
};
},
destroy() {
this.stop?.();
},
}"
{{ $attributes->merge([...$a11y, 'style' => '--reach: '.(float) $reach.'px'])->class([$base, $orientations[$orientation] ?? $orientations['horizontal'], $colors[$color] ?? $colors['line']]) }}
>
<svg aria-hidden="true" viewBox="0 0 100 100" preserveAspectRatio="none" class="{{ $svgClass }}">
<path
x-ref="path"
d="{{ $vertical ? 'M50 0Q50 50 50 100' : 'M0 50Q50 50 100 50' }}"
stroke-width="{{ (float) $strokeWidth }}"
stroke-linecap="round"
class="{{ $pathClass }}"
/>
</svg>
</div>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/ElasticLine.tsx.
"use client";
import { useEffect, useRef, type ComponentProps } from "react";
export type ElasticLineVariant = "pull" | "push" | "pluck";
export type ElasticLineOrientation = "horizontal" | "vertical";
const base = "relative block";
const orientations: Record<ElasticLineOrientation, string> = {
horizontal: "h-[calc(var(--reach)*2)]",
vertical: "w-[calc(var(--reach)*2)] self-stretch",
};
const colors = {
line: "text-line",
muted: "text-muted",
ink: "text-ink",
primary: "text-primary",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const svgClass =
"pointer-events-none absolute inset-0 size-full overflow-visible";
const pathClass = "fill-none stroke-current [vector-effect:non-scaling-stroke]";
/** Spring per variant: k pulls toward the target, d keeps that share of the speed each frame. */
const SPRINGS = {
pull: { k: 0.12, d: 0.82 },
push: { k: 0.1, d: 0.8 },
pluck: { k: 0.3, d: 0.6 },
release: { k: 0.18, d: 0.93 },
};
const REST = 0.05;
const cx = (...c: (string | false | null | undefined)[]) =>
c.filter(Boolean).join(" ");
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
/** Quadratic curve in a 0 to 100 box. The control sits at twice the bend so the line peaks at the bend. */
export const curve = (vertical: boolean, along = 50, bend = 0) =>
vertical
? `M50 0Q${50 + 2 * bend} ${along} 50 100`
: `M0 50Q${along} ${50 + 2 * bend} 100 50`;
/**
* Bend the line toward (pull), away from (push), or with the pointer until it slips (pluck), then spring
* back. requestAnimationFrame only runs while the pointer is near or the line still moves.
*/
function createLine(
root: HTMLElement,
path: SVGPathElement,
vertical: boolean,
variant: ElasticLineVariant,
playOnView: boolean,
) {
let pointer: { along: number; perp: number } | null = null;
let along = 50;
let bend = 0;
let speed = 0;
let grabbed = false;
let frame = 0;
const reach = () => {
const rect = root.getBoundingClientRect();
return (vertical ? rect.width : rect.height) / 2 || 1;
};
const step = () => {
const half = reach();
let target = 0;
let spring = SPRINGS.release;
if (pointer) {
along = Math.min(Math.max(pointer.along, 10), 90);
const perp = pointer.perp;
if (variant === "pull") target = perp;
if (variant === "push")
target = -Math.sign(perp || 1) * (half - Math.abs(perp)) * 0.6;
if (variant === "pluck") {
if (Math.abs(perp) > half * 0.8) grabbed = false;
if (grabbed) target = perp;
}
if (variant !== "pluck") spring = SPRINGS[variant];
else if (grabbed) spring = SPRINGS.pluck;
}
speed = (speed + (target - bend) * spring.k) * spring.d;
bend += speed;
const settled = !pointer && Math.abs(bend) < REST && Math.abs(speed) < REST;
if (settled) bend = speed = 0;
path.setAttribute("d", curve(vertical, along, (bend / half) * 50));
frame = settled ? 0 : requestAnimationFrame(step);
};
const wake = () => {
frame ||= requestAnimationFrame(step);
};
const move = (event: PointerEvent) => {
if (still()) return;
const rect = root.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const next = vertical
? { along: (y / rect.height) * 100, perp: x - rect.width / 2 }
: { along: (x / rect.width) * 100, perp: y - rect.height / 2 };
// Pluck grabs when the pointer touches or crosses the line, even between two frames.
const crossed = pointer && Math.sign(pointer.perp) !== Math.sign(next.perp);
if (Math.abs(next.perp) < 6 || crossed) grabbed = true;
pointer = next;
wake();
};
const leave = () => {
pointer = null;
grabbed = false;
wake();
};
root.addEventListener("pointermove", move);
root.addEventListener("pointerleave", leave);
// Twang once when the line first scrolls into view.
let observer: IntersectionObserver | null = null;
if (playOnView && !still() && typeof IntersectionObserver === "function") {
observer = new IntersectionObserver(([entry]) => {
if (!entry?.isIntersecting) return;
observer?.disconnect();
speed = reach() * 0.5;
wake();
});
observer.observe(root);
}
return () => {
root.removeEventListener("pointermove", move);
root.removeEventListener("pointerleave", leave);
observer?.disconnect();
cancelAnimationFrame(frame);
};
}
export type ElasticLineProps = ComponentProps<"div"> & {
/** How the line answers the pointer. */
variant?: ElasticLineVariant;
/** Direction of the line. */
orientation?: ElasticLineOrientation;
/** Px on each side of the line where the pointer bends it, and the most it can bend. */
reach?: number;
/** Line color token. */
color?: keyof typeof colors;
/** Line width in px. */
strokeWidth?: number;
/** Twangs once when the line first scrolls into view. */
playOnView?: boolean;
/** Hides the line from assistive tech instead of announcing a separator. */
decorative?: boolean;
};
export function ElasticLine({
variant = "pull",
orientation = "horizontal",
reach = 24,
color = "line",
strokeWidth = 1.5,
playOnView = false,
decorative = false,
className,
style,
...props
}: ElasticLineProps) {
const rootRef = useRef<HTMLDivElement>(null);
const pathRef = useRef<SVGPathElement>(null);
const vertical = orientation === "vertical";
useEffect(
() =>
createLine(
rootRef.current!,
pathRef.current!,
vertical,
variant,
playOnView,
),
[vertical, variant, playOnView],
);
return (
<div
role={decorative ? undefined : "separator"}
aria-orientation={decorative ? undefined : orientation}
aria-hidden={decorative ? "true" : undefined}
{...props}
ref={rootRef}
className={cx(base, orientations[orientation], colors[color], className)}
style={
{ "--reach": `${reach}px`, ...style } as ComponentProps<"div">["style"]
}
>
<svg
aria-hidden="true"
viewBox="0 0 100 100"
preserveAspectRatio="none"
className={svgClass}
>
<path
ref={pathRef}
d={curve(vertical)}
strokeWidth={strokeWidth}
strokeLinecap="round"
className={pathClass}
/>
</svg>
</div>
);
}- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/ElasticLine.vue.
<script setup lang="ts">
import { onBeforeUnmount, onMounted, useTemplateRef, watch } from "vue";
export type ElasticLineVariant = "pull" | "push" | "pluck";
export type ElasticLineOrientation = "horizontal" | "vertical";
const colors = {
line: "text-line",
muted: "text-muted",
ink: "text-ink",
primary: "text-primary",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const props = withDefaults(
defineProps<{
/** How the line answers the pointer. */
variant?: ElasticLineVariant;
/** Direction of the line. */
orientation?: ElasticLineOrientation;
/** Px on each side of the line where the pointer bends it, and the most it can bend. */
reach?: number;
/** Line color token. */
color?: keyof typeof colors;
/** Line width in px. */
strokeWidth?: number;
/** Twangs once when the line first scrolls into view. */
playOnView?: boolean;
/** Hides the line from assistive tech instead of announcing a separator. */
decorative?: boolean;
}>(),
{
variant: "pull",
orientation: "horizontal",
reach: 24,
color: "line",
strokeWidth: 1.5,
playOnView: false,
decorative: false,
},
);
const base = "relative block";
const orientations: Record<ElasticLineOrientation, string> = {
horizontal: "h-[calc(var(--reach)*2)]",
vertical: "w-[calc(var(--reach)*2)] self-stretch",
};
const svgClass =
"pointer-events-none absolute inset-0 size-full overflow-visible";
const pathClass = "fill-none stroke-current [vector-effect:non-scaling-stroke]";
/** Spring per variant: k pulls toward the target, d keeps that share of the speed each frame. */
const SPRINGS = {
pull: { k: 0.12, d: 0.82 },
push: { k: 0.1, d: 0.8 },
pluck: { k: 0.3, d: 0.6 },
release: { k: 0.18, d: 0.93 },
};
const REST = 0.05;
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
/** Quadratic curve in a 0 to 100 box. The control sits at twice the bend so the line peaks at the bend. */
const curve = (vertical: boolean, along = 50, bend = 0) =>
vertical
? `M50 0Q${50 + 2 * bend} ${along} 50 100`
: `M0 50Q${along} ${50 + 2 * bend} 100 50`;
/**
* Bend the line toward (pull), away from (push), or with the pointer until it slips (pluck), then spring
* back. requestAnimationFrame only runs while the pointer is near or the line still moves.
*/
function createLine(root: HTMLElement, path: SVGPathElement) {
const vertical = props.orientation === "vertical";
const variant = props.variant;
let pointer: { along: number; perp: number } | null = null;
let along = 50;
let bend = 0;
let speed = 0;
let grabbed = false;
let frame = 0;
const reach = () => {
const rect = root.getBoundingClientRect();
return (vertical ? rect.width : rect.height) / 2 || 1;
};
const step = () => {
const half = reach();
let target = 0;
let spring = SPRINGS.release;
if (pointer) {
along = Math.min(Math.max(pointer.along, 10), 90);
const perp = pointer.perp;
if (variant === "pull") target = perp;
if (variant === "push")
target = -Math.sign(perp || 1) * (half - Math.abs(perp)) * 0.6;
if (variant === "pluck") {
if (Math.abs(perp) > half * 0.8) grabbed = false;
if (grabbed) target = perp;
}
if (variant !== "pluck") spring = SPRINGS[variant];
else if (grabbed) spring = SPRINGS.pluck;
}
speed = (speed + (target - bend) * spring.k) * spring.d;
bend += speed;
const settled = !pointer && Math.abs(bend) < REST && Math.abs(speed) < REST;
if (settled) bend = speed = 0;
path.setAttribute("d", curve(vertical, along, (bend / half) * 50));
frame = settled ? 0 : requestAnimationFrame(step);
};
const wake = () => {
frame ||= requestAnimationFrame(step);
};
const move = (event: PointerEvent) => {
if (still()) return;
const rect = root.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const next = vertical
? { along: (y / rect.height) * 100, perp: x - rect.width / 2 }
: { along: (x / rect.width) * 100, perp: y - rect.height / 2 };
// Pluck grabs when the pointer touches or crosses the line, even between two frames.
const crossed = pointer && Math.sign(pointer.perp) !== Math.sign(next.perp);
if (Math.abs(next.perp) < 6 || crossed) grabbed = true;
pointer = next;
wake();
};
const leave = () => {
pointer = null;
grabbed = false;
wake();
};
root.addEventListener("pointermove", move);
root.addEventListener("pointerleave", leave);
// Twang once when the line first scrolls into view.
let observer: IntersectionObserver | null = null;
if (
props.playOnView &&
!still() &&
typeof IntersectionObserver === "function"
) {
observer = new IntersectionObserver(([entry]) => {
if (!entry?.isIntersecting) return;
observer?.disconnect();
speed = reach() * 0.5;
wake();
});
observer.observe(root);
}
return () => {
root.removeEventListener("pointermove", move);
root.removeEventListener("pointerleave", leave);
observer?.disconnect();
cancelAnimationFrame(frame);
};
}
const rootEl = useTemplateRef<HTMLDivElement>("rootRef");
const pathEl = useTemplateRef<SVGPathElement>("pathRef");
let stop = () => {};
const start = () => {
stop();
stop = createLine(rootEl.value!, pathEl.value!);
};
onMounted(start);
watch(() => [props.orientation, props.variant, props.playOnView], start);
onBeforeUnmount(() => stop());
</script>
<template>
<div
ref="rootRef"
:role="props.decorative ? undefined : 'separator'"
:aria-orientation="props.decorative ? undefined : props.orientation"
:aria-hidden="props.decorative ? 'true' : undefined"
:class="[base, orientations[props.orientation], colors[props.color]]"
:style="{ '--reach': `${props.reach}px` }"
>
<svg
aria-hidden="true"
viewBox="0 0 100 100"
preserveAspectRatio="none"
:class="svgClass"
>
<path
ref="pathRef"
:d="curve(props.orientation === 'vertical')"
:stroke-width="props.strokeWidth"
stroke-linecap="round"
:class="pathClass"
/>
</svg>
</div>
</template>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/ElasticLine.svelte.
<script lang="ts" module>
export type ElasticLineVariant = "pull" | "push" | "pluck";
export type ElasticLineOrientation = "horizontal" | "vertical";
/** Spring per variant: k pulls toward the target, d keeps that share of the speed each frame. */
const SPRINGS = {
pull: { k: 0.12, d: 0.82 },
push: { k: 0.1, d: 0.8 },
pluck: { k: 0.3, d: 0.6 },
release: { k: 0.18, d: 0.93 },
};
const REST = 0.05;
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
/** Quadratic curve in a 0 to 100 box. The control sits at twice the bend so the line peaks at the bend. */
export const curve = (vertical: boolean, along = 50, bend = 0) =>
vertical
? `M50 0Q${50 + 2 * bend} ${along} 50 100`
: `M0 50Q${along} ${50 + 2 * bend} 100 50`;
/**
* Bend the line toward (pull), away from (push), or with the pointer until it slips (pluck), then spring
* back. requestAnimationFrame only runs while the pointer is near or the line still moves.
*/
function createLine(
root: HTMLElement,
path: SVGPathElement,
vertical: boolean,
variant: ElasticLineVariant,
playOnView: boolean,
) {
let pointer: { along: number; perp: number } | null = null;
let along = 50;
let bend = 0;
let speed = 0;
let grabbed = false;
let frame = 0;
const reach = () => {
const rect = root.getBoundingClientRect();
return (vertical ? rect.width : rect.height) / 2 || 1;
};
const step = () => {
const half = reach();
let target = 0;
let spring = SPRINGS.release;
if (pointer) {
along = Math.min(Math.max(pointer.along, 10), 90);
const perp = pointer.perp;
if (variant === "pull") target = perp;
if (variant === "push")
target = -Math.sign(perp || 1) * (half - Math.abs(perp)) * 0.6;
if (variant === "pluck") {
if (Math.abs(perp) > half * 0.8) grabbed = false;
if (grabbed) target = perp;
}
if (variant !== "pluck") spring = SPRINGS[variant];
else if (grabbed) spring = SPRINGS.pluck;
}
speed = (speed + (target - bend) * spring.k) * spring.d;
bend += speed;
const settled =
!pointer && Math.abs(bend) < REST && Math.abs(speed) < REST;
if (settled) bend = speed = 0;
path.setAttribute("d", curve(vertical, along, (bend / half) * 50));
frame = settled ? 0 : requestAnimationFrame(step);
};
const wake = () => {
frame ||= requestAnimationFrame(step);
};
const move = (event: PointerEvent) => {
if (still()) return;
const rect = root.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const next = vertical
? { along: (y / rect.height) * 100, perp: x - rect.width / 2 }
: { along: (x / rect.width) * 100, perp: y - rect.height / 2 };
// Pluck grabs when the pointer touches or crosses the line, even between two frames.
const crossed =
pointer && Math.sign(pointer.perp) !== Math.sign(next.perp);
if (Math.abs(next.perp) < 6 || crossed) grabbed = true;
pointer = next;
wake();
};
const leave = () => {
pointer = null;
grabbed = false;
wake();
};
root.addEventListener("pointermove", move);
root.addEventListener("pointerleave", leave);
// Twang once when the line first scrolls into view.
let observer: IntersectionObserver | null = null;
if (playOnView && !still() && typeof IntersectionObserver === "function") {
observer = new IntersectionObserver(([entry]) => {
if (!entry?.isIntersecting) return;
observer?.disconnect();
speed = reach() * 0.5;
wake();
});
observer.observe(root);
}
return () => {
root.removeEventListener("pointermove", move);
root.removeEventListener("pointerleave", leave);
observer?.disconnect();
cancelAnimationFrame(frame);
};
}
</script>
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
const base = "relative block";
const orientations: Record<ElasticLineOrientation, string> = {
horizontal: "h-[calc(var(--reach)*2)]",
vertical: "w-[calc(var(--reach)*2)] self-stretch",
};
const colors = {
line: "text-line",
muted: "text-muted",
ink: "text-ink",
primary: "text-primary",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const svgClass =
"pointer-events-none absolute inset-0 size-full overflow-visible";
const pathClass =
"fill-none stroke-current [vector-effect:non-scaling-stroke]";
type Props = HTMLAttributes<HTMLDivElement> & {
/** How the line answers the pointer. */
variant?: ElasticLineVariant;
/** Direction of the line. */
orientation?: ElasticLineOrientation;
/** Px on each side of the line where the pointer bends it, and the most it can bend. */
reach?: number;
/** Line color token. */
color?: keyof typeof colors;
/** Line width in px. */
strokeWidth?: number;
/** Twangs once when the line first scrolls into view. */
playOnView?: boolean;
/** Hides the line from assistive tech instead of announcing a separator. */
decorative?: boolean;
};
let {
variant = "pull",
orientation = "horizontal",
reach = 24,
color = "line",
strokeWidth = 1.5,
playOnView = false,
decorative = false,
class: className,
...rest
}: Props = $props();
const vertical = $derived(orientation === "vertical");
let rootEl = $state<HTMLDivElement>();
let pathEl = $state<SVGPathElement>();
$effect(() =>
rootEl && pathEl
? createLine(rootEl, pathEl, vertical, variant, playOnView)
: undefined,
);
</script>
<div
role={decorative ? undefined : "separator"}
aria-orientation={decorative ? undefined : orientation}
aria-hidden={decorative ? "true" : undefined}
{...rest}
bind:this={rootEl}
class={[base, orientations[orientation], colors[color], className]}
style:--reach={`${reach}px`}
>
<svg
aria-hidden="true"
viewBox="0 0 100 100"
preserveAspectRatio="none"
class={svgClass}
>
<path
bind:this={pathEl}
d={curve(vertical)}
stroke-width={strokeWidth}
stroke-linecap="round"
class={pathClass}
/>
</svg>
</div>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/ElasticLine.astro.
---
import type { HTMLAttributes } from "astro/types";
export type ElasticLineVariant = "pull" | "push" | "pluck";
export type ElasticLineOrientation = "horizontal" | "vertical";
const base = "relative block";
const orientations: Record<ElasticLineOrientation, string> = {
horizontal: "h-[calc(var(--reach)*2)]",
vertical: "w-[calc(var(--reach)*2)] self-stretch",
};
const colors = {
line: "text-line",
muted: "text-muted",
ink: "text-ink",
primary: "text-primary",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const svgClass =
"pointer-events-none absolute inset-0 size-full overflow-visible";
const pathClass = "fill-none stroke-current [vector-effect:non-scaling-stroke]";
/** Quadratic curve in a 0 to 100 box. The control sits at twice the bend so the line peaks at the bend. */
const curve = (vertical: boolean) => (vertical ? "M50 0Q50 50 50 100" : "M0 50Q50 50 100 50");
type Props = HTMLAttributes<"div"> & {
/** How the line answers the pointer. */
variant?: ElasticLineVariant;
/** Direction of the line. */
orientation?: ElasticLineOrientation;
/** Px on each side of the line where the pointer bends it, and the most it can bend. */
reach?: number;
/** Line color token. */
color?: keyof typeof colors;
/** Line width in px. */
strokeWidth?: number;
/** Twangs once when the line first scrolls into view. */
playOnView?: boolean;
/** Hides the line from assistive tech instead of announcing a separator. */
decorative?: boolean;
};
const {
variant = "pull",
orientation = "horizontal",
reach = 24,
color = "line",
strokeWidth = 1.5,
playOnView = false,
decorative = false,
class: className,
style,
...rest
} = Astro.props;
---
<markas-elastic-line
class="contents"
data-variant={variant}
data-orientation={orientation}
data-play-on-view={playOnView ? "" : undefined}
>
<div
role={decorative ? undefined : "separator"}
aria-orientation={decorative ? undefined : orientation}
aria-hidden={decorative ? "true" : undefined}
{...rest}
class:list={[base, orientations[orientation], colors[color], className]}
style={`--reach: ${reach}px;${typeof style === "string" ? ` ${style}` : ""}`}
>
<svg
aria-hidden="true"
viewBox="0 0 100 100"
preserveAspectRatio="none"
class={svgClass}
>
<path
d={curve(orientation === "vertical")}
stroke-width={strokeWidth}
stroke-linecap="round"
class={pathClass}
></path>
</svg>
</div>
</markas-elastic-line>
<script>
type ElasticLineVariant = "pull" | "push" | "pluck";
type ElasticLineOrientation = "horizontal" | "vertical";
/** Spring per variant: k pulls toward the target, d keeps that share of the speed each frame. */
const SPRINGS = {
pull: { k: 0.12, d: 0.82 },
push: { k: 0.1, d: 0.8 },
pluck: { k: 0.3, d: 0.6 },
release: { k: 0.18, d: 0.93 },
};
const REST = 0.05;
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
/** Quadratic curve in a 0 to 100 box. The control sits at twice the bend so the line peaks at the bend. */
const curve = (vertical: boolean, along = 50, bend = 0) =>
vertical
? `M50 0Q${50 + 2 * bend} ${along} 50 100`
: `M0 50Q${along} ${50 + 2 * bend} 100 50`;
/**
* Bend the line toward (pull), away from (push), or with the pointer until it slips (pluck), then spring
* back. requestAnimationFrame only runs while the pointer is near or the line still moves.
*/
function createLine(
root: HTMLElement,
path: SVGPathElement,
vertical: boolean,
variant: ElasticLineVariant,
playOnView: boolean,
) {
let pointer: { along: number; perp: number } | null = null;
let along = 50;
let bend = 0;
let speed = 0;
let grabbed = false;
let frame = 0;
const reach = () => {
const rect = root.getBoundingClientRect();
return (vertical ? rect.width : rect.height) / 2 || 1;
};
const step = () => {
const half = reach();
let target = 0;
let spring = SPRINGS.release;
if (pointer) {
along = Math.min(Math.max(pointer.along, 10), 90);
const perp = pointer.perp;
if (variant === "pull") target = perp;
if (variant === "push")
target = -Math.sign(perp || 1) * (half - Math.abs(perp)) * 0.6;
if (variant === "pluck") {
if (Math.abs(perp) > half * 0.8) grabbed = false;
if (grabbed) target = perp;
}
if (variant !== "pluck") spring = SPRINGS[variant];
else if (grabbed) spring = SPRINGS.pluck;
}
speed = (speed + (target - bend) * spring.k) * spring.d;
bend += speed;
const settled = !pointer && Math.abs(bend) < REST && Math.abs(speed) < REST;
if (settled) bend = speed = 0;
path.setAttribute("d", curve(vertical, along, (bend / half) * 50));
frame = settled ? 0 : requestAnimationFrame(step);
};
const wake = () => {
frame ||= requestAnimationFrame(step);
};
const move = (event: PointerEvent) => {
if (still()) return;
const rect = root.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const next = vertical
? { along: (y / rect.height) * 100, perp: x - rect.width / 2 }
: { along: (x / rect.width) * 100, perp: y - rect.height / 2 };
// Pluck grabs when the pointer touches or crosses the line, even between two frames.
const crossed = pointer && Math.sign(pointer.perp) !== Math.sign(next.perp);
if (Math.abs(next.perp) < 6 || crossed) grabbed = true;
pointer = next;
wake();
};
const leave = () => {
pointer = null;
grabbed = false;
wake();
};
root.addEventListener("pointermove", move);
root.addEventListener("pointerleave", leave);
// Twang once when the line first scrolls into view.
let observer: IntersectionObserver | null = null;
if (playOnView && !still() && typeof IntersectionObserver === "function") {
observer = new IntersectionObserver(([entry]) => {
if (!entry?.isIntersecting) return;
observer?.disconnect();
speed = reach() * 0.5;
wake();
});
observer.observe(root);
}
return () => {
root.removeEventListener("pointermove", move);
root.removeEventListener("pointerleave", leave);
observer?.disconnect();
cancelAnimationFrame(frame);
};
}
// Each line runs its own spring, so it is a custom element: it also works for markup added
// later and for pages reached through view transitions.
class MarkasElasticLine extends HTMLElement {
private stop?: () => void;
connectedCallback() {
const root = this.firstElementChild;
const path = this.querySelector("path");
if (this.stop || !(root instanceof HTMLElement) || !path) return;
this.stop = createLine(
root,
path,
this.dataset.orientation === "vertical",
(this.dataset.variant ?? "pull") as ElasticLineVariant,
this.dataset.playOnView !== undefined,
);
}
disconnectedCallback() {
this.stop?.();
this.stop = undefined;
}
}
if (!customElements.get("markas-elastic-line"))
customElements.define("markas-elastic-line", MarkasElasticLine);
</script>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/elastic-line.component.ts.
import {
afterRenderEffect,
booleanAttribute,
ChangeDetectionStrategy,
Component,
computed,
type ElementRef,
input,
numberAttribute,
viewChild,
} from "@angular/core";
export type ElasticLineVariant = "pull" | "push" | "pluck";
export type ElasticLineOrientation = "horizontal" | "vertical";
const base = "relative block";
const orientations: Record<ElasticLineOrientation, string> = {
horizontal: "h-[calc(var(--reach)*2)]",
vertical: "w-[calc(var(--reach)*2)] self-stretch",
};
const colors = {
line: "text-line",
muted: "text-muted",
ink: "text-ink",
primary: "text-primary",
success: "text-success",
warning: "text-warning",
danger: "text-danger",
};
const svgClass =
"pointer-events-none absolute inset-0 size-full overflow-visible";
const pathClass = "fill-none stroke-current [vector-effect:non-scaling-stroke]";
/** Spring per variant: k pulls toward the target, d keeps that share of the speed each frame. */
const SPRINGS = {
pull: { k: 0.12, d: 0.82 },
push: { k: 0.1, d: 0.8 },
pluck: { k: 0.3, d: 0.6 },
release: { k: 0.18, d: 0.93 },
};
const REST = 0.05;
const still = () =>
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
/** Quadratic curve in a 0 to 100 box. The control sits at twice the bend so the line peaks at the bend. */
export const curve = (vertical: boolean, along = 50, bend = 0) =>
vertical
? `M50 0Q${50 + 2 * bend} ${along} 50 100`
: `M0 50Q${along} ${50 + 2 * bend} 100 50`;
/**
* Bend the line toward (pull), away from (push), or with the pointer until it slips (pluck), then spring
* back. requestAnimationFrame only runs while the pointer is near or the line still moves.
*/
function createLine(
root: HTMLElement,
path: SVGPathElement,
vertical: boolean,
variant: ElasticLineVariant,
playOnView: boolean,
) {
let pointer: { along: number; perp: number } | null = null;
let along = 50;
let bend = 0;
let speed = 0;
let grabbed = false;
let frame = 0;
const reach = () => {
const rect = root.getBoundingClientRect();
return (vertical ? rect.width : rect.height) / 2 || 1;
};
const step = () => {
const half = reach();
let target = 0;
let spring = SPRINGS.release;
if (pointer) {
along = Math.min(Math.max(pointer.along, 10), 90);
const perp = pointer.perp;
if (variant === "pull") target = perp;
if (variant === "push")
target = -Math.sign(perp || 1) * (half - Math.abs(perp)) * 0.6;
if (variant === "pluck") {
if (Math.abs(perp) > half * 0.8) grabbed = false;
if (grabbed) target = perp;
}
if (variant !== "pluck") spring = SPRINGS[variant];
else if (grabbed) spring = SPRINGS.pluck;
}
speed = (speed + (target - bend) * spring.k) * spring.d;
bend += speed;
const settled = !pointer && Math.abs(bend) < REST && Math.abs(speed) < REST;
if (settled) bend = speed = 0;
path.setAttribute("d", curve(vertical, along, (bend / half) * 50));
frame = settled ? 0 : requestAnimationFrame(step);
};
const wake = () => {
frame ||= requestAnimationFrame(step);
};
const move = (event: PointerEvent) => {
if (still()) return;
const rect = root.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const next = vertical
? { along: (y / rect.height) * 100, perp: x - rect.width / 2 }
: { along: (x / rect.width) * 100, perp: y - rect.height / 2 };
// Pluck grabs when the pointer touches or crosses the line, even between two frames.
const crossed = pointer && Math.sign(pointer.perp) !== Math.sign(next.perp);
if (Math.abs(next.perp) < 6 || crossed) grabbed = true;
pointer = next;
wake();
};
const leave = () => {
pointer = null;
grabbed = false;
wake();
};
root.addEventListener("pointermove", move);
root.addEventListener("pointerleave", leave);
// Twang once when the line first scrolls into view.
let observer: IntersectionObserver | null = null;
if (playOnView && !still() && typeof IntersectionObserver === "function") {
observer = new IntersectionObserver(([entry]) => {
if (!entry?.isIntersecting) return;
observer?.disconnect();
speed = reach() * 0.5;
wake();
});
observer.observe(root);
}
return () => {
root.removeEventListener("pointermove", move);
root.removeEventListener("pointerleave", leave);
observer?.disconnect();
cancelAnimationFrame(frame);
};
}
/** Host stays out of layout; class moves to the line. */
@Component({
selector: "markas-elastic-line",
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: "contents" },
template: `
<div
#lineEl
[attr.role]="decorative() ? null : 'separator'"
[attr.aria-orientation]="decorative() ? null : orientation()"
[attr.aria-hidden]="decorative() ? 'true' : null"
[class]="rootClasses()"
[style.--reach]="reach() + 'px'"
>
<svg
aria-hidden="true"
viewBox="0 0 100 100"
preserveAspectRatio="none"
[class]="svgClass"
>
<path
#pathEl
[attr.d]="straight()"
[attr.stroke-width]="strokeWidth()"
stroke-linecap="round"
[class]="pathClass"
/>
</svg>
</div>
`,
})
export class ElasticLine {
/** How the line answers the pointer. */
readonly variant = input<ElasticLineVariant>("pull");
/** Direction of the line. */
readonly orientation = input<ElasticLineOrientation>("horizontal");
/** Px on each side of the line where the pointer bends it, and the most it can bend. */
readonly reach = input(24, { transform: numberAttribute });
/** Line color token. */
readonly color = input<keyof typeof colors>("line");
/** Line width in px. */
readonly strokeWidth = input(1.5, { transform: numberAttribute });
/** Twangs once when the line first scrolls into view. */
readonly playOnView = input(false, { transform: booleanAttribute });
/** Hides the line from assistive tech instead of announcing a separator. */
readonly decorative = input(false, { transform: booleanAttribute });
readonly userClass = input("", { alias: "class" });
protected readonly svgClass = svgClass;
protected readonly pathClass = pathClass;
private readonly vertical = computed(() => this.orientation() === "vertical");
protected readonly straight = computed(() => curve(this.vertical()));
protected readonly rootClasses = computed(() =>
[
base,
orientations[this.orientation()],
colors[this.color()],
this.userClass(),
]
.filter(Boolean)
.join(" "),
);
private readonly lineEl =
viewChild.required<ElementRef<HTMLDivElement>>("lineEl");
private readonly pathEl =
viewChild.required<ElementRef<SVGPathElement>>("pathEl");
constructor() {
afterRenderEffect((onCleanup) => {
const stop = createLine(
this.lineEl().nativeElement,
this.pathEl().nativeElement,
this.vertical(),
this.variant(),
this.playOnView(),
);
onCleanup(stop);
});
}
}Usage
<h2 class="text-3xl font-semibold">Our services</h2>
<x-markas.elastic-line variant="pluck" color="primary" :stroke-width="3" :reach="16" play-on-view decorative class="w-40" />
<x-markas.elastic-line variant="push" :reach="32" />Needs Alpine.js.
import { ElasticLine } from "@/components/markas/ElasticLine";
<h2 className="text-3xl font-semibold">Our services</h2>
<ElasticLine
variant="pluck"
color="primary"
strokeWidth={3}
reach={16}
playOnView
decorative
className="w-40"
/>
<ElasticLine variant="push" reach={32} /><template>
<h2 class="text-3xl font-semibold">Our services</h2>
<ElasticLine
variant="pluck"
color="primary"
:stroke-width="3"
:reach="16"
play-on-view
decorative
class="w-40"
/>
<ElasticLine variant="push" :reach="32" />
</template><script lang="ts">
import ElasticLine from "$lib/components/markas/ElasticLine.svelte";
</script>
<h2 class="text-3xl font-semibold">Our services</h2>
<ElasticLine
variant="pluck"
color="primary"
strokeWidth={3}
reach={16}
playOnView
decorative
class="w-40"
/>---
import ElasticLine from "@/components/markas/ElasticLine.astro";
---
<h2 class="text-3xl font-semibold">Our services</h2>
<ElasticLine
variant="pluck"
color="primary"
strokeWidth={3}
reach={16}
playOnView
decorative
class="w-40"
/>Each line is a small custom element that runs its own spring, also after view transitions.
import { Component } from "@angular/core";
import { ElasticLine } from "./markas/elastic-line.component";
@Component({
selector: "app-services-heading",
imports: [ElasticLine],
template: `
<h2 class="text-3xl font-semibold">Our services</h2>
<markas-elastic-line
variant="pluck"
color="primary"
[strokeWidth]="3"
[reach]="16"
playOnView
decorative
class="w-40"
/>
`,
})
export class ServicesHeading {}- The component is
reachx 2 tall (or wide when vertical) and the line runs through its middle. The pointer bends it only inside that band. pullbends toward the pointer,pushaway from it, andpluckfollows the pointer once touched until it slips free and vibrates.- The curve is one quadratic SVG path. requestAnimationFrame only runs while the pointer is close or the line still moves.
playOnViewtwangs it once when it first scrolls into view. - By default it is a
separator. Usedecorativefor underlines. With reduced motion the line stays straight. Attributes andclassgo to the wrapper.
Props
| Name | Type | Default | Description |
|---|---|---|---|
variant | "pull" | "push" | "pluck" | "pull" | pull: the line bends toward the pointer. push: it bends away like a soft wall. pluck: it follows the pointer once touched, slips free, and vibrates. |
orientation | "horizontal" | "vertical" | "horizontal" | Direction of the line. A vertical line stretches to the height of its flex row. |
reach | number | 24 | Px on each side of the line where the pointer bends it. Also the most it can bend. The component is twice this tall (or wide). |
color | "line" | "muted" | "ink" | "primary" | "success" | "warning" | "danger" | "line" | Line color token. |
strokeWidth | number | 1.5 | Line width in px. It stays the same however wide the line is. |
playOnView | boolean | false | Twangs once when the line first scrolls into view. |
decorative | boolean | false | Hides the line from assistive tech, for underlines and ornaments. Otherwise it is announced as a separator. |
Accessibility
- By default the line has role="separator" with aria-orientation; use decorative for underlines so it is hidden instead.
- The bend is drawn by changing one SVG path; requestAnimationFrame only runs while the pointer is close or the line still moves.
- With reduced motion the line stays straight and never twangs.
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.