@auto-skeleton/react 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +201 -0
  2. package/package.json +5 -3
package/README.md ADDED
@@ -0,0 +1,201 @@
1
+ # auto-skeleton
2
+
3
+ [![npm](https://img.shields.io/npm/v/@auto-skeleton/react?label=npm&color=cb3837)](https://www.npmjs.com/package/@auto-skeleton/react)
4
+ [![downloads](https://img.shields.io/npm/dm/@auto-skeleton/react?color=blue)](https://www.npmjs.com/package/@auto-skeleton/react)
5
+ [![stars](https://img.shields.io/github/stars/riazzahmedm/react-auto-skeleton?style=flat&color=yellow)](https://github.com/riazzahmedm/react-auto-skeleton/stargazers)
6
+ [![issues](https://img.shields.io/github/issues/riazzahmedm/react-auto-skeleton)](https://github.com/riazzahmedm/react-auto-skeleton/issues)
7
+ [![license](https://img.shields.io/github/license/riazzahmedm/react-auto-skeleton)](https://github.com/riazzahmedm/react-auto-skeleton/blob/main/LICENSE)
8
+
9
+ Zero-config skeleton loaders for React. Wraps any component and auto-generates a pixel-accurate skeleton by scanning the real DOM — no manual shape definitions needed.
10
+
11
+ **[Live demo →](https://riazzahmedm.github.io/react-auto-skeleton/)**
12
+
13
+ ```tsx
14
+ <AutoSkeleton id="profile" loading={isLoading}>
15
+ <ProfileCard />
16
+ </AutoSkeleton>
17
+ ```
18
+
19
+ When `loading` is true, the real UI is replaced with a skeleton that mirrors its exact layout.
20
+
21
+ ---
22
+
23
+ ## Packages
24
+
25
+ | Package | Description |
26
+ |---|---|
27
+ | [`@auto-skeleton/react`](https://www.npmjs.com/package/@auto-skeleton/react) | React component and hook |
28
+ | [`@auto-skeleton/core`](https://www.npmjs.com/package/@auto-skeleton/core) | Framework-agnostic DOM scanner |
29
+
30
+ ---
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ npm install @auto-skeleton/react
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Quick start
41
+
42
+ ```tsx
43
+ import { AutoSkeleton } from "@auto-skeleton/react";
44
+ import "@auto-skeleton/react/styles.css";
45
+
46
+ function UserProfile({ userId }: { userId: string }) {
47
+ const { data, isLoading } = useUser(userId);
48
+
49
+ return (
50
+ <AutoSkeleton id="user-profile" loading={isLoading}>
51
+ <div className="profile">
52
+ <img src={data?.avatar} alt="avatar" />
53
+ <h2>{data?.name}</h2>
54
+ <p>{data?.bio}</p>
55
+ </div>
56
+ </AutoSkeleton>
57
+ );
58
+ }
59
+ ```
60
+
61
+ On first load, `auto-skeleton` scans the rendered DOM, extracts bone positions, and caches them. Every subsequent load shows the skeleton immediately — no layout shift.
62
+
63
+ ---
64
+
65
+ ## How it works
66
+
67
+ 1. On the first non-loading render, the DOM inside `<AutoSkeleton>` is scanned using a `TreeWalker`
68
+ 2. Each visible element is measured with `getBoundingClientRect` and classified as a rect, circle, or text block
69
+ 3. Bone positions are stored in memory and `sessionStorage` keyed by `id` + viewport width
70
+ 4. When `loading` switches back to `true`, an absolutely-positioned overlay renders the cached bones
71
+ 5. The real content is hidden (`visibility: hidden`) so the layout is preserved during loading
72
+
73
+ ---
74
+
75
+ ## Props
76
+
77
+ ```tsx
78
+ <AutoSkeleton
79
+ id="unique-id" // required — used as the cache key
80
+ loading={boolean} // required — controls when the skeleton shows
81
+ className="..." // optional — added to the root wrapper div
82
+ options={...} // optional — see options table below
83
+ >
84
+ {children}
85
+ </AutoSkeleton>
86
+ ```
87
+
88
+ ### Options
89
+
90
+ | Option | Type | Default | Description |
91
+ |---|---|---|---|
92
+ | `animation` | `"wave" \| "pulse" \| "none"` | `"wave"` | Skeleton animation style |
93
+ | `debug` | `boolean` | `false` | Outline detected bones with dashed borders |
94
+ | `watch` | `boolean` | `true` | Re-scan when layout changes while not loading |
95
+ | `watchDebounceMs` | `number` | `120` | Debounce delay for watcher-triggered re-scans |
96
+ | `cache` | `boolean` | `true` | Cache bones in memory and `sessionStorage` |
97
+ | `minSize` | `number` | `8` | Minimum element size in px to generate a bone for |
98
+ | `ignoreSelectors` | `string[]` | `[]` | CSS selectors for elements to skip during scan |
99
+
100
+ ---
101
+
102
+ ## Data attribute overrides
103
+
104
+ Fine-tune how individual elements are scanned without changing render logic:
105
+
106
+ | Attribute | Effect |
107
+ |---|---|
108
+ | `data-skeleton-ignore` | Skip this element entirely |
109
+ | `data-skeleton-shape="circle"` | Force a circular bone |
110
+ | `data-skeleton-shape="rect"` | Force a rectangular bone |
111
+ | `data-skeleton-lines="N"` | Force N text lines instead of auto-detecting |
112
+ | `data-skeleton-container` | Treat as a container — scan children instead of creating one large bone |
113
+
114
+ ```tsx
115
+ <AutoSkeleton id="profile" loading={loading}>
116
+ <article data-skeleton-container>
117
+ <img src={avatar} data-skeleton-shape="circle" />
118
+ <h2 data-skeleton-lines="1">{name}</h2>
119
+ <p data-skeleton-lines="3">{bio}</p>
120
+ <span data-skeleton-ignore>Live</span>
121
+ </article>
122
+ </AutoSkeleton>
123
+ ```
124
+
125
+ ---
126
+
127
+ ## Theming
128
+
129
+ Override CSS variables to match your design system:
130
+
131
+ ```css
132
+ :root {
133
+ --as-base: #e4e4e7; /* bone background */
134
+ --as-highlight: rgba(255, 255, 255, 0.9); /* wave shimmer */
135
+ }
136
+ ```
137
+
138
+ ---
139
+
140
+ ## Accessibility
141
+
142
+ - The skeleton overlay is `aria-hidden="true"` — invisible to screen readers
143
+ - Animations are automatically disabled when `prefers-reduced-motion: reduce` is set
144
+
145
+ ---
146
+
147
+ ## Debug mode
148
+
149
+ Set `options.debug = true` to visualize detected bones with dashed red outlines while tuning your layout:
150
+
151
+ ```tsx
152
+ <AutoSkeleton id="card" loading={loading} options={{ debug: true }}>
153
+ <Card />
154
+ </AutoSkeleton>
155
+ ```
156
+
157
+ ---
158
+
159
+ ## Using the core scanner directly
160
+
161
+ For non-React environments, `@auto-skeleton/core` exposes the scanner:
162
+
163
+ ```ts
164
+ import { scanBones } from "@auto-skeleton/core";
165
+
166
+ const bones = scanBones(document.getElementById("root"), {
167
+ minSize: 8,
168
+ ignoreSelectors: [".no-skeleton"]
169
+ });
170
+ // bones: Array<{ x, y, width, height, radius, kind }>
171
+ ```
172
+
173
+ ---
174
+
175
+ ## Browser support
176
+
177
+ Latest 2 versions of Chrome, Edge, Firefox, and Safari (macOS + iOS).
178
+
179
+ Requires `MutationObserver`, `ResizeObserver`, and `sessionStorage`. Falls back to `window resize` events if `ResizeObserver` is unavailable.
180
+
181
+ ---
182
+
183
+ ## Contributing
184
+
185
+ ```bash
186
+ git clone https://github.com/riazzahmedm/react-auto-skeleton
187
+ cd react-auto-skeleton
188
+ npm install
189
+ npm run demo:dev # start the demo
190
+ npm test # run tests
191
+ npm run build # build all packages
192
+ npm run perf:scan # run performance benchmark (budget: <80ms avg)
193
+ ```
194
+
195
+ To release:
196
+
197
+ ```bash
198
+ npm run changeset # describe your changes
199
+ npm run version-packages # bump versions + generate changelogs
200
+ npm run release # publish to npm
201
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auto-skeleton/react",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,8 +12,10 @@
12
12
  },
13
13
  "./styles.css": "./dist/styles.css"
14
14
  },
15
+ "license": "MIT",
15
16
  "files": [
16
- "dist"
17
+ "dist",
18
+ "README.md"
17
19
  ],
18
20
  "sideEffects": [
19
21
  "**/*.css"
@@ -27,6 +29,6 @@
27
29
  "react-dom": ">=18"
28
30
  },
29
31
  "dependencies": {
30
- "@auto-skeleton/core": "0.0.2"
32
+ "@auto-skeleton/core": "0.0.4"
31
33
  }
32
34
  }