Overview
Components
Text Animations
A 3D book component with hover animation and customizable appearance.
Perspective Interfaces
A layered cover that turns any slot content into a dramatic book-style reveal.
Spell Collection
Svelte Animationspreview.svelte
<script lang="ts"> import { PerspectiveBook } from "$lib/components/spell/perspective-book/index.js"; import Code2Icon from "@lucide/svelte/icons/code-2";</script>
<div class="py-10"> <PerspectiveBook size="lg" textured class="bg-[#5f4638] text-stone-100"> <div class="flex h-full flex-col justify-between"> <div class="space-y-4"> <div class="flex items-start justify-between gap-4"> <h2 class="max-w-[12ch] text-lg leading-5 font-semibold sm:text-xl"> Perspective Interfaces </h2> <Code2Icon class="mt-0.5 size-6 shrink-0" /> </div>
<p class="max-w-[18ch] text-xs/relaxed font-medium text-stone-200/80 sm:text-sm/relaxed" > A layered cover that turns any slot content into a dramatic book-style reveal. </p> </div>
<div class="space-y-1"> <p class="text-[0.65rem] font-semibold tracking-[0.28em] text-stone-200/70 uppercase" > Spell Collection </p> <span class="font-serif text-base font-medium sm:text-lg">Svelte Animations</span> </div> </div> </PerspectiveBook></div>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/s/perspective-book.json
Copy the Source Code
Copy and paste the following code into your project:
perspective-book.svelte
<script lang="ts"> import { asset } from "$app/paths"; import { cn } from "#lib/utils.js"; import type { Snippet } from "svelte"; import type { ClassValue, HTMLAttributes } from "svelte/elements";
type BookSize = "sm" | "default" | "lg";
interface SizeConfig { width: string; spineTranslation: string; }
let sizeMap: Record<BookSize, SizeConfig> = { sm: { width: "150px", spineTranslation: "122px" }, default: { width: "196px", spineTranslation: "168px" }, lg: { width: "300px", spineTranslation: "272px" }, };
let borderRadius = "6px 4px 4px 6px"; let defaultColorClasses = 'bg-neutral-100 text-primary dark:bg-[#1f1f1f] dark:before:absolute dark:before:inset-0 dark:before:rounded-[inherit] dark:before:bg-gradient-to-b dark:before:from-[#ffffff1a] dark:before:to-transparent dark:before:content-[""]';
interface Props extends HTMLAttributes<HTMLDivElement> { children?: Snippet; size?: BookSize; class?: ClassValue; textured?: boolean; style?: string; }
let { children, size = "default", class: className, textured = false, style, ...props }: Props = $props();
// you need to download the texture image // place it inside /static folder let textureUrl = asset("perspective-book-textured.avif");</script>
<div class="group z-10 h-min w-min perspective-[900px]" {style} {...props}> <div class="relative aspect-49/60 transform-[rotateY(0deg)] transition-transform duration-300 ease-out transform-3d group-hover:-translate-x-1 group-hover:scale-[1.066] group-hover:transform-[rotateY(-20deg)]" style="width: {sizeMap[size].width}; border-radius: {borderRadius};" > <div class={cn( "absolute inset-y-0 left-0 flex size-full flex-col overflow-hidden p-[12%] after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:border after:border-solid after:border-[#00000014] after:shadow-[0_1.8px_3.6px_#0000000d,0_10.8px_21.6px_#00000014,inset_0_-.9px_#0000001a,inset_0_1.8px_1.8px_#ffffff1a,inset_3.6px_0_3.6px_#0000001a] after:content-['']", className || defaultColorClasses )} style="transform: translateZ(25px); border-radius:{borderRadius};" > <div class="absolute top-0 left-0 h-full opacity-40" style={`min-width: 8.2%; background: linear-gradient(90deg, hsla(0, 0%, 100%, 0), hsla(0, 0%, 100%, 0) 12%, hsla(0, 0%, 100%, .25) 29.25%, hsla(0, 0%, 100%, 0) 50.5%, hsla(0, 0%, 100%, 0) 75.25%, hsla(0, 0%, 100%, .25) 91%, hsla(0, 0%, 100%, 0)), linear-gradient(90deg, rgba(0, 0, 0, .03), rgba(0, 0, 0, .1) 12%, transparent 30%, rgba(0, 0, 0, .02) 50%, rgba(0, 0, 0, .2) 73.5%, rgba(0, 0, 0, .5) 75.25%, rgba(0, 0, 0, .15) 85.25%, transparent);`} ></div>
<div class="h-full pl-1"> {@render children?.()} </div>
{#if textured && textureUrl} <div class="pointer-events-none absolute inset-0 rotate-180 bg-cover bg-no-repeat opacity-50 mix-blend-hard-light brightness-110" style={`border-radius: ${borderRadius}; background-image: url(${textureUrl});`} ></div> {/if} </div>
<div class="absolute left-0 bg-[linear-gradient(90deg,#eaeaea_0%,#0000_80%),linear-gradient(#fff,#fafafa)]" style="top: 3px; bottom: 3px; width: 48px; transform: translateX({sizeMap[size] .spineTranslation}) rotateY(90deg);" ></div>
<div class={cn( "absolute inset-y-0 left-0 flex size-full flex-col justify-end overflow-hidden p-[12%]", className || defaultColorClasses )} style="transform: translateZ(-25px); border-radius: {borderRadius};" ></div> </div></div> index.ts
import PerspectiveBook from "./perspective-book.svelte";export { PerspectiveBook };Folder Structure
Folder Structure
src/└── lib/ └── components/ └── spell/ └── perspective-book/ ├── perspective-book.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/spell/perspective-book/llms.txt
Follow the guide's installation and usage instructions.Match the project's existing structure, imports, and styles.Keep changes scoped to the component and verify it works.Reply with a short bullet list of completed changes.Download textured cover image
Use this texture for the optional textured book finish and save it in your app's `static/` folder.
Usage
<script lang="ts"> import { PerspectiveBook } from "#lib/components/spell/perspective-book/index.js";</script>
<PerspectiveBook> <h2>Perspective Interfaces</h2></PerspectiveBook>Examples
Textured Preview
Zoom in to view the texture details.
Building Interfaces the Svelte Way
A compact tribute to compiler-driven UI design and the creator behind it.
Creator of Svelte
Rich Harrispreview.svelte
<script lang="ts"> import { PerspectiveBook } from "$lib/components/spell/perspective-book/index.js"; import { Label } from "$lib/components/ui/label/index.js"; import { Switch } from "$lib/components/ui/switch/index.js"; import Svelte from "$lib/components/icons/svelte.svelte";
let textured = $state(true);</script>
<div class="py-10"> <div class="border-input relative mb-10 flex w-full items-start gap-2 rounded-lg border p-4 shadow-xs" > <Switch bind:checked={textured} class="order-1 h-4 w-6" id="show-textured" /> <div class="grid grow gap-2"> <Label for="show-textured">Toggle Textured</Label> <p id="description" class="text-muted-foreground text-xs"> Zoom in to view the texture details. </p> </div> </div> <PerspectiveBook size="lg" {textured}> <div class="flex h-full flex-col justify-between"> <div class="flex flex-col gap-4"> <div class="flex items-start justify-between gap-4"> <h2 class="max-w-[12ch] text-lg leading-5 font-semibold sm:text-xl"> Building Interfaces the Svelte Way </h2> <!-- <Code2 class="mt-0.5 size-6 shrink-0" /> --> <Svelte class="size-14" /> </div>
<p class="text-muted-foreground/80 max-w-[18ch] text-xs/relaxed font-medium sm:text-sm/relaxed" > A compact tribute to compiler-driven UI design and the creator behind it. </p> </div>
<div class="space-y-1"> <p class="text-primary/50 text-[0.65rem] font-semibold tracking-[0.28em] uppercase"> Creator of Svelte </p> <span class="font-serif text-base font-medium sm:text-lg">Rich Harris</span> </div> </div> </PerspectiveBook></div>Props
| Name | Type | Default | Description |
|---|---|---|---|
size | "sm" | "default" | "lg" | "default" | |
textured | boolean | false | |
class | ClassValue | '' | |
style | string | | |