API Reference
React — @auto-skeleton/react
<AutoSkeleton>
The main component. Wraps any subtree and replaces it with a skeleton overlay when loading is true.
import { AutoSkeleton } from "@auto-skeleton/react";
<AutoSkeleton
id="unique-id"
loading={boolean}
className="..."
options={{ ... }}
>
{children}
</AutoSkeleton>Props
| Prop | Type | Required | Description |
|---|---|---|---|
id | string | ✅ | Unique cache key. Must be unique per instance on the page. |
loading | boolean | ✅ | When true, shows the skeleton overlay. |
className | string | CSS class added to the root wrapper <div>. | |
options | AutoSkeletonOptions | Fine-tune scan and animation behaviour. |
AutoSkeletonOptions
| Option | Type | Default | Description |
|---|---|---|---|
animation | "wave" | "pulse" | "none" | "wave" | Skeleton animation style. |
debug | boolean | false | Outline detected bones with dashed borders for debugging. |
watch | boolean | true | Re-scan when layout changes while not loading. |
watchDebounceMs | number | 120 | Debounce delay (ms) for watcher-triggered re-scans. |
cache | boolean | true | Cache bones in memory and sessionStorage. |
minSize | number | 8 | Minimum element dimension (px) to generate a bone for. |
ignoreSelectors | string[] | [] | CSS selectors for elements to skip during scan. |
Vue 3 — <AutoSkeleton>
The Vue 3 component. Works identically to the React version — wrap any template subtree, pass loading.
<script setup lang="ts">
import { AutoSkeleton } from "@auto-skeleton/vue";
import "@auto-skeleton/vue/styles.css";
</script>
<template>
<AutoSkeleton id="unique-id" :loading="loading" :options="{ animation: 'wave' }">
<slot />
</AutoSkeleton>
</template>Props
| Prop | Type | Required | Description |
|---|---|---|---|
id | string | ✅ | Unique cache key per instance. |
loading | boolean | ✅ | Shows skeleton overlay when true. |
options | AutoSkeletonOptions | Same options object as React — see below. |
Vue 3 — useAutoSkeleton
Low-level composable for custom overlay integrations.
import { useAutoSkeleton } from "@auto-skeleton/vue";
const { rootRef, bones, shouldShow, animation, debug } = useAutoSkeleton(
toRef(props, "id"),
toRef(props, "loading"),
toRef(props, "options")
);Parameters
| Parameter | Type | Description |
|---|---|---|
id | Ref<string> | Unique cache key. |
loading | Ref<boolean> | Controls when bones are active. |
options | Ref<AutoSkeletonOptions | undefined> | Optional configuration. |
Returns
| Property | Type | Description |
|---|---|---|
rootRef | Ref<HTMLElement | null> | Attach to your container element. |
bones | ComputedRef<Bone[] | null> | Detected bones, or null before first scan. |
shouldShow | ComputedRef<boolean> | true when loading and bones are ready. |
animation | ComputedRef<string> | Resolved animation ("wave" default). |
debug | ComputedRef<boolean> | Resolved debug flag. |
React — useAutoSkeleton
Low-level hook for custom integrations. Returns the scan state and a ref to attach to your container.
import { useAutoSkeleton } from "@auto-skeleton/react";
function MyComponent({ loading }: { loading: boolean }) {
const { ref, bones, isScanning } = useAutoSkeleton({
id: "my-component",
loading,
options: { animation: "pulse" },
});
return <div ref={ref}>{/* your content */}</div>;
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string | ✅ | Unique cache key. |
loading | boolean | ✅ | Controls when bones are active. |
options | AutoSkeletonOptions | Same options as <AutoSkeleton>. |
Returns
| Property | Type | Description |
|---|---|---|
ref | RefObject<HTMLDivElement> | Attach to the container element you want scanned. |
bones | Bone[] | Current array of detected bones. |
isScanning | boolean | true while a scan is in progress. |
Lit & Web Components — @auto-skeleton/lit
<auto-skeleton>
A native custom element. Works in any framework or vanilla JS. Registered automatically on import.
import '@auto-skeleton/lit';<auto-skeleton skeleton-id="profile" loading>
<user-profile></user-profile>
</auto-skeleton>Attributes & properties
| Name | Type | Required | Description |
|---|---|---|---|
skeleton-id | string (attribute) | ✅ | Unique cache key. Maps to the skeletonId JS property. |
loading | boolean (property) | ✅ | When true, shows the skeleton overlay. Presence of the attribute also sets true. |
options | AutoSkeletonOptions (property only) | Fine-tune scan and animation behaviour. Set via JS or Lit property binding. |
Use .options (property binding) rather than an attribute, as the options object cannot be serialised to a string attribute. In Lit: .options=${{ animation: "pulse" }}.
AutoSkeletonOptions
Same shape as the React package:
| Option | Type | Default | Description |
|---|---|---|---|
animation | "wave" | "pulse" | "none" | "wave" | Skeleton animation style. |
debug | boolean | false | Outline detected bones with dashed borders. |
watch | boolean | true | Re-scan when layout changes while not loading. |
watchDebounceMs | number | 120 | Debounce delay (ms) for watcher-triggered re-scans. |
cache | boolean | true | Cache bones in memory and sessionStorage. |
minSize | number | 8 | Minimum element dimension (px) to generate a bone. |
ignoreSelectors | string[] | [] | CSS selectors for elements to skip during scan. |
Cache utilities
import { clearCachedBones, clearAllCachedBones } from '@auto-skeleton/lit';
clearCachedBones('profile'); // clear one cache entry
clearAllCachedBones(); // clear all entriesCore — @auto-skeleton/core
Framework-agnostic scanner. Used internally by both packages. Import directly for custom integrations.
import { scanBones } from '@auto-skeleton/core';
const bones = scanBones(containerElement, {
minSize: 8,
ignoreSelectors: ['.ad'],
});scanBones(root, options?)
| Parameter | Type | Description |
|---|---|---|
root | HTMLElement | The element to scan. Children and shadow DOM are traversed recursively. |
options.minSize | number | Minimum bone dimension in px. Default 8. |
options.ignoreSelectors | string[] | Elements matching these selectors are skipped. |
Returns Bone[] — an array of { x, y, width, height, radius, kind } objects positioned relative to root.