skeleton-load 0.0.0-stage → 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +455 -2
- package/dist/cli.js +255 -0
- package/dist/index.cjs +1347 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1338 -0
- package/dist/index.js.map +1 -0
- package/dist/next/index.cjs +425 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +19 -0
- package/dist/next/index.d.ts +19 -0
- package/dist/next/index.js +420 -0
- package/dist/next/index.js.map +1 -0
- package/dist/plugins/vite.cjs +413 -0
- package/dist/plugins/vite.cjs.map +1 -0
- package/dist/plugins/vite.d.cts +40 -0
- package/dist/plugins/vite.d.ts +40 -0
- package/dist/plugins/vite.js +408 -0
- package/dist/plugins/vite.js.map +1 -0
- package/dist/plugins/webpack.cjs +411 -0
- package/dist/plugins/webpack.cjs.map +1 -0
- package/dist/plugins/webpack.d.cts +43 -0
- package/dist/plugins/webpack.d.ts +43 -0
- package/dist/plugins/webpack.js +406 -0
- package/dist/plugins/webpack.js.map +1 -0
- package/dist/react/index.cjs +1387 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +48 -0
- package/dist/react/index.d.ts +48 -0
- package/dist/react/index.js +1382 -0
- package/dist/react/index.js.map +1 -0
- package/dist/singleton-D0608W4u.d.cts +74 -0
- package/dist/singleton-D4bvf9fp.d.ts +74 -0
- package/dist/skeleton-load.auto.js +328 -0
- package/dist/skeleton-load.css +326 -0
- package/dist/skeleton-load.record.js +21 -0
- package/dist/types-DNYMIyOJ.d.cts +73 -0
- package/dist/types-DNYMIyOJ.d.ts +73 -0
- package/dist/vanilla.cjs +1356 -0
- package/dist/vanilla.cjs.map +1 -0
- package/dist/vanilla.d.cts +23 -0
- package/dist/vanilla.d.ts +23 -0
- package/dist/vanilla.js +1353 -0
- package/dist/vanilla.js.map +1 -0
- package/dist/vue/index.cjs +1379 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.cts +145 -0
- package/dist/vue/index.d.ts +145 -0
- package/dist/vue/index.js +1373 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +104 -4
|
@@ -0,0 +1,1387 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
// src/react/index.tsx
|
|
6
|
+
|
|
7
|
+
// src/core/config.ts
|
|
8
|
+
var PRESETS = ["shimmer", "pulse", "static"];
|
|
9
|
+
var SHAPES = [
|
|
10
|
+
"auto",
|
|
11
|
+
"card",
|
|
12
|
+
"grid",
|
|
13
|
+
"list",
|
|
14
|
+
"text",
|
|
15
|
+
"table",
|
|
16
|
+
"media",
|
|
17
|
+
"avatar",
|
|
18
|
+
"chart",
|
|
19
|
+
"profile",
|
|
20
|
+
"off"
|
|
21
|
+
];
|
|
22
|
+
var DEFAULTS = {
|
|
23
|
+
preset: "shimmer",
|
|
24
|
+
theme: "auto",
|
|
25
|
+
delay: 120,
|
|
26
|
+
minVisible: 300,
|
|
27
|
+
maxWait: 5e3,
|
|
28
|
+
autoMedia: true,
|
|
29
|
+
observe: true,
|
|
30
|
+
css: true,
|
|
31
|
+
nonce: "",
|
|
32
|
+
root: null,
|
|
33
|
+
debug: false,
|
|
34
|
+
respectReducedMotion: true
|
|
35
|
+
};
|
|
36
|
+
function toNumber(value, fallback) {
|
|
37
|
+
if (value === null || value === "") return fallback;
|
|
38
|
+
const n = Number(value);
|
|
39
|
+
return Number.isFinite(n) ? n : fallback;
|
|
40
|
+
}
|
|
41
|
+
function resolveOptions(options = {}) {
|
|
42
|
+
const merged = { ...DEFAULTS };
|
|
43
|
+
for (const key of Object.keys(options)) {
|
|
44
|
+
const value = options[key];
|
|
45
|
+
if (value !== void 0) {
|
|
46
|
+
merged[key] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!PRESETS.includes(merged.preset)) merged.preset = DEFAULTS.preset;
|
|
50
|
+
merged.delay = Math.max(0, merged.delay);
|
|
51
|
+
merged.minVisible = Math.max(0, merged.minVisible);
|
|
52
|
+
merged.maxWait = Math.max(0, merged.maxWait);
|
|
53
|
+
return merged;
|
|
54
|
+
}
|
|
55
|
+
function normalizePreset(value) {
|
|
56
|
+
if (!value) return null;
|
|
57
|
+
return PRESETS.includes(value) ? value : null;
|
|
58
|
+
}
|
|
59
|
+
function normalizeTheme(value) {
|
|
60
|
+
if (value === "light" || value === "dark" || value === "auto") return value;
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
function normalizeShape(value) {
|
|
64
|
+
if (!value) return null;
|
|
65
|
+
const v = value.trim().toLowerCase();
|
|
66
|
+
if (v === "" || v === "true" || v === "1") return "auto";
|
|
67
|
+
return SHAPES.includes(v) ? v : null;
|
|
68
|
+
}
|
|
69
|
+
function readSpec(element) {
|
|
70
|
+
const el = element;
|
|
71
|
+
const ds = el.dataset;
|
|
72
|
+
const rawShape = normalizeShape(el.getAttribute("data-skeleton"));
|
|
73
|
+
return {
|
|
74
|
+
shape: rawShape ?? "auto",
|
|
75
|
+
state: ds.skeletonState === "loading" || ds.skeletonState === "done" ? ds.skeletonState : null,
|
|
76
|
+
preset: normalizePreset(el.getAttribute("data-skeleton-preset")),
|
|
77
|
+
lines: Math.max(1, Math.min(12, toNumber(el.getAttribute("data-skeleton-lines"), 3))),
|
|
78
|
+
ratio: el.getAttribute("data-skeleton-ratio"),
|
|
79
|
+
count: Math.max(1, Math.min(24, toNumber(el.getAttribute("data-skeleton-count"), 4))),
|
|
80
|
+
cols: Math.max(1, Math.min(6, toNumber(el.getAttribute("data-skeleton-cols"), 3))),
|
|
81
|
+
height: el.hasAttribute("data-skeleton-h") ? toNumber(el.getAttribute("data-skeleton-h"), 0) || null : null,
|
|
82
|
+
radius: el.hasAttribute("data-skeleton-radius") ? toNumber(el.getAttribute("data-skeleton-radius"), 0) || null : null
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function inheritedPreset(element) {
|
|
86
|
+
let node = element;
|
|
87
|
+
while (node && node !== document.documentElement) {
|
|
88
|
+
const preset = normalizePreset(node.getAttribute("data-skeleton-preset"));
|
|
89
|
+
if (preset) return preset;
|
|
90
|
+
node = node.parentElement;
|
|
91
|
+
}
|
|
92
|
+
return normalizePreset(document.documentElement.getAttribute("data-skeleton-preset"));
|
|
93
|
+
}
|
|
94
|
+
function inheritedTheme(element) {
|
|
95
|
+
let node = element;
|
|
96
|
+
while (node) {
|
|
97
|
+
const theme = normalizeTheme(node.getAttribute("data-skeleton-theme"));
|
|
98
|
+
if (theme) return theme;
|
|
99
|
+
node = node.parentElement;
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
function isOptedOut(element) {
|
|
104
|
+
let node = element;
|
|
105
|
+
let depth = 0;
|
|
106
|
+
while (node && depth < 64) {
|
|
107
|
+
if (node.hasAttribute("data-skeleton-skip")) return true;
|
|
108
|
+
if (node.getAttribute("data-skeleton") === "off") return true;
|
|
109
|
+
node = node.parentElement;
|
|
110
|
+
depth++;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
function isMedia(element) {
|
|
115
|
+
const tag = element.tagName;
|
|
116
|
+
return tag === "IMG" || tag === "VIDEO" || tag === "IFRAME";
|
|
117
|
+
}
|
|
118
|
+
function isLoadedMedia(element) {
|
|
119
|
+
const tag = element.tagName;
|
|
120
|
+
if (tag === "IMG") {
|
|
121
|
+
const img = element;
|
|
122
|
+
return img.complete && img.naturalWidth > 0;
|
|
123
|
+
}
|
|
124
|
+
if (tag === "VIDEO") {
|
|
125
|
+
const video = element;
|
|
126
|
+
return video.readyState >= 2;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
function hasRealContent(element) {
|
|
131
|
+
for (const child of Array.from(element.children)) {
|
|
132
|
+
if (!child.classList.contains("skl-overlay")) return true;
|
|
133
|
+
}
|
|
134
|
+
return (element.textContent ?? "").trim().length > 0;
|
|
135
|
+
}
|
|
136
|
+
function isLazy(element) {
|
|
137
|
+
const loading = element.getAttribute("loading");
|
|
138
|
+
return loading === "lazy" || element.getAttribute("data-skeleton-lazy") === "true";
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/core/utils.ts
|
|
142
|
+
var raf = typeof requestAnimationFrame === "function" ? (cb) => requestAnimationFrame(cb) : (cb) => setTimeout(() => cb(Date.now()), 16);
|
|
143
|
+
function now() {
|
|
144
|
+
return typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
145
|
+
}
|
|
146
|
+
function clamp(value, min, max) {
|
|
147
|
+
return Math.min(max, Math.max(min, value));
|
|
148
|
+
}
|
|
149
|
+
function parseRadius(style) {
|
|
150
|
+
const raw = style.borderTopLeftRadius || style.borderRadius;
|
|
151
|
+
if (!raw) return null;
|
|
152
|
+
const first = raw.split(/\s+/)[0] ?? "";
|
|
153
|
+
if (first.endsWith("%")) return null;
|
|
154
|
+
const n = Number.parseFloat(first);
|
|
155
|
+
return Number.isFinite(n) ? n : null;
|
|
156
|
+
}
|
|
157
|
+
function computedPadding(style) {
|
|
158
|
+
return {
|
|
159
|
+
"padding-top": style.paddingTop,
|
|
160
|
+
"padding-right": style.paddingRight,
|
|
161
|
+
"padding-bottom": style.paddingBottom,
|
|
162
|
+
"padding-left": style.paddingLeft
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/core/shapes.ts
|
|
167
|
+
function make(tag, className, style = {}) {
|
|
168
|
+
const node = document.createElement(tag);
|
|
169
|
+
if (className) node.className = className;
|
|
170
|
+
for (const key of Object.keys(style)) {
|
|
171
|
+
const value = style[key];
|
|
172
|
+
if (value !== void 0) node.style.setProperty(key, value);
|
|
173
|
+
}
|
|
174
|
+
return node;
|
|
175
|
+
}
|
|
176
|
+
function block(style = {}, extra = "") {
|
|
177
|
+
return make("div", `skl-block ${extra}`.trim(), style);
|
|
178
|
+
}
|
|
179
|
+
function relativeLuminance(color) {
|
|
180
|
+
const match = color.match(/rgba?\(([^)]+)\)/i);
|
|
181
|
+
if (!match || !match[1]) return null;
|
|
182
|
+
const parts = match[1].split(",").map((value) => Number.parseFloat(value.trim()));
|
|
183
|
+
const [r, g, b, a] = parts;
|
|
184
|
+
if (r === void 0 || g === void 0 || b === void 0) return null;
|
|
185
|
+
if (a !== void 0 && a < 0.5) return null;
|
|
186
|
+
const channel = (value) => {
|
|
187
|
+
const v = value / 255;
|
|
188
|
+
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
189
|
+
};
|
|
190
|
+
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
|
|
191
|
+
}
|
|
192
|
+
function surfaceOf(element) {
|
|
193
|
+
let node = element;
|
|
194
|
+
let depth = 0;
|
|
195
|
+
while (node && depth < 24) {
|
|
196
|
+
let background = "";
|
|
197
|
+
try {
|
|
198
|
+
background = getComputedStyle(node).backgroundColor;
|
|
199
|
+
} catch {
|
|
200
|
+
background = "";
|
|
201
|
+
}
|
|
202
|
+
const luminance = relativeLuminance(background);
|
|
203
|
+
if (luminance !== null) {
|
|
204
|
+
return { tone: luminance < 0.42 ? "dark" : "light", color: background };
|
|
205
|
+
}
|
|
206
|
+
node = node.parentElement;
|
|
207
|
+
depth++;
|
|
208
|
+
}
|
|
209
|
+
const dark = typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches;
|
|
210
|
+
return { tone: dark ? "dark" : "light", color: dark ? "#0b0d12" : "#ffffff" };
|
|
211
|
+
}
|
|
212
|
+
function line(width, height) {
|
|
213
|
+
return block({ width, ...height ? { height } : {} }, "skl-line");
|
|
214
|
+
}
|
|
215
|
+
function textLines(count) {
|
|
216
|
+
const wrap = make("div", "skl-lines");
|
|
217
|
+
const widths = ["100%", "92%", "97%", "88%", "94%", "84%"];
|
|
218
|
+
for (let i = 0; i < count; i++) {
|
|
219
|
+
const isLast = i === count - 1 && count > 1;
|
|
220
|
+
wrap.appendChild(line(isLast ? "58%" : widths[i % widths.length] ?? "100%"));
|
|
221
|
+
}
|
|
222
|
+
return wrap;
|
|
223
|
+
}
|
|
224
|
+
function cardBlock(spec) {
|
|
225
|
+
const card = make("div", "skl-card");
|
|
226
|
+
const ratio = spec.ratio ?? "16/10";
|
|
227
|
+
card.appendChild(block({ width: "100%", "aspect-ratio": ratio }));
|
|
228
|
+
card.appendChild(line("68%", "0.8em"));
|
|
229
|
+
const lines = make("div", "skl-lines");
|
|
230
|
+
lines.appendChild(line("100%"));
|
|
231
|
+
lines.appendChild(line("82%"));
|
|
232
|
+
card.appendChild(lines);
|
|
233
|
+
card.appendChild(block({ width: "34%", height: "1.15em", "border-radius": "999px" }));
|
|
234
|
+
return card;
|
|
235
|
+
}
|
|
236
|
+
function gridCell(spec) {
|
|
237
|
+
const cell = make("div", "skl-cell");
|
|
238
|
+
cell.appendChild(
|
|
239
|
+
block({ width: "100%", "aspect-ratio": spec.ratio ?? "16/10", "border-radius": "0" })
|
|
240
|
+
);
|
|
241
|
+
const body = make("div", "skl-cell-body");
|
|
242
|
+
body.appendChild(line("58%", "0.82em"));
|
|
243
|
+
body.appendChild(line("36%"));
|
|
244
|
+
body.appendChild(line("92%"));
|
|
245
|
+
const footer = make("div", "skl-row", { "justify-content": "space-between", "margin-top": "6px" });
|
|
246
|
+
footer.appendChild(block({ width: "28%", height: "1.15em", "border-radius": "999px" }));
|
|
247
|
+
footer.appendChild(block({ width: "24%", height: "1.5em", "border-radius": "999px" }));
|
|
248
|
+
body.appendChild(footer);
|
|
249
|
+
cell.appendChild(body);
|
|
250
|
+
return cell;
|
|
251
|
+
}
|
|
252
|
+
function rowBlock(withAvatar) {
|
|
253
|
+
const row = make("div", "skl-row");
|
|
254
|
+
{
|
|
255
|
+
row.appendChild(block({ width: "40px", height: "40px" }, "skl-circle"));
|
|
256
|
+
}
|
|
257
|
+
const lines = make("div", "skl-lines");
|
|
258
|
+
lines.appendChild(line("62%"));
|
|
259
|
+
lines.appendChild(line("40%"));
|
|
260
|
+
row.appendChild(lines);
|
|
261
|
+
return row;
|
|
262
|
+
}
|
|
263
|
+
function tableBlock(spec) {
|
|
264
|
+
const wrap = make("div", "skl-table");
|
|
265
|
+
const header = make("div", "skl-trow skl-thead");
|
|
266
|
+
for (const width of ["54%", "66%", "58%", "50%"]) header.appendChild(line(width, "10px"));
|
|
267
|
+
wrap.appendChild(header);
|
|
268
|
+
const rows = clamp(spec.count, 1, 12);
|
|
269
|
+
for (let i = 0; i < rows; i++) {
|
|
270
|
+
const row = make("div", "skl-trow");
|
|
271
|
+
const who = make("div", "skl-who");
|
|
272
|
+
who.appendChild(block({ width: "30px", height: "30px", "min-height": "0" }, "skl-circle"));
|
|
273
|
+
const lines = make("div", "skl-lines", { gap: "7px" });
|
|
274
|
+
lines.appendChild(line("86%", "10px"));
|
|
275
|
+
lines.appendChild(line("52%", "10px"));
|
|
276
|
+
who.appendChild(lines);
|
|
277
|
+
row.appendChild(who);
|
|
278
|
+
row.appendChild(line("62%", "12px"));
|
|
279
|
+
row.appendChild(line("54%", "12px"));
|
|
280
|
+
row.appendChild(line("58%", "12px"));
|
|
281
|
+
wrap.appendChild(row);
|
|
282
|
+
}
|
|
283
|
+
return wrap;
|
|
284
|
+
}
|
|
285
|
+
function chartBlock() {
|
|
286
|
+
const chart = make("div", "skl-chart");
|
|
287
|
+
const heights = ["38%", "64%", "48%", "86%", "58%", "74%", "44%"];
|
|
288
|
+
for (const h of heights) {
|
|
289
|
+
chart.appendChild(block({ height: h, width: "100%", "border-radius": "6px" }));
|
|
290
|
+
}
|
|
291
|
+
return chart;
|
|
292
|
+
}
|
|
293
|
+
function mediaBlock(spec) {
|
|
294
|
+
const wrap = make("div", "skl-lines", { width: "100%", height: "100%" });
|
|
295
|
+
const ratio = spec.ratio ?? "16/9";
|
|
296
|
+
wrap.appendChild(
|
|
297
|
+
block({ width: "100%", height: "100%", "min-height": "48px", "aspect-ratio": ratio, "border-radius": "inherit" })
|
|
298
|
+
);
|
|
299
|
+
return wrap;
|
|
300
|
+
}
|
|
301
|
+
function avatarBlock(spec) {
|
|
302
|
+
const size = spec.height ? `${spec.height}px` : "clamp(32px, 42%, 64px)";
|
|
303
|
+
const wrap = make("div", "skl-lines", { width: "100%", height: "100%", "align-items": "center", "justify-content": "center" });
|
|
304
|
+
wrap.appendChild(block({ width: size, height: size, "min-height": "0" }, "skl-circle"));
|
|
305
|
+
return wrap;
|
|
306
|
+
}
|
|
307
|
+
function profileBlock(spec) {
|
|
308
|
+
const wrap = make("div", "skl-lines", { "align-items": "center", "justify-content": "center", height: "100%", gap: "12px" });
|
|
309
|
+
const size = spec.height ? `${spec.height}px` : "72px";
|
|
310
|
+
wrap.appendChild(block({ width: size, height: size, "min-height": "0" }, "skl-circle"));
|
|
311
|
+
wrap.appendChild(line("46%"));
|
|
312
|
+
wrap.appendChild(line("30%"));
|
|
313
|
+
return wrap;
|
|
314
|
+
}
|
|
315
|
+
function autoFallback(spec) {
|
|
316
|
+
const count = clamp(spec.count, 1, 8);
|
|
317
|
+
const wrap = make("div", "skl-lines", { width: "100%", gap: "12px" });
|
|
318
|
+
wrap.appendChild(line("34%", "0.85em"));
|
|
319
|
+
for (let i = 0; i < count; i++) {
|
|
320
|
+
const cell = make("div", "skl-cell skl-cell-pad");
|
|
321
|
+
cell.appendChild(rowBlock());
|
|
322
|
+
wrap.appendChild(cell);
|
|
323
|
+
}
|
|
324
|
+
return wrap;
|
|
325
|
+
}
|
|
326
|
+
function mirror(host, overlay, spec, depth) {
|
|
327
|
+
const hostEl = host;
|
|
328
|
+
const rect = hostEl.getBoundingClientRect();
|
|
329
|
+
const originLeft = rect.left + hostEl.clientLeft;
|
|
330
|
+
const originTop = rect.top + hostEl.clientTop;
|
|
331
|
+
const width = hostEl.clientWidth || rect.width;
|
|
332
|
+
const height = hostEl.clientHeight || rect.height;
|
|
333
|
+
if (width < 8 || height < 8) return 0;
|
|
334
|
+
const targets = [];
|
|
335
|
+
const walk = (parent, level) => {
|
|
336
|
+
for (const child of Array.from(parent.children)) {
|
|
337
|
+
if (child.classList.contains("skl-overlay")) continue;
|
|
338
|
+
const style = getComputedStyle(child);
|
|
339
|
+
if (style.display === "none" || style.visibility === "hidden") continue;
|
|
340
|
+
targets.push(child);
|
|
341
|
+
if (level < depth) walk(child, level + 1);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
walk(host, 1);
|
|
345
|
+
let count = 0;
|
|
346
|
+
for (const child of targets) {
|
|
347
|
+
if (count >= 64) break;
|
|
348
|
+
const r = child.getBoundingClientRect();
|
|
349
|
+
if (r.width < 4 || r.height < 4) continue;
|
|
350
|
+
let left = r.left - originLeft;
|
|
351
|
+
let top = r.top - originTop;
|
|
352
|
+
if (left > width - 2 || top > height - 2) continue;
|
|
353
|
+
left = clamp(left, 0, Math.max(0, width - 4));
|
|
354
|
+
top = clamp(top, 0, Math.max(0, height - 4));
|
|
355
|
+
const w = Math.min(r.width, width - left);
|
|
356
|
+
const h = Math.min(r.height, height - top);
|
|
357
|
+
if (w < 4 || h < 4) continue;
|
|
358
|
+
const style = getComputedStyle(child);
|
|
359
|
+
const radius = spec.radius ?? (child.tagName === "IMG" ? 8 : clamp(parseRadius(style) ?? 8, 0, 24));
|
|
360
|
+
const textLike = child.childElementCount === 0 && (child.textContent ?? "").trim().length > 0;
|
|
361
|
+
const node = block({
|
|
362
|
+
left: `${Math.round(left)}px`,
|
|
363
|
+
top: `${Math.round(top)}px`,
|
|
364
|
+
width: `${Math.round(w)}px`,
|
|
365
|
+
height: `${Math.round(h)}px`,
|
|
366
|
+
"border-radius": `${radius}px`,
|
|
367
|
+
...textLike ? { "border-radius": "999px", height: `${Math.min(Math.round(h), 16)}px` } : {}
|
|
368
|
+
});
|
|
369
|
+
overlay.appendChild(node);
|
|
370
|
+
count++;
|
|
371
|
+
}
|
|
372
|
+
return count;
|
|
373
|
+
}
|
|
374
|
+
function buildOverlay(ctx) {
|
|
375
|
+
const { host, spec, media, preset } = ctx;
|
|
376
|
+
const overlay = make("div", "skl-overlay");
|
|
377
|
+
overlay.dataset.sklPreset = preset;
|
|
378
|
+
overlay.dataset.sklKind = media ? "media" : "container";
|
|
379
|
+
overlay.setAttribute("aria-hidden", "true");
|
|
380
|
+
const style = getComputedStyle(host);
|
|
381
|
+
const surface = surfaceOf(media ? host.parentElement ?? host : host);
|
|
382
|
+
const forced = ctx.theme === "light" || ctx.theme === "dark" ? ctx.theme : null;
|
|
383
|
+
overlay.dataset.sklTone = forced ?? surface.tone;
|
|
384
|
+
overlay.style.setProperty("--skl-solid", surface.color);
|
|
385
|
+
if (media) {
|
|
386
|
+
overlay.dataset.sklLayout = "fill";
|
|
387
|
+
const hostRadius = style.borderRadius;
|
|
388
|
+
if (hostRadius && hostRadius !== "0px") overlay.style.borderRadius = hostRadius;
|
|
389
|
+
overlay.appendChild(block({ width: "100%", height: "100%", "border-radius": "inherit" }));
|
|
390
|
+
return overlay;
|
|
391
|
+
}
|
|
392
|
+
const pad = computedPadding(style);
|
|
393
|
+
for (const key of Object.keys(pad)) {
|
|
394
|
+
const value = pad[key];
|
|
395
|
+
if (value && value !== "0px") overlay.style.setProperty(key, value);
|
|
396
|
+
}
|
|
397
|
+
if (spec.radius) overlay.style.setProperty("--skl-radius", `${spec.radius}px`);
|
|
398
|
+
switch (spec.shape) {
|
|
399
|
+
case "text":
|
|
400
|
+
overlay.dataset.sklLayout = "stack";
|
|
401
|
+
overlay.appendChild(textLines(spec.lines));
|
|
402
|
+
break;
|
|
403
|
+
case "card":
|
|
404
|
+
overlay.dataset.sklLayout = "stack";
|
|
405
|
+
overlay.appendChild(cardBlock(spec));
|
|
406
|
+
break;
|
|
407
|
+
case "grid": {
|
|
408
|
+
overlay.dataset.sklLayout = "grid";
|
|
409
|
+
overlay.style.setProperty("--skl-cols", String(spec.cols));
|
|
410
|
+
for (let i = 0; i < spec.count; i++) overlay.appendChild(gridCell(spec));
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
case "list": {
|
|
414
|
+
overlay.dataset.sklLayout = "stack";
|
|
415
|
+
for (let i = 0; i < spec.count; i++) overlay.appendChild(rowBlock());
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
case "table":
|
|
419
|
+
overlay.dataset.sklLayout = "stack";
|
|
420
|
+
overlay.appendChild(tableBlock(spec));
|
|
421
|
+
break;
|
|
422
|
+
case "media":
|
|
423
|
+
overlay.dataset.sklLayout = "stack";
|
|
424
|
+
overlay.appendChild(mediaBlock(spec));
|
|
425
|
+
break;
|
|
426
|
+
case "avatar":
|
|
427
|
+
overlay.dataset.sklLayout = "stack";
|
|
428
|
+
overlay.appendChild(avatarBlock(spec));
|
|
429
|
+
break;
|
|
430
|
+
case "chart":
|
|
431
|
+
overlay.dataset.sklLayout = "stack";
|
|
432
|
+
overlay.appendChild(chartBlock());
|
|
433
|
+
break;
|
|
434
|
+
case "profile":
|
|
435
|
+
overlay.dataset.sklLayout = "stack";
|
|
436
|
+
overlay.appendChild(profileBlock(spec));
|
|
437
|
+
break;
|
|
438
|
+
default: {
|
|
439
|
+
overlay.dataset.sklLayout = "mirror";
|
|
440
|
+
const depth = host.getAttribute("data-skeleton-depth") === "2" ? 2 : 1;
|
|
441
|
+
const painted = mirror(host, overlay, spec, depth);
|
|
442
|
+
if (!painted) {
|
|
443
|
+
overlay.dataset.sklLayout = "stack";
|
|
444
|
+
overlay.appendChild(autoFallback(spec));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (!overlay.style.getPropertyValue("--skl-radius") && spec.radius === null) {
|
|
449
|
+
const hostRadius = parseRadius(style);
|
|
450
|
+
if (hostRadius !== null && hostRadius <= 32) {
|
|
451
|
+
overlay.style.setProperty("--skl-radius", `${hostRadius}px`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return overlay;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// src/core/css.generated.ts
|
|
458
|
+
var css_generated_default = `/*!
|
|
459
|
+
* skeleton-load v0.1.0 \u2014 MIT
|
|
460
|
+
* https://github.com/skeleton-load
|
|
461
|
+
*/
|
|
462
|
+
|
|
463
|
+
.skl-host,
|
|
464
|
+
[data-skl-state] {
|
|
465
|
+
position: relative;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/* Content is kept in the layout (no CLS) but hidden while the skeleton plays. */
|
|
469
|
+
[data-skl-state="loading"] > *:not(.skl-overlay) {
|
|
470
|
+
visibility: hidden !important;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
.skl-overlay {
|
|
474
|
+
position: absolute;
|
|
475
|
+
inset: 0;
|
|
476
|
+
z-index: 4;
|
|
477
|
+
overflow: hidden;
|
|
478
|
+
pointer-events: none;
|
|
479
|
+
border-radius: inherit;
|
|
480
|
+
opacity: 0;
|
|
481
|
+
transition: opacity 180ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
482
|
+
contain: layout paint style;
|
|
483
|
+
|
|
484
|
+
--skl-base: rgba(17, 20, 28, 0.1);
|
|
485
|
+
--skl-highlight: rgba(255, 255, 255, 0.72);
|
|
486
|
+
--skl-radius: 8px;
|
|
487
|
+
--skl-gap: 10px;
|
|
488
|
+
--skl-surface: #ffffff;
|
|
489
|
+
--skl-border: rgba(17, 20, 28, 0.08);
|
|
490
|
+
--skl-line: rgba(17, 20, 28, 0.08);
|
|
491
|
+
--skl-solid: #f1f1f6;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/* A dark surface needs brighter placeholders to be readable at all. */
|
|
495
|
+
.skl-overlay[data-skl-tone="dark"] {
|
|
496
|
+
--skl-base: rgba(255, 255, 255, 0.115);
|
|
497
|
+
--skl-highlight: rgba(255, 255, 255, 0.22);
|
|
498
|
+
--skl-surface: rgba(255, 255, 255, 0.035);
|
|
499
|
+
--skl-border: rgba(255, 255, 255, 0.07);
|
|
500
|
+
--skl-line: rgba(255, 255, 255, 0.07);
|
|
501
|
+
--skl-solid: #14161c;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
.skl-overlay[data-skl-show="1"] {
|
|
505
|
+
opacity: 1;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/* Temporary state used to measure the skeleton's natural height. */
|
|
509
|
+
.skl-overlay[data-skl-measure] {
|
|
510
|
+
inset: auto;
|
|
511
|
+
top: 0;
|
|
512
|
+
left: 0;
|
|
513
|
+
opacity: 0;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
.skl-overlay[data-skl-kind="media"] {
|
|
517
|
+
background: var(--skl-solid);
|
|
518
|
+
border-radius: var(--skl-radius);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/* ---------- blocks ---------- */
|
|
522
|
+
|
|
523
|
+
.skl-block {
|
|
524
|
+
position: relative;
|
|
525
|
+
min-height: 8px;
|
|
526
|
+
overflow: hidden;
|
|
527
|
+
border-radius: var(--skl-radius);
|
|
528
|
+
background: var(--skl-base);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
.skl-block::after {
|
|
532
|
+
content: "";
|
|
533
|
+
position: absolute;
|
|
534
|
+
inset: 0;
|
|
535
|
+
background: linear-gradient(
|
|
536
|
+
90deg,
|
|
537
|
+
transparent 0%,
|
|
538
|
+
var(--skl-highlight) 50%,
|
|
539
|
+
transparent 100%
|
|
540
|
+
);
|
|
541
|
+
transform: translateX(-100%);
|
|
542
|
+
animation: skl-shimmer var(--skl-speed, 1.6s) cubic-bezier(0.45, 0, 0.25, 1) infinite;
|
|
543
|
+
will-change: transform;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
.skl-overlay[data-skl-preset="pulse"] .skl-block::after,
|
|
547
|
+
.skl-overlay[data-skl-preset="static"] .skl-block::after {
|
|
548
|
+
display: none;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
.skl-overlay[data-skl-preset="pulse"] .skl-block {
|
|
552
|
+
animation: skl-pulse 1.8s ease-in-out infinite;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
.skl-overlay[data-skl-preset="static"] .skl-block {
|
|
556
|
+
opacity: 0.92;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/* Pause everything while the tab is in the background. */
|
|
560
|
+
html[data-skl-idle] .skl-block::after,
|
|
561
|
+
html[data-skl-idle] .skl-block {
|
|
562
|
+
animation-play-state: paused;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/* ---------- layouts ---------- */
|
|
566
|
+
|
|
567
|
+
.skl-overlay[data-skl-layout="stack"] {
|
|
568
|
+
display: flex;
|
|
569
|
+
flex-direction: column;
|
|
570
|
+
gap: var(--skl-gap);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
.skl-overlay[data-skl-layout="row"] {
|
|
574
|
+
display: flex;
|
|
575
|
+
flex-direction: row;
|
|
576
|
+
align-items: center;
|
|
577
|
+
gap: var(--skl-gap);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
.skl-overlay[data-skl-layout="grid"] {
|
|
581
|
+
display: grid;
|
|
582
|
+
gap: var(--skl-gap);
|
|
583
|
+
grid-template-columns: repeat(var(--skl-cols, 3), minmax(0, 1fr));
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
.skl-overlay[data-skl-layout="center"] {
|
|
587
|
+
display: flex;
|
|
588
|
+
flex-direction: column;
|
|
589
|
+
align-items: center;
|
|
590
|
+
justify-content: center;
|
|
591
|
+
gap: var(--skl-gap);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
.skl-overlay[data-skl-layout="mirror"] {
|
|
595
|
+
padding: 0;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
.skl-overlay[data-skl-layout="mirror"] > .skl-block {
|
|
599
|
+
position: absolute;
|
|
600
|
+
min-height: 0;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
.skl-card {
|
|
604
|
+
display: flex;
|
|
605
|
+
flex-direction: column;
|
|
606
|
+
gap: var(--skl-gap);
|
|
607
|
+
min-width: 0;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
.skl-cell {
|
|
611
|
+
display: flex;
|
|
612
|
+
flex-direction: column;
|
|
613
|
+
gap: 0;
|
|
614
|
+
min-width: 0;
|
|
615
|
+
overflow: hidden;
|
|
616
|
+
border-radius: calc(var(--skl-radius) + 8px);
|
|
617
|
+
background: var(--skl-surface);
|
|
618
|
+
border: 1px solid var(--skl-border);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
.skl-cell-body {
|
|
622
|
+
display: flex;
|
|
623
|
+
flex-direction: column;
|
|
624
|
+
gap: 8px;
|
|
625
|
+
padding: 16px;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
.skl-cell-pad {
|
|
629
|
+
padding: 20px 18px;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
.skl-row {
|
|
633
|
+
display: flex;
|
|
634
|
+
align-items: center;
|
|
635
|
+
gap: var(--skl-gap);
|
|
636
|
+
min-width: 0;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
.skl-lines {
|
|
640
|
+
display: flex;
|
|
641
|
+
flex: 1 1 auto;
|
|
642
|
+
flex-direction: column;
|
|
643
|
+
gap: 8px;
|
|
644
|
+
min-width: 0;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
.skl-line {
|
|
648
|
+
height: var(--skl-line-h, 0.72em);
|
|
649
|
+
min-height: 7px;
|
|
650
|
+
border-radius: 999px;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
.skl-circle {
|
|
654
|
+
border-radius: 50%;
|
|
655
|
+
flex: 0 0 auto;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
.skl-chart {
|
|
659
|
+
display: flex;
|
|
660
|
+
align-items: flex-end;
|
|
661
|
+
gap: var(--skl-gap);
|
|
662
|
+
height: 100%;
|
|
663
|
+
min-height: 90px;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
.skl-chart > .skl-block {
|
|
667
|
+
flex: 1 1 0;
|
|
668
|
+
min-width: 0;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/* ---------- table ---------- */
|
|
672
|
+
|
|
673
|
+
.skl-table {
|
|
674
|
+
display: flex;
|
|
675
|
+
flex-direction: column;
|
|
676
|
+
width: 100%;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
.skl-trow {
|
|
680
|
+
display: grid;
|
|
681
|
+
grid-template-columns: 2.2fr 1fr 1fr 0.9fr;
|
|
682
|
+
gap: 14px;
|
|
683
|
+
align-items: center;
|
|
684
|
+
padding: 19px 8px;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
.skl-trow + .skl-trow {
|
|
688
|
+
border-top: 1px solid var(--skl-line);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
.skl-thead {
|
|
692
|
+
padding-top: 2px;
|
|
693
|
+
padding-bottom: 12px;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
.skl-thead .skl-line {
|
|
697
|
+
min-height: 8px;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
.skl-who {
|
|
701
|
+
display: flex;
|
|
702
|
+
align-items: center;
|
|
703
|
+
gap: 10px;
|
|
704
|
+
min-width: 0;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/* ---------- reveal ---------- */
|
|
708
|
+
|
|
709
|
+
[data-skl-state="done"] > *:not(.skl-overlay) {
|
|
710
|
+
animation: skl-content-in 200ms ease both;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/* ---------- debug ---------- */
|
|
714
|
+
|
|
715
|
+
[data-skl-debug] .skl-block {
|
|
716
|
+
outline: 1px dashed rgba(255, 64, 129, 0.7);
|
|
717
|
+
outline-offset: -1px;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
[data-skl-debug] .skl-overlay {
|
|
721
|
+
outline: 2px solid rgba(255, 64, 129, 0.9);
|
|
722
|
+
outline-offset: -2px;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/* ---------- keyframes ---------- */
|
|
726
|
+
|
|
727
|
+
@keyframes skl-shimmer {
|
|
728
|
+
from {
|
|
729
|
+
transform: translateX(-100%);
|
|
730
|
+
}
|
|
731
|
+
to {
|
|
732
|
+
transform: translateX(100%);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
@keyframes skl-pulse {
|
|
737
|
+
0%,
|
|
738
|
+
100% {
|
|
739
|
+
opacity: 0.55;
|
|
740
|
+
}
|
|
741
|
+
50% {
|
|
742
|
+
opacity: 1;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
@keyframes skl-content-in {
|
|
747
|
+
from {
|
|
748
|
+
opacity: 0;
|
|
749
|
+
}
|
|
750
|
+
to {
|
|
751
|
+
opacity: 1;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/* ---------- preferences ---------- */
|
|
756
|
+
|
|
757
|
+
@media (prefers-reduced-motion: reduce) {
|
|
758
|
+
.skl-overlay {
|
|
759
|
+
transition: none;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
.skl-block::after {
|
|
763
|
+
display: none;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
.skl-overlay[data-skl-preset="pulse"] .skl-block,
|
|
767
|
+
[data-skl-state="done"] > * {
|
|
768
|
+
animation: none;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
@media (prefers-reduced-data: reduce) {
|
|
773
|
+
.skl-block::after {
|
|
774
|
+
display: none;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
@media (forced-colors: active) {
|
|
779
|
+
.skl-block {
|
|
780
|
+
background: CanvasText;
|
|
781
|
+
opacity: 0.25;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
`;
|
|
785
|
+
|
|
786
|
+
// src/core/style.ts
|
|
787
|
+
var STYLE_ID = "skeleton-load-styles";
|
|
788
|
+
function injectStyles(nonce) {
|
|
789
|
+
if (typeof document === "undefined") return null;
|
|
790
|
+
const existing = document.getElementById(STYLE_ID);
|
|
791
|
+
if (existing) return existing;
|
|
792
|
+
const style = document.createElement("style");
|
|
793
|
+
style.id = STYLE_ID;
|
|
794
|
+
style.setAttribute("data-skeleton-load", "");
|
|
795
|
+
if (nonce) style.setAttribute("nonce", nonce);
|
|
796
|
+
style.textContent = css_generated_default;
|
|
797
|
+
const head = document.head ?? document.documentElement;
|
|
798
|
+
head.prepend(style);
|
|
799
|
+
return style;
|
|
800
|
+
}
|
|
801
|
+
function removeStyles() {
|
|
802
|
+
document.getElementById(STYLE_ID)?.remove();
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// src/core/engine.ts
|
|
806
|
+
function isDisplayNone(element) {
|
|
807
|
+
const el = element;
|
|
808
|
+
if (el.hidden) return true;
|
|
809
|
+
try {
|
|
810
|
+
return getComputedStyle(element).display === "none";
|
|
811
|
+
} catch {
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
var SkeletonEngine = class {
|
|
816
|
+
constructor(options = {}) {
|
|
817
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
818
|
+
this.waiting = /* @__PURE__ */ new Map();
|
|
819
|
+
this.mo = null;
|
|
820
|
+
this.io = null;
|
|
821
|
+
this.pending = /* @__PURE__ */ new Set();
|
|
822
|
+
this.rafId = 0;
|
|
823
|
+
this.styleEl = null;
|
|
824
|
+
this.started = false;
|
|
825
|
+
this.destroyed = false;
|
|
826
|
+
this.visibilityHandler = null;
|
|
827
|
+
this.stats = { shown: 0, hidden: 0, total: 0 };
|
|
828
|
+
this.raw = { ...options };
|
|
829
|
+
this.resolved = resolveOptions(this.raw);
|
|
830
|
+
}
|
|
831
|
+
get options() {
|
|
832
|
+
return this.resolved;
|
|
833
|
+
}
|
|
834
|
+
start() {
|
|
835
|
+
if (typeof document === "undefined") return this;
|
|
836
|
+
this.destroyed = false;
|
|
837
|
+
if (this.started) return this;
|
|
838
|
+
this.started = true;
|
|
839
|
+
if (this.resolved.css && !this.styleEl) {
|
|
840
|
+
this.styleEl = injectStyles(this.resolved.nonce);
|
|
841
|
+
}
|
|
842
|
+
if (this.resolved.debug) {
|
|
843
|
+
document.documentElement.setAttribute("data-skl-debug", "");
|
|
844
|
+
}
|
|
845
|
+
this.observe();
|
|
846
|
+
this.bindVisibility();
|
|
847
|
+
this.refresh();
|
|
848
|
+
return this;
|
|
849
|
+
}
|
|
850
|
+
stop() {
|
|
851
|
+
this.started = false;
|
|
852
|
+
this.mo?.disconnect();
|
|
853
|
+
this.mo = null;
|
|
854
|
+
this.io?.disconnect();
|
|
855
|
+
this.io = null;
|
|
856
|
+
this.waiting.clear();
|
|
857
|
+
if (this.rafId) {
|
|
858
|
+
cancelAnimationFrame(this.rafId);
|
|
859
|
+
this.rafId = 0;
|
|
860
|
+
}
|
|
861
|
+
for (const entry of Array.from(this.entries.values())) {
|
|
862
|
+
entry.state = "done";
|
|
863
|
+
this.teardown(entry, true);
|
|
864
|
+
}
|
|
865
|
+
this.entries.clear();
|
|
866
|
+
document.documentElement.removeAttribute("data-skl-debug");
|
|
867
|
+
return this;
|
|
868
|
+
}
|
|
869
|
+
destroy() {
|
|
870
|
+
this.stop();
|
|
871
|
+
this.destroyed = true;
|
|
872
|
+
if (this.styleEl) {
|
|
873
|
+
removeStyles();
|
|
874
|
+
this.styleEl = null;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
update(options) {
|
|
878
|
+
this.raw = { ...this.raw, ...options };
|
|
879
|
+
this.resolved = resolveOptions(this.raw);
|
|
880
|
+
if (this.started) {
|
|
881
|
+
for (const entry of this.entries.values()) {
|
|
882
|
+
const next = entry.spec.preset ?? inheritedPreset(entry.host) ?? this.resolved.preset;
|
|
883
|
+
if (entry.preset !== next) {
|
|
884
|
+
entry.preset = next;
|
|
885
|
+
if (entry.overlay) entry.overlay.dataset.sklPreset = next;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
this.refresh();
|
|
889
|
+
}
|
|
890
|
+
return this;
|
|
891
|
+
}
|
|
892
|
+
setPreset(preset) {
|
|
893
|
+
return this.update({ preset });
|
|
894
|
+
}
|
|
895
|
+
refresh(root) {
|
|
896
|
+
if (!this.started) this.start();
|
|
897
|
+
this.scan(root ?? this.resolved.root ?? document);
|
|
898
|
+
return this;
|
|
899
|
+
}
|
|
900
|
+
show(element) {
|
|
901
|
+
if (!this.started) this.start();
|
|
902
|
+
this.consider(element, true);
|
|
903
|
+
return this;
|
|
904
|
+
}
|
|
905
|
+
hide(element) {
|
|
906
|
+
const entry = this.entries.get(element);
|
|
907
|
+
if (entry) this.finish(entry);
|
|
908
|
+
return this;
|
|
909
|
+
}
|
|
910
|
+
/** Elements currently displaying a skeleton. */
|
|
911
|
+
get active() {
|
|
912
|
+
return Array.from(this.entries.values()).filter((e) => e.state === "shown").map((e) => e.host);
|
|
913
|
+
}
|
|
914
|
+
get report() {
|
|
915
|
+
return { ...this.stats };
|
|
916
|
+
}
|
|
917
|
+
// ----------------------------- internals -----------------------------
|
|
918
|
+
observe() {
|
|
919
|
+
if (typeof MutationObserver === "undefined") return;
|
|
920
|
+
if (!this.mo) {
|
|
921
|
+
this.mo = new MutationObserver((records) => this.onMutations(records));
|
|
922
|
+
}
|
|
923
|
+
this.mo.observe(document.documentElement, {
|
|
924
|
+
childList: true,
|
|
925
|
+
subtree: true,
|
|
926
|
+
characterData: true,
|
|
927
|
+
attributes: true,
|
|
928
|
+
attributeFilter: [
|
|
929
|
+
"data-skeleton",
|
|
930
|
+
"data-skeleton-state",
|
|
931
|
+
"data-skeleton-preset",
|
|
932
|
+
"data-skeleton-lines",
|
|
933
|
+
"src",
|
|
934
|
+
"loading"
|
|
935
|
+
]
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
bindVisibility() {
|
|
939
|
+
if (this.visibilityHandler) return;
|
|
940
|
+
this.visibilityHandler = () => {
|
|
941
|
+
const root = document.documentElement;
|
|
942
|
+
if (document.hidden) root.setAttribute("data-skl-idle", "");
|
|
943
|
+
else root.removeAttribute("data-skl-idle");
|
|
944
|
+
};
|
|
945
|
+
document.addEventListener("visibilitychange", this.visibilityHandler);
|
|
946
|
+
}
|
|
947
|
+
onMutations(records) {
|
|
948
|
+
const roots = [];
|
|
949
|
+
for (const record of records) {
|
|
950
|
+
const target = record.target;
|
|
951
|
+
if (record.type === "attributes") {
|
|
952
|
+
const name = record.attributeName;
|
|
953
|
+
if (name === "data-skeleton-state") {
|
|
954
|
+
this.syncState(target);
|
|
955
|
+
continue;
|
|
956
|
+
}
|
|
957
|
+
if (name === "data-skeleton" || name === "data-skeleton-preset" || name === "data-skeleton-lines") {
|
|
958
|
+
if (this.entries.has(target)) this.restart(target);
|
|
959
|
+
else if (this.resolved.observe) roots.push(target);
|
|
960
|
+
continue;
|
|
961
|
+
}
|
|
962
|
+
if (name === "src" && isMedia(target)) {
|
|
963
|
+
if (this.entries.has(target)) this.restart(target);
|
|
964
|
+
else if (this.resolved.observe) roots.push(target);
|
|
965
|
+
}
|
|
966
|
+
continue;
|
|
967
|
+
}
|
|
968
|
+
const entry = this.entries.get(target);
|
|
969
|
+
if (entry && !entry.media) {
|
|
970
|
+
if (hasRealContent(target)) this.finish(entry);
|
|
971
|
+
}
|
|
972
|
+
if (record.type === "characterData") {
|
|
973
|
+
const host = target.parentElement;
|
|
974
|
+
const hostEntry = host ? this.entries.get(host) : void 0;
|
|
975
|
+
if (hostEntry && !hostEntry.media && hasRealContent(host)) this.finish(hostEntry);
|
|
976
|
+
continue;
|
|
977
|
+
}
|
|
978
|
+
if (!this.resolved.observe) continue;
|
|
979
|
+
record.addedNodes.forEach((node) => {
|
|
980
|
+
if (node.nodeType === 1) roots.push(node);
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
if (roots.length) this.queueScan(roots);
|
|
984
|
+
}
|
|
985
|
+
queueScan(roots) {
|
|
986
|
+
for (const root of roots) this.pending.add(root);
|
|
987
|
+
if (this.rafId) return;
|
|
988
|
+
this.rafId = raf(() => {
|
|
989
|
+
this.rafId = 0;
|
|
990
|
+
const nodes = Array.from(this.pending);
|
|
991
|
+
this.pending.clear();
|
|
992
|
+
for (const node of nodes) {
|
|
993
|
+
if (node.isConnected) this.scan(node);
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
syncState(element) {
|
|
998
|
+
const state = element.getAttribute("data-skeleton-state");
|
|
999
|
+
const entry = this.entries.get(element);
|
|
1000
|
+
if (state === "loading") {
|
|
1001
|
+
if (!entry) this.consider(element, true);
|
|
1002
|
+
else if (entry.state === "done") this.restart(element);
|
|
1003
|
+
else entry.forced = true;
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
if (state === "done" && entry) this.finish(entry);
|
|
1007
|
+
}
|
|
1008
|
+
restart(element) {
|
|
1009
|
+
const entry = this.entries.get(element);
|
|
1010
|
+
if (entry) this.teardown(entry, true);
|
|
1011
|
+
raf(() => this.consider(element, false));
|
|
1012
|
+
}
|
|
1013
|
+
scan(root) {
|
|
1014
|
+
if (!root) return;
|
|
1015
|
+
const candidates = [];
|
|
1016
|
+
if (root instanceof Element) candidates.push(root);
|
|
1017
|
+
const query = root.querySelectorAll;
|
|
1018
|
+
if (typeof query === "function") {
|
|
1019
|
+
query.call(root, "img,video,iframe,[data-skeleton]").forEach((el) => candidates.push(el));
|
|
1020
|
+
}
|
|
1021
|
+
for (const element of candidates) this.consider(element, false);
|
|
1022
|
+
}
|
|
1023
|
+
consider(element, force) {
|
|
1024
|
+
if (!element.isConnected && force) return;
|
|
1025
|
+
if (this.entries.has(element)) return;
|
|
1026
|
+
if (!force && isOptedOut(element)) return;
|
|
1027
|
+
const media = isMedia(element);
|
|
1028
|
+
const spec = readSpec(element);
|
|
1029
|
+
if (!media && spec.shape === "off") return;
|
|
1030
|
+
if (!force && element.closest('[data-skl-state="loading"]')) return;
|
|
1031
|
+
if (media) {
|
|
1032
|
+
const explicit = element.hasAttribute("data-skeleton");
|
|
1033
|
+
if (!this.resolved.autoMedia && !explicit && !force) return;
|
|
1034
|
+
if (!force && spec.state === "done") return;
|
|
1035
|
+
if (!force && isLoadedMedia(element) && spec.state !== "loading") return;
|
|
1036
|
+
if (!force && this.resolved.observe && isLazy(element)) {
|
|
1037
|
+
this.watchLazy(element);
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
this.addEntry(element, true, spec, force || spec.state === "loading");
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
if (!force && spec.state === "done") return;
|
|
1044
|
+
const forced = force || spec.state === "loading";
|
|
1045
|
+
if (!forced && hasRealContent(element)) return;
|
|
1046
|
+
if (!forced && isDisplayNone(element)) return;
|
|
1047
|
+
this.addEntry(element, false, spec, forced);
|
|
1048
|
+
}
|
|
1049
|
+
watchLazy(element) {
|
|
1050
|
+
if (typeof IntersectionObserver === "undefined") {
|
|
1051
|
+
this.consider(element, true);
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
if (this.waiting.has(element)) return;
|
|
1055
|
+
if (!this.io) {
|
|
1056
|
+
this.io = new IntersectionObserver(
|
|
1057
|
+
(records) => {
|
|
1058
|
+
for (const record of records) {
|
|
1059
|
+
if (!record.isIntersecting) continue;
|
|
1060
|
+
const callback = this.waiting.get(record.target);
|
|
1061
|
+
if (!callback) continue;
|
|
1062
|
+
this.waiting.delete(record.target);
|
|
1063
|
+
this.io?.unobserve(record.target);
|
|
1064
|
+
callback();
|
|
1065
|
+
}
|
|
1066
|
+
},
|
|
1067
|
+
{ rootMargin: "320px 0px" }
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
this.waiting.set(element, () => this.consider(element, false));
|
|
1071
|
+
this.io.observe(element);
|
|
1072
|
+
}
|
|
1073
|
+
addEntry(host, media, spec, forced) {
|
|
1074
|
+
if (this.entries.has(host)) return;
|
|
1075
|
+
const preset = spec.preset ?? inheritedPreset(host) ?? this.resolved.preset;
|
|
1076
|
+
const entry = {
|
|
1077
|
+
host,
|
|
1078
|
+
media,
|
|
1079
|
+
spec,
|
|
1080
|
+
preset,
|
|
1081
|
+
forced,
|
|
1082
|
+
state: "pending",
|
|
1083
|
+
overlay: null,
|
|
1084
|
+
container: null,
|
|
1085
|
+
timer: null,
|
|
1086
|
+
guard: null,
|
|
1087
|
+
hideTimer: null,
|
|
1088
|
+
fadeTimer: null,
|
|
1089
|
+
shownAt: 0,
|
|
1090
|
+
cleanup: []
|
|
1091
|
+
};
|
|
1092
|
+
this.entries.set(host, entry);
|
|
1093
|
+
this.stats.total++;
|
|
1094
|
+
const delay = this.resolved.delay;
|
|
1095
|
+
if (delay <= 0) this.paint(entry);
|
|
1096
|
+
else entry.timer = setTimeout(() => this.paint(entry), delay);
|
|
1097
|
+
if (this.resolved.maxWait > 0) {
|
|
1098
|
+
entry.guard = setTimeout(() => this.finish(entry), this.resolved.maxWait + delay);
|
|
1099
|
+
}
|
|
1100
|
+
if (media) {
|
|
1101
|
+
const done = () => this.finish(entry);
|
|
1102
|
+
host.addEventListener("load", done, { once: true });
|
|
1103
|
+
host.addEventListener("error", done, { once: true });
|
|
1104
|
+
entry.cleanup.push(() => {
|
|
1105
|
+
host.removeEventListener("load", done);
|
|
1106
|
+
host.removeEventListener("error", done);
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
paint(entry) {
|
|
1111
|
+
if (entry.state !== "pending") return;
|
|
1112
|
+
const host = entry.host;
|
|
1113
|
+
if (entry.media) {
|
|
1114
|
+
if (isLoadedMedia(host) && !entry.forced) {
|
|
1115
|
+
this.finish(entry);
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
} else if (!entry.forced && hasRealContent(host)) {
|
|
1119
|
+
this.finish(entry);
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
const overlay = buildOverlay({
|
|
1123
|
+
host,
|
|
1124
|
+
spec: entry.spec,
|
|
1125
|
+
media: entry.media,
|
|
1126
|
+
preset: entry.preset,
|
|
1127
|
+
theme: this.themeOf(host)
|
|
1128
|
+
});
|
|
1129
|
+
if (entry.media) this.mountMedia(entry, overlay);
|
|
1130
|
+
else this.mountContainer(entry, overlay);
|
|
1131
|
+
entry.overlay = overlay;
|
|
1132
|
+
entry.state = "shown";
|
|
1133
|
+
entry.shownAt = now();
|
|
1134
|
+
this.stats.shown++;
|
|
1135
|
+
if (this.resolved.debug) overlay.setAttribute("data-skl-debug", "");
|
|
1136
|
+
void overlay.offsetWidth;
|
|
1137
|
+
overlay.dataset.sklShow = "1";
|
|
1138
|
+
this.resolved.onShow?.(host);
|
|
1139
|
+
}
|
|
1140
|
+
mountContainer(entry, overlay) {
|
|
1141
|
+
const host = entry.host;
|
|
1142
|
+
host.classList.add("skl-host");
|
|
1143
|
+
host.dataset.sklShape = entry.spec.shape;
|
|
1144
|
+
host.dataset.sklState = "loading";
|
|
1145
|
+
host.appendChild(overlay);
|
|
1146
|
+
if (entry.spec.height) {
|
|
1147
|
+
entry.prevMinHeight = host.style.minHeight;
|
|
1148
|
+
host.style.minHeight = `${entry.spec.height}px`;
|
|
1149
|
+
} else if (overlay.dataset.sklLayout !== "mirror") {
|
|
1150
|
+
const reserved = this.measure(overlay);
|
|
1151
|
+
if (reserved > 8) {
|
|
1152
|
+
const current = host.getBoundingClientRect().height;
|
|
1153
|
+
if (reserved > current + 2) {
|
|
1154
|
+
entry.prevMinHeight = host.style.minHeight;
|
|
1155
|
+
host.style.minHeight = `${Math.ceil(reserved)}px`;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
if (entry.spec.shape === "auto" && typeof ResizeObserver !== "undefined") {
|
|
1160
|
+
const ro = new ResizeObserver(() => this.repaint(entry));
|
|
1161
|
+
ro.observe(host);
|
|
1162
|
+
entry.cleanup.push(() => ro.disconnect());
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
measure(overlay) {
|
|
1166
|
+
const host = overlay.parentElement;
|
|
1167
|
+
overlay.dataset.sklMeasure = "";
|
|
1168
|
+
if (host && host.clientWidth > 0) overlay.style.width = `${host.clientWidth}px`;
|
|
1169
|
+
const height = overlay.getBoundingClientRect().height;
|
|
1170
|
+
overlay.style.removeProperty("width");
|
|
1171
|
+
delete overlay.dataset.sklMeasure;
|
|
1172
|
+
return height;
|
|
1173
|
+
}
|
|
1174
|
+
mountMedia(entry, overlay) {
|
|
1175
|
+
const host = entry.host;
|
|
1176
|
+
const parent = host.parentElement;
|
|
1177
|
+
if (!parent) return;
|
|
1178
|
+
let position = "";
|
|
1179
|
+
try {
|
|
1180
|
+
position = getComputedStyle(parent).position;
|
|
1181
|
+
} catch {
|
|
1182
|
+
position = "static";
|
|
1183
|
+
}
|
|
1184
|
+
if (position === "static") {
|
|
1185
|
+
entry.prevParentPosition = parent.style.position;
|
|
1186
|
+
parent.style.position = "relative";
|
|
1187
|
+
overlay.dataset.sklPatched = "1";
|
|
1188
|
+
}
|
|
1189
|
+
parent.appendChild(overlay);
|
|
1190
|
+
entry.container = parent;
|
|
1191
|
+
entry.prevVisibility = host.style.visibility;
|
|
1192
|
+
host.style.visibility = "hidden";
|
|
1193
|
+
const sync = () => {
|
|
1194
|
+
if (!overlay.isConnected) return;
|
|
1195
|
+
const parentRect = parent.getBoundingClientRect();
|
|
1196
|
+
const rect = host.getBoundingClientRect();
|
|
1197
|
+
overlay.style.left = `${rect.left - parentRect.left - parent.clientLeft}px`;
|
|
1198
|
+
overlay.style.top = `${rect.top - parentRect.top - parent.clientTop}px`;
|
|
1199
|
+
overlay.style.width = `${rect.width}px`;
|
|
1200
|
+
overlay.style.height = `${rect.height}px`;
|
|
1201
|
+
};
|
|
1202
|
+
sync();
|
|
1203
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
1204
|
+
const ro = new ResizeObserver(sync);
|
|
1205
|
+
ro.observe(host);
|
|
1206
|
+
ro.observe(parent);
|
|
1207
|
+
entry.cleanup.push(() => ro.disconnect());
|
|
1208
|
+
}
|
|
1209
|
+
if (typeof window !== "undefined") {
|
|
1210
|
+
window.addEventListener("resize", sync);
|
|
1211
|
+
entry.cleanup.push(() => window.removeEventListener("resize", sync));
|
|
1212
|
+
}
|
|
1213
|
+
entry.cleanup.push(() => {
|
|
1214
|
+
if (overlay.dataset.sklPatched) parent.style.position = entry.prevParentPosition ?? "";
|
|
1215
|
+
if (entry.prevVisibility !== void 0) host.style.visibility = entry.prevVisibility;
|
|
1216
|
+
});
|
|
1217
|
+
}
|
|
1218
|
+
repaint(entry) {
|
|
1219
|
+
if (entry.state !== "shown" || !entry.overlay || !entry.overlay.isConnected) return;
|
|
1220
|
+
const overlay = buildOverlay({
|
|
1221
|
+
host: entry.host,
|
|
1222
|
+
spec: entry.spec,
|
|
1223
|
+
media: entry.media,
|
|
1224
|
+
preset: entry.preset,
|
|
1225
|
+
theme: this.themeOf(entry.host)
|
|
1226
|
+
});
|
|
1227
|
+
overlay.dataset.sklShow = "1";
|
|
1228
|
+
if (this.resolved.debug) overlay.setAttribute("data-skl-debug", "");
|
|
1229
|
+
entry.overlay.replaceWith(overlay);
|
|
1230
|
+
entry.overlay = overlay;
|
|
1231
|
+
}
|
|
1232
|
+
finish(entry) {
|
|
1233
|
+
if (entry.state === "done") return;
|
|
1234
|
+
const wasShown = entry.state === "shown";
|
|
1235
|
+
entry.state = "done";
|
|
1236
|
+
this.clearTimers(entry);
|
|
1237
|
+
const wait = wasShown ? Math.max(0, this.resolved.minVisible - (now() - entry.shownAt)) : 0;
|
|
1238
|
+
if (!entry.overlay) {
|
|
1239
|
+
this.teardown(entry, false);
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
entry.hideTimer = setTimeout(() => this.teardown(entry, false), wait);
|
|
1243
|
+
}
|
|
1244
|
+
teardown(entry, immediate) {
|
|
1245
|
+
this.entries.delete(entry.host);
|
|
1246
|
+
this.clearTimers(entry);
|
|
1247
|
+
for (const fn of entry.cleanup) {
|
|
1248
|
+
try {
|
|
1249
|
+
fn();
|
|
1250
|
+
} catch {
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
entry.cleanup = [];
|
|
1254
|
+
const host = entry.host;
|
|
1255
|
+
if (entry.prevMinHeight !== void 0) host.style.minHeight = entry.prevMinHeight;
|
|
1256
|
+
host.classList.remove("skl-host");
|
|
1257
|
+
if (!entry.overlay) {
|
|
1258
|
+
if (host.dataset.sklState === "loading") delete host.dataset.sklState;
|
|
1259
|
+
delete host.dataset.sklShape;
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
const overlay = entry.overlay;
|
|
1263
|
+
host.dataset.sklState = "done";
|
|
1264
|
+
const cleanup = () => {
|
|
1265
|
+
overlay.remove();
|
|
1266
|
+
if (host.dataset.sklState === "done") delete host.dataset.sklState;
|
|
1267
|
+
delete host.dataset.sklShape;
|
|
1268
|
+
overlay.remove();
|
|
1269
|
+
};
|
|
1270
|
+
if (immediate || this.prefersReducedMotion()) {
|
|
1271
|
+
cleanup();
|
|
1272
|
+
} else {
|
|
1273
|
+
overlay.dataset.sklShow = "0";
|
|
1274
|
+
entry.fadeTimer = setTimeout(cleanup, 220);
|
|
1275
|
+
}
|
|
1276
|
+
this.stats.hidden++;
|
|
1277
|
+
this.resolved.onHide?.(host);
|
|
1278
|
+
if (this.started) setTimeout(() => this.scan(host), 0);
|
|
1279
|
+
}
|
|
1280
|
+
themeOf(host) {
|
|
1281
|
+
return inheritedTheme(host) ?? this.resolved.theme;
|
|
1282
|
+
}
|
|
1283
|
+
prefersReducedMotion() {
|
|
1284
|
+
if (!this.resolved.respectReducedMotion || typeof matchMedia !== "function") return false;
|
|
1285
|
+
try {
|
|
1286
|
+
return matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1287
|
+
} catch {
|
|
1288
|
+
return false;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
clearTimers(entry) {
|
|
1292
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
1293
|
+
if (entry.guard) clearTimeout(entry.guard);
|
|
1294
|
+
if (entry.hideTimer) clearTimeout(entry.hideTimer);
|
|
1295
|
+
entry.timer = null;
|
|
1296
|
+
entry.guard = null;
|
|
1297
|
+
entry.hideTimer = null;
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
// src/core/singleton.ts
|
|
1302
|
+
var KEY = /* @__PURE__ */ Symbol.for("skeleton-load:default");
|
|
1303
|
+
function bag() {
|
|
1304
|
+
const root = globalThis;
|
|
1305
|
+
if (!root[KEY]) root[KEY] = {};
|
|
1306
|
+
return root[KEY];
|
|
1307
|
+
}
|
|
1308
|
+
function getEngine(options) {
|
|
1309
|
+
const holder = bag();
|
|
1310
|
+
if (!holder.engine) holder.engine = new SkeletonEngine(options);
|
|
1311
|
+
return holder.engine;
|
|
1312
|
+
}
|
|
1313
|
+
function ensureStarted(options) {
|
|
1314
|
+
const engine = getEngine(options);
|
|
1315
|
+
return engine.start();
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
// src/react/index.tsx
|
|
1319
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? react.useLayoutEffect : react.useEffect;
|
|
1320
|
+
function mergeRefs(...refs) {
|
|
1321
|
+
return (value) => {
|
|
1322
|
+
for (const ref of refs) {
|
|
1323
|
+
if (!ref) continue;
|
|
1324
|
+
if (typeof ref === "function") ref(value);
|
|
1325
|
+
else ref.current = value;
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
var Skeleton = react.forwardRef(function Skeleton2(props, forwardedRef) {
|
|
1330
|
+
const {
|
|
1331
|
+
loading = false,
|
|
1332
|
+
shape = "auto",
|
|
1333
|
+
preset,
|
|
1334
|
+
lines,
|
|
1335
|
+
ratio,
|
|
1336
|
+
height,
|
|
1337
|
+
as: Tag = "div",
|
|
1338
|
+
children,
|
|
1339
|
+
...rest
|
|
1340
|
+
} = props;
|
|
1341
|
+
const localRef = react.useRef(null);
|
|
1342
|
+
useIsomorphicLayoutEffect(() => {
|
|
1343
|
+
ensureStarted();
|
|
1344
|
+
if (localRef.current) getEngine().refresh(localRef.current);
|
|
1345
|
+
}, []);
|
|
1346
|
+
react.useEffect(() => {
|
|
1347
|
+
const element = localRef.current;
|
|
1348
|
+
if (!element) return;
|
|
1349
|
+
element.setAttribute("data-skeleton-state", loading ? "loading" : "done");
|
|
1350
|
+
getEngine().refresh(element);
|
|
1351
|
+
}, [loading, shape, preset, lines, ratio, height]);
|
|
1352
|
+
return react.createElement(
|
|
1353
|
+
Tag,
|
|
1354
|
+
{
|
|
1355
|
+
ref: mergeRefs(localRef, forwardedRef),
|
|
1356
|
+
"data-skeleton": shape,
|
|
1357
|
+
"data-skeleton-state": loading ? "loading" : "done",
|
|
1358
|
+
"data-skeleton-preset": preset,
|
|
1359
|
+
"data-skeleton-lines": lines,
|
|
1360
|
+
"data-skeleton-ratio": ratio,
|
|
1361
|
+
"data-skeleton-h": height,
|
|
1362
|
+
...rest
|
|
1363
|
+
},
|
|
1364
|
+
children
|
|
1365
|
+
);
|
|
1366
|
+
});
|
|
1367
|
+
var SkeletonGroup = Skeleton;
|
|
1368
|
+
function useSkeleton(loading, options = {}) {
|
|
1369
|
+
return {
|
|
1370
|
+
"data-skeleton": options.shape ?? "auto",
|
|
1371
|
+
"data-skeleton-state": loading ? "loading" : "done",
|
|
1372
|
+
"data-skeleton-preset": options.preset,
|
|
1373
|
+
"data-skeleton-lines": options.lines,
|
|
1374
|
+
"data-skeleton-ratio": options.ratio,
|
|
1375
|
+
"data-skeleton-h": options.height
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
function startSkeleton() {
|
|
1379
|
+
ensureStarted();
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
exports.Skeleton = Skeleton;
|
|
1383
|
+
exports.SkeletonGroup = SkeletonGroup;
|
|
1384
|
+
exports.startSkeleton = startSkeleton;
|
|
1385
|
+
exports.useSkeleton = useSkeleton;
|
|
1386
|
+
//# sourceMappingURL=index.cjs.map
|
|
1387
|
+
//# sourceMappingURL=index.cjs.map
|