Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

phantom-ui

> 前端框架
Open source

Structure-aware skeleton loader. One Web Component, every framework.

767 stars0 likes1 views
WebsiteGitHub

About

Structure-aware skeleton loader. One Web Component, every framework.

Structure-aware skeleton loader. One Web Component. Every framework.

Documentation · Live Demo


Stop building skeleton screens by hand. Wrap your real UI in `` and it generates shimmer placeholders automatically by measuring your actual DOM at runtime.

No separate skeleton components to maintain. No copy-pasting layouts. The real component is the skeleton template.

Why

Traditional skeleton loaders require you to build and maintain a second version of every component, just for the loading state. When the real component changes, the skeleton drifts out of sync.

phantom-ui takes a different approach. It renders your real component with invisible text, measures the position and size of every leaf element (getBoundingClientRect), and overlays animated shimmer blocks at the exact same coordinates. Container backgrounds and borders stay visible, giving a natural card outline while loading.

Because it is a standard Web Component (built with Lit), it works in React, Vue, Svelte, Angular, Solid, Qwik, HTMX, or plain HTML. No framework adapters needed.

Install

bash
bun add @aejkatappaja/phantom-ui     # bun
npm install @aejkatappaja/phantom-ui # npm
pnpm add @aejkatappaja/phantom-ui    # pnpm
yarn add @aejkatappaja/phantom-ui    # yarn

Or drop in a script tag with no build step:

xml

Vendoring a single file

If you cannot install from a registry, or you would rather keep a copy in your repo, there is a standalone ES module with Lit bundled in. One file, 34 kB minified, 11.5 kB gzipped, no runtime dependency:

typescript
import "@aejkatappaja/phantom-ui/standalone";

Or, if you cannot reach a registry at all, copy two files into your project and import by path:

phantom-ui.standalone.js      # the component, unminified so a review can read it
phantom-ui.standalone.min.js  # the same code, minified
phantom-ui.standalone.d.ts    # its types, no imports of any kind

Take the first and the third. TypeScript pairs a declaration to a module by exact filename, so those two names go together and the types apply with nothing to configure.

typescript
import "./phantom-ui.standalone.js";
import type { PhantomUi } from "./phantom-ui.standalone.js";

That is the whole install. The element registers itself on import, and the declarations reference nothing external, so a project with no node_modules at all still type-checks under strict with skipLibCheck: false.

The declared class extends HTMLElement rather than LitElement, which is a narrower view of the same object, so updateComplete is declared explicitly and the rest of the public API is unchanged.

Those are the release assets, which is the channel for people who cannot reach a registry at all. Inside the npm package the same builds are phantom-ui.standalone.js and phantom-ui.standalone.dev.js, resolved through the exports map rather than by filename. Either build is the same code, and both are bundled output rather than the original TypeScript: the sources import Lit, so they cannot be compiled on their own.

The library is MIT, so vendoring is fine. Note the version you copied somewhere near the file, since a vendored copy does not get updates.

Optional setup

The component works with zero setup. For an extra convenience pass, run the bundled init command once from your project root:

bash
npx @aejkatappaja/phantom-ui init    # npm
bunx @aejkatappaja/phantom-ui init   # bun
pnpx @aejkatappaja/phantom-ui init   # pnpm
yarn dlx @aejkatappaja/phantom-ui init  # yarn

It detects your project setup and handles two things:

JSX type declarations: For React, Solid, and Qwik, it generates a phantom-ui.d.ts in your src/ directory so `` is recognized in JSX. Vue, Svelte, and Angular work out of the box without any type declaration.

SSR pre-hydration CSS: For Next.js, Nuxt, SvelteKit, Remix, and Qwik, it adds import "@aejkatappaja/phantom-ui/ssr.css" to your layout file to prevent content flash before hydration (see Pre-hydration CSS).

Nothing runs on install: the library deliberately has no postinstall hook, so your source is never modified unless you ask for it. Prefer not to run the command at all? Both steps are tiny and documented below for manual setup.

Manual JSX type declarations

React / Next.js / Remix

typescript
import type { PhantomUiAttributes } from "@aejkatappaja/phantom-ui";

declare module "react/jsx-runtime" {
  export namespace JSX {
    interface IntrinsicElements {
      "phantom-ui": PhantomUiAttributes;
    }
  }
}

Solid

typescript
import type { SolidPhantomUiAttributes } from "@aejkatappaja/phantom-ui";

declare module "solid-js" {
  namespace JSX {
    interface IntrinsicElements {
      "phantom-ui": SolidPhantomUiAttributes;
    }
  }
}

Qwik

typescript
import type { PhantomUiAttributes } from "@aejkatappaja/phantom-ui";

declare module "@builder.io/qwik" {
  namespace QwikJSX {
    interface IntrinsicElements {
      "phantom-ui": PhantomUiAttributes & Record;
    }
  }
}

Manual SSR CSS import

Add this import to your root layout file:

javascript
import "@aejkatappaja/phantom-ui/ssr.css";
Framework Layout file
Next.js (App Router) app/layout.tsx
Next.js (Pages) pages/_app.tsx
Nuxt app.vue
SvelteKit src/routes/+layout.svelte
Remix app/root.tsx
Qwik src/root.tsx

Quick start

xml

  

Set loading to show the shimmer. Remove it to reveal the real content. All child elements (including deeply nested images and media) are automatically hidden during loading.

Data fetching

