skeleton-ghost-loader 2.6.3 → 2.6.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.
- package/dist/skeleton-loader.es.js +35 -29
- package/dist/skeleton-loader.umd.js +36 -47
- package/package.json +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
2
|
+
import React from "react";
|
|
3
3
|
const skeletonBgColors = {
|
|
4
4
|
text: "#ccc",
|
|
5
|
+
// lighter for text/headings
|
|
5
6
|
box: "#e0e0e0"
|
|
7
|
+
// darker for boxes/images/buttons
|
|
6
8
|
};
|
|
7
9
|
const styleCache = {};
|
|
8
10
|
function getComputedStyleFromNode(node) {
|
|
@@ -27,7 +29,7 @@ function getComputedStyleFromNode(node) {
|
|
|
27
29
|
fontSize: cs.fontSize || void 0,
|
|
28
30
|
margin: cs.margin || "0",
|
|
29
31
|
padding: cs.padding || "0",
|
|
30
|
-
borderRadius: cs.borderRadius || "
|
|
32
|
+
borderRadius: cs.borderRadius || "0px"
|
|
31
33
|
};
|
|
32
34
|
document.body.removeChild(el);
|
|
33
35
|
styleCache[key] = computed;
|
|
@@ -36,34 +38,38 @@ function getComputedStyleFromNode(node) {
|
|
|
36
38
|
const SkeletonBlock = ({ children }) => {
|
|
37
39
|
function traverse(node) {
|
|
38
40
|
if (!React.isValidElement(node)) return node;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
newProps.style = style;
|
|
62
|
-
}
|
|
63
|
-
const childrenNodes = React.Children.map(node.props.children, traverse);
|
|
64
|
-
return React.cloneElement(node, newProps, childrenNodes);
|
|
41
|
+
let newProps = { ...node.props };
|
|
42
|
+
let style = { ...newProps.style };
|
|
43
|
+
if (newProps.skeletonrequired === "y") {
|
|
44
|
+
const type = typeof node.type === "string" ? node.type : "div";
|
|
45
|
+
const defaults = getComputedStyleFromNode(node);
|
|
46
|
+
style.height = style.height || newProps.height || defaults.height || "20px";
|
|
47
|
+
style.width = style.width || newProps.width || defaults.width || "100%";
|
|
48
|
+
style.fontSize = style.fontSize || newProps.fontSize || defaults.fontSize || "16px";
|
|
49
|
+
style.margin = style.margin || newProps.margin || defaults.margin || "0";
|
|
50
|
+
style.padding = style.padding || newProps.padding || defaults.padding || "0";
|
|
51
|
+
style.borderRadius = style.borderRadius || defaults.borderRadius || "4px";
|
|
52
|
+
const isText = ["p", "span", "h1", "h2", "h3", "h4", "h5", "h6"].includes(type);
|
|
53
|
+
style.backgroundColor = isText ? skeletonBgColors.text : skeletonBgColors.box;
|
|
54
|
+
style.color = "transparent";
|
|
55
|
+
style.position = "relative";
|
|
56
|
+
style.overflow = "hidden";
|
|
57
|
+
const shimmerBase = isText ? skeletonBgColors.text : skeletonBgColors.box;
|
|
58
|
+
style.backgroundImage = `linear-gradient(90deg, ${shimmerBase} 0%, #f5f5f5 50%, ${shimmerBase} 100%)`;
|
|
59
|
+
style.backgroundSize = "200% 100%";
|
|
60
|
+
style.animation = "shimmer 1.5s infinite";
|
|
61
|
+
delete newProps.skeletonrequired;
|
|
62
|
+
newProps.style = style;
|
|
65
63
|
}
|
|
66
|
-
|
|
64
|
+
if (typeof node.type === "function") {
|
|
65
|
+
const rendered = node.type(newProps);
|
|
66
|
+
return traverse(rendered);
|
|
67
|
+
}
|
|
68
|
+
const childrenNodes = React.Children.map(
|
|
69
|
+
node.props.children,
|
|
70
|
+
(child) => traverse(child)
|
|
71
|
+
);
|
|
72
|
+
return React.cloneElement(node, newProps, childrenNodes);
|
|
67
73
|
}
|
|
68
74
|
const result = React.Children.map(children, traverse);
|
|
69
75
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -2,26 +2,11 @@
|
|
|
2
2
|
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("react")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "react"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.SkeletonGhostLoader = {}, global.jsxRuntime, global.React));
|
|
3
3
|
})(this, function(exports2, jsxRuntime, React) {
|
|
4
4
|
"use strict";
|
|
5
|
-
function _interopNamespaceDefault(e) {
|
|
6
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
7
|
-
if (e) {
|
|
8
|
-
for (const k in e) {
|
|
9
|
-
if (k !== "default") {
|
|
10
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: () => e[k]
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
n.default = e;
|
|
19
|
-
return Object.freeze(n);
|
|
20
|
-
}
|
|
21
|
-
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
22
5
|
const skeletonBgColors = {
|
|
23
6
|
text: "#ccc",
|
|
7
|
+
// lighter for text/headings
|
|
24
8
|
box: "#e0e0e0"
|
|
9
|
+
// darker for boxes/images/buttons
|
|
25
10
|
};
|
|
26
11
|
const styleCache = {};
|
|
27
12
|
function getComputedStyleFromNode(node) {
|
|
@@ -46,7 +31,7 @@
|
|
|
46
31
|
fontSize: cs.fontSize || void 0,
|
|
47
32
|
margin: cs.margin || "0",
|
|
48
33
|
padding: cs.padding || "0",
|
|
49
|
-
borderRadius: cs.borderRadius || "
|
|
34
|
+
borderRadius: cs.borderRadius || "0px"
|
|
50
35
|
};
|
|
51
36
|
document.body.removeChild(el);
|
|
52
37
|
styleCache[key] = computed;
|
|
@@ -54,37 +39,41 @@
|
|
|
54
39
|
}
|
|
55
40
|
const SkeletonBlock = ({ children }) => {
|
|
56
41
|
function traverse(node) {
|
|
57
|
-
if (!
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
return
|
|
42
|
+
if (!React.isValidElement(node)) return node;
|
|
43
|
+
let newProps = { ...node.props };
|
|
44
|
+
let style = { ...newProps.style };
|
|
45
|
+
if (newProps.skeletonrequired === "y") {
|
|
46
|
+
const type = typeof node.type === "string" ? node.type : "div";
|
|
47
|
+
const defaults = getComputedStyleFromNode(node);
|
|
48
|
+
style.height = style.height || newProps.height || defaults.height || "20px";
|
|
49
|
+
style.width = style.width || newProps.width || defaults.width || "100%";
|
|
50
|
+
style.fontSize = style.fontSize || newProps.fontSize || defaults.fontSize || "16px";
|
|
51
|
+
style.margin = style.margin || newProps.margin || defaults.margin || "0";
|
|
52
|
+
style.padding = style.padding || newProps.padding || defaults.padding || "0";
|
|
53
|
+
style.borderRadius = style.borderRadius || defaults.borderRadius || "4px";
|
|
54
|
+
const isText = ["p", "span", "h1", "h2", "h3", "h4", "h5", "h6"].includes(type);
|
|
55
|
+
style.backgroundColor = isText ? skeletonBgColors.text : skeletonBgColors.box;
|
|
56
|
+
style.color = "transparent";
|
|
57
|
+
style.position = "relative";
|
|
58
|
+
style.overflow = "hidden";
|
|
59
|
+
const shimmerBase = isText ? skeletonBgColors.text : skeletonBgColors.box;
|
|
60
|
+
style.backgroundImage = `linear-gradient(90deg, ${shimmerBase} 0%, #f5f5f5 50%, ${shimmerBase} 100%)`;
|
|
61
|
+
style.backgroundSize = "200% 100%";
|
|
62
|
+
style.animation = "shimmer 1.5s infinite";
|
|
63
|
+
delete newProps.skeletonrequired;
|
|
64
|
+
newProps.style = style;
|
|
65
|
+
}
|
|
66
|
+
if (typeof node.type === "function") {
|
|
67
|
+
const rendered = node.type(newProps);
|
|
68
|
+
return traverse(rendered);
|
|
84
69
|
}
|
|
85
|
-
|
|
70
|
+
const childrenNodes = React.Children.map(
|
|
71
|
+
node.props.children,
|
|
72
|
+
(child) => traverse(child)
|
|
73
|
+
);
|
|
74
|
+
return React.cloneElement(node, newProps, childrenNodes);
|
|
86
75
|
}
|
|
87
|
-
const result =
|
|
76
|
+
const result = React.Children.map(children, traverse);
|
|
88
77
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
89
78
|
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `
|
|
90
79
|
@keyframes shimmer {
|