phantom-ui works with any data fetching approach. The pattern: render placeholder content while loading, real content when done. The placeholder text is invisible (CSS transparent) and only used to generate the skeleton shape.

TanStack Query

typescript
import { useQuery } from "@tanstack/react-query";
import "@aejkatappaja/phantom-ui";

function UserProfile({ userId }: { userId: string }) {
  const { data: user, isLoading } = useQuery({
    queryKey: ["user", userId],
    queryFn: () => fetch(`/api/users/${userId}`).then((r) => r.json()),
  });

  return (
    
      

    
  );
}

While isLoading is true, the placeholder text ("Placeholder Name", "A short bio goes here.") is rendered invisibly and phantom-ui generates shimmer blocks matching their exact position and size. When the query resolves, loading is removed and the real content appears.

SWR

typescript
import useSWR from "swr";
import "@aejkatappaja/phantom-ui";

function UserProfile({ userId }: { userId: string }) {
  const { data: user, isLoading } = useSWR(`/api/users/${userId}`);

  return (
    
      

    
  );
}

Lists

For dynamic lists where the data hasn't loaded yet, use count to repeat a single template row:

typescript
const { data: users, isLoading } = useQuery({
  queryKey: ["users"],
  queryFn: () => fetch("/api/users").then((r) => r.json()),
});

return (
  
    {isLoading ? (
      

    ) : (
      users?.map((u) => (
        

      ))
    )}
  
);

Framework examples

Safe to import multiple times. The custom element registration is guarded against duplicate customElements.define() calls, so phantom-ui works reliably in micro-frontends, lazy-loaded modules, dynamic imports, and HMR / hot reload environments where the package can end up being initialized more than once.

React

typescript
import "@aejkatappaja/phantom-ui";

function ProfileCard({ user, isLoading }: Props) {
  return (
    
      

    
  );
}

// List with repeat mode
function UserList({ users, isLoading }: Props) {
  return (
    
      

    
  );
}

Vue

xml

  
    

  

Svelte

svelte

  

Angular

typescript
import { Component, signal, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import "@aejkatappaja/phantom-ui";

@Component({
  selector: "app-profile",
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    
      

    
  `,
})
export class ProfileComponent {
  loading = signal(true);
}

Solid

typescript
import { createSignal } from "solid-js";
import "@aejkatappaja/phantom-ui";

function ProfileCard() {
  const [loading, setLoading] = createSignal(true);

  return (
    
      

    
  );
}

SSR frameworks (Next.js, Nuxt, SvelteKit, Remix, Qwik)

The component needs browser APIs to measure the DOM. Import it client-side only:

typescript
// Next.js
"use client";
import { useEffect } from "react";

export default function Page() {
  useEffect(() => { import("@aejkatappaja/phantom-ui"); }, []);
  return ...;
}
xml

  
    ...
  
svelte
typescript
// Qwik
import { component$, useVisibleTask$ } from "@builder.io/qwik";

export default component$(() => {
  // eslint-disable-next-line qwik/no-use-visible-task
  useVisibleTask$(async () => {
    import("@aejkatappaja/phantom-ui");
  });

  return ...;
});

The `` tag can exist in server-rendered HTML. The browser treats it as an unknown element until hydration, then the Web Component activates and measures the DOM. Content renders normally on the server, which is good for SEO.

Pre-hydration CSS

Before JavaScript loads, content inside `` can briefly flash as visible text. The package ships a small CSS file that hides this content immediately, with no JS needed:

css
import "@aejkatappaja/phantom-ui/ssr.css";

Running npx @aejkatappaja/phantom-ui init detects SSR frameworks and adds this import to your layout file (e.g. app/layout.tsx for Next.js, app.vue for Nuxt, +layout.svelte for SvelteKit). Or add the line yourself. If you use the CDN build, add the rules directly in your ``:

xml

Attributes

Attribute Type Default Description
loading boolean false Show shimmer overlay or real content
animation string shimmer Animation mode: shimmer, pulse, breathe, or solid
mode string skeleton skeleton (hide content, show blocks) or overlay (keep content dimmed, sweep light over it for refresh)
shimmer-direction string ltr Direction of the shimmer sweep: ltr, rtl, ttb, or btt (shimmer mode only)
shimmer-color string rgba(128,128,128,0.3) Color of the animated gradient sweep (shimmer mode only)
background-color string rgba(128,128,128,0.2) Background of each shimmer block (all modes)
duration number 1.5 Animation cycle in seconds
stagger number 0 Delay in seconds between each block's animation start
reveal number 0 Fade-out duration in seconds when loading ends
count number 1 Number of skeleton rows to repeat from a single template
count-gap number 0 Gap in pixels between repeated rows
fallback-radius number 4 Border radius (px) for flat elements like text
debug boolean false Outline each measured block with an index for inspection
loading-label string Loading Accessible label announced by screen readers while loading (set as aria-label)
pierce-shadow boolean false Measure inside open shadow roots of slotted components (Stencil, Lit design systems)

Using a Web Component design system? See the Shadow DOM guide for how pierce-shadow measures inside your components.

Refresh mode (mode="overlay")

The default skeleton mode is for the first load: it hides the content and shows placeholder blocks. For a refresh / stale-while-revalidate state, where you already have a result and are refetching, use mode="overlay":

xml

  

The existing content stays visible and dimmed while a light glint sweeps over each element (structure-aware, just like the skeleton). It is not clickable during the refresh

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptangularcustom-elementhtmxlit

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架