Skeleton.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. import { c as C, g as N, m as D, d as o, aI as G, u as W, i as j } from "./index2.js";
  2. import { defineComponent as I, createVNode as c } from "vue";
  3. const z = () => ({
  4. prefixCls: String,
  5. width: {
  6. type: [Number, String]
  7. }
  8. }), O = I({
  9. compatConfig: {
  10. MODE: 3
  11. },
  12. name: "SkeletonTitle",
  13. props: z(),
  14. setup(e) {
  15. return () => {
  16. const {
  17. prefixCls: t,
  18. width: n
  19. } = e, r = typeof n == "number" ? `${n}px` : n;
  20. return c("h3", {
  21. class: t,
  22. style: {
  23. width: r
  24. }
  25. }, null);
  26. };
  27. }
  28. }), X = () => ({
  29. prefixCls: String,
  30. width: {
  31. type: [Number, String, Array]
  32. },
  33. rows: Number
  34. }), q = I({
  35. compatConfig: {
  36. MODE: 3
  37. },
  38. name: "SkeletonParagraph",
  39. props: X(),
  40. setup(e) {
  41. const t = (n) => {
  42. const {
  43. width: r,
  44. rows: l = 2
  45. } = e;
  46. if (Array.isArray(r))
  47. return r[n];
  48. if (l - 1 === n)
  49. return r;
  50. };
  51. return () => {
  52. const {
  53. prefixCls: n,
  54. rows: r
  55. } = e, l = [...Array(r)].map((i, a) => {
  56. const d = t(a);
  57. return c("li", {
  58. key: a,
  59. style: {
  60. width: typeof d == "number" ? `${d}px` : d
  61. }
  62. }, null);
  63. });
  64. return c("ul", {
  65. class: n
  66. }, [l]);
  67. };
  68. }
  69. }), le = () => ({
  70. prefixCls: String,
  71. size: [String, Number],
  72. shape: String,
  73. active: {
  74. type: Boolean,
  75. default: void 0
  76. }
  77. }), L = (e) => {
  78. const {
  79. prefixCls: t,
  80. size: n,
  81. shape: r
  82. } = e, l = C({
  83. [`${t}-lg`]: n === "large",
  84. [`${t}-sm`]: n === "small"
  85. }), i = C({
  86. [`${t}-circle`]: r === "circle",
  87. [`${t}-square`]: r === "square",
  88. [`${t}-round`]: r === "round"
  89. }), a = typeof n == "number" ? {
  90. width: `${n}px`,
  91. height: `${n}px`,
  92. lineHeight: `${n}px`
  93. } : {};
  94. return c("span", {
  95. class: C(t, l, i),
  96. style: a
  97. }, null);
  98. };
  99. L.displayName = "SkeletonElement";
  100. const F = new G("ant-skeleton-loading", {
  101. "0%": {
  102. transform: "translateX(-37.5%)"
  103. },
  104. "100%": {
  105. transform: "translateX(37.5%)"
  106. }
  107. }), v = (e) => ({
  108. height: e,
  109. lineHeight: `${e}px`
  110. }), m = (e) => o({
  111. width: e
  112. }, v(e)), _ = (e) => ({
  113. position: "relative",
  114. // fix https://github.com/ant-design/ant-design/issues/36444
  115. // https://monshin.github.io/202109/css/safari-border-radius-overflow-hidden/
  116. /* stylelint-disable-next-line property-no-vendor-prefix,value-no-vendor-prefix */
  117. zIndex: 0,
  118. overflow: "hidden",
  119. background: "transparent",
  120. "&::after": {
  121. position: "absolute",
  122. top: 0,
  123. insetInlineEnd: "-150%",
  124. bottom: 0,
  125. insetInlineStart: "-150%",
  126. background: e.skeletonLoadingBackground,
  127. animationName: F,
  128. animationDuration: e.skeletonLoadingMotionDuration,
  129. animationTimingFunction: "ease",
  130. animationIterationCount: "infinite",
  131. content: '""'
  132. }
  133. }), P = (e) => o({
  134. width: e * 5,
  135. minWidth: e * 5
  136. }, v(e)), K = (e) => {
  137. const {
  138. skeletonAvatarCls: t,
  139. color: n,
  140. controlHeight: r,
  141. controlHeightLG: l,
  142. controlHeightSM: i
  143. } = e;
  144. return {
  145. [`${t}`]: o({
  146. display: "inline-block",
  147. verticalAlign: "top",
  148. background: n
  149. }, m(r)),
  150. [`${t}${t}-circle`]: {
  151. borderRadius: "50%"
  152. },
  153. [`${t}${t}-lg`]: o({}, m(l)),
  154. [`${t}${t}-sm`]: o({}, m(i))
  155. };
  156. }, V = (e) => {
  157. const {
  158. controlHeight: t,
  159. borderRadiusSM: n,
  160. skeletonInputCls: r,
  161. controlHeightLG: l,
  162. controlHeightSM: i,
  163. color: a
  164. } = e;
  165. return {
  166. [`${r}`]: o({
  167. display: "inline-block",
  168. verticalAlign: "top",
  169. background: a,
  170. borderRadius: n
  171. }, P(t)),
  172. [`${r}-lg`]: o({}, P(l)),
  173. [`${r}-sm`]: o({}, P(i))
  174. };
  175. }, M = (e) => o({
  176. width: e
  177. }, v(e)), J = (e) => {
  178. const {
  179. skeletonImageCls: t,
  180. imageSizeBase: n,
  181. color: r,
  182. borderRadiusSM: l
  183. } = e;
  184. return {
  185. [`${t}`]: o(o({
  186. display: "flex",
  187. alignItems: "center",
  188. justifyContent: "center",
  189. verticalAlign: "top",
  190. background: r,
  191. borderRadius: l
  192. }, M(n * 2)), {
  193. [`${t}-path`]: {
  194. fill: "#bfbfbf"
  195. },
  196. [`${t}-svg`]: o(o({}, M(n)), {
  197. maxWidth: n * 4,
  198. maxHeight: n * 4
  199. }),
  200. [`${t}-svg${t}-svg-circle`]: {
  201. borderRadius: "50%"
  202. }
  203. }),
  204. [`${t}${t}-circle`]: {
  205. borderRadius: "50%"
  206. }
  207. };
  208. }, x = (e, t, n) => {
  209. const {
  210. skeletonButtonCls: r
  211. } = e;
  212. return {
  213. [`${n}${r}-circle`]: {
  214. width: t,
  215. minWidth: t,
  216. borderRadius: "50%"
  217. },
  218. [`${n}${r}-round`]: {
  219. borderRadius: t
  220. }
  221. };
  222. }, E = (e) => o({
  223. width: e * 2,
  224. minWidth: e * 2
  225. }, v(e)), Q = (e) => {
  226. const {
  227. borderRadiusSM: t,
  228. skeletonButtonCls: n,
  229. controlHeight: r,
  230. controlHeightLG: l,
  231. controlHeightSM: i,
  232. color: a
  233. } = e;
  234. return o(o(o(o(o({
  235. [`${n}`]: o({
  236. display: "inline-block",
  237. verticalAlign: "top",
  238. background: a,
  239. borderRadius: t,
  240. width: r * 2,
  241. minWidth: r * 2
  242. }, E(r))
  243. }, x(e, r, n)), {
  244. [`${n}-lg`]: o({}, E(l))
  245. }), x(e, l, `${n}-lg`)), {
  246. [`${n}-sm`]: o({}, E(i))
  247. }), x(e, i, `${n}-sm`));
  248. }, U = (e) => {
  249. const {
  250. componentCls: t,
  251. skeletonAvatarCls: n,
  252. skeletonTitleCls: r,
  253. skeletonParagraphCls: l,
  254. skeletonButtonCls: i,
  255. skeletonInputCls: a,
  256. skeletonImageCls: d,
  257. controlHeight: y,
  258. controlHeightLG: f,
  259. controlHeightSM: p,
  260. color: g,
  261. padding: w,
  262. marginSM: B,
  263. borderRadius: s,
  264. skeletonTitleHeight: h,
  265. skeletonBlockRadius: u,
  266. skeletonParagraphLineHeight: $,
  267. controlHeightXS: k,
  268. skeletonParagraphMarginTop: S
  269. } = e;
  270. return {
  271. [`${t}`]: {
  272. display: "table",
  273. width: "100%",
  274. [`${t}-header`]: {
  275. display: "table-cell",
  276. paddingInlineEnd: w,
  277. verticalAlign: "top",
  278. // Avatar
  279. [`${n}`]: o({
  280. display: "inline-block",
  281. verticalAlign: "top",
  282. background: g
  283. }, m(y)),
  284. [`${n}-circle`]: {
  285. borderRadius: "50%"
  286. },
  287. [`${n}-lg`]: o({}, m(f)),
  288. [`${n}-sm`]: o({}, m(p))
  289. },
  290. [`${t}-content`]: {
  291. display: "table-cell",
  292. width: "100%",
  293. verticalAlign: "top",
  294. // Title
  295. [`${r}`]: {
  296. width: "100%",
  297. height: h,
  298. background: g,
  299. borderRadius: u,
  300. [`+ ${l}`]: {
  301. marginBlockStart: p
  302. }
  303. },
  304. // paragraph
  305. [`${l}`]: {
  306. padding: 0,
  307. "> li": {
  308. width: "100%",
  309. height: $,
  310. listStyle: "none",
  311. background: g,
  312. borderRadius: u,
  313. "+ li": {
  314. marginBlockStart: k
  315. }
  316. }
  317. },
  318. [`${l}> li:last-child:not(:first-child):not(:nth-child(2))`]: {
  319. width: "61%"
  320. }
  321. },
  322. [`&-round ${t}-content`]: {
  323. [`${r}, ${l} > li`]: {
  324. borderRadius: s
  325. }
  326. }
  327. },
  328. [`${t}-with-avatar ${t}-content`]: {
  329. // Title
  330. [`${r}`]: {
  331. marginBlockStart: B,
  332. [`+ ${l}`]: {
  333. marginBlockStart: S
  334. }
  335. }
  336. },
  337. // Skeleton element
  338. [`${t}${t}-element`]: o(o(o(o({
  339. display: "inline-block",
  340. width: "auto"
  341. }, Q(e)), K(e)), V(e)), J(e)),
  342. // Skeleton Block Button, Input
  343. [`${t}${t}-block`]: {
  344. width: "100%",
  345. [`${i}`]: {
  346. width: "100%"
  347. },
  348. [`${a}`]: {
  349. width: "100%"
  350. }
  351. },
  352. // With active animation
  353. [`${t}${t}-active`]: {
  354. [`
  355. ${r},
  356. ${l} > li,
  357. ${n},
  358. ${i},
  359. ${a},
  360. ${d}
  361. `]: o({}, _(e))
  362. }
  363. };
  364. }, Y = N("Skeleton", (e) => {
  365. const {
  366. componentCls: t
  367. } = e, n = D(e, {
  368. skeletonAvatarCls: `${t}-avatar`,
  369. skeletonTitleCls: `${t}-title`,
  370. skeletonParagraphCls: `${t}-paragraph`,
  371. skeletonButtonCls: `${t}-button`,
  372. skeletonInputCls: `${t}-input`,
  373. skeletonImageCls: `${t}-image`,
  374. imageSizeBase: e.controlHeight * 1.5,
  375. skeletonTitleHeight: e.controlHeight / 2,
  376. skeletonBlockRadius: e.borderRadiusSM,
  377. skeletonParagraphLineHeight: e.controlHeight / 2,
  378. skeletonParagraphMarginTop: e.marginLG + e.marginXXS,
  379. borderRadius: 100,
  380. skeletonLoadingBackground: `linear-gradient(90deg, ${e.color} 25%, ${e.colorGradientEnd} 37%, ${e.color} 63%)`,
  381. skeletonLoadingMotionDuration: "1.4s"
  382. });
  383. return [U(n)];
  384. }, (e) => {
  385. const {
  386. colorFillContent: t,
  387. colorFill: n
  388. } = e;
  389. return {
  390. color: t,
  391. colorGradientEnd: n
  392. };
  393. }), Z = () => ({
  394. active: {
  395. type: Boolean,
  396. default: void 0
  397. },
  398. loading: {
  399. type: Boolean,
  400. default: void 0
  401. },
  402. prefixCls: String,
  403. avatar: {
  404. type: [Boolean, Object],
  405. default: void 0
  406. },
  407. title: {
  408. type: [Boolean, Object],
  409. default: void 0
  410. },
  411. paragraph: {
  412. type: [Boolean, Object],
  413. default: void 0
  414. },
  415. round: {
  416. type: Boolean,
  417. default: void 0
  418. }
  419. });
  420. function R(e) {
  421. return e && typeof e == "object" ? e : {};
  422. }
  423. function ee(e, t) {
  424. return e && !t ? {
  425. size: "large",
  426. shape: "square"
  427. } : {
  428. size: "large",
  429. shape: "circle"
  430. };
  431. }
  432. function te(e, t) {
  433. return !e && t ? {
  434. width: "38%"
  435. } : e && t ? {
  436. width: "50%"
  437. } : {};
  438. }
  439. function ne(e, t) {
  440. const n = {};
  441. return (!e || !t) && (n.width = "61%"), !e && t ? n.rows = 3 : n.rows = 2, n;
  442. }
  443. const ie = I({
  444. compatConfig: {
  445. MODE: 3
  446. },
  447. name: "ASkeleton",
  448. props: j(Z(), {
  449. avatar: !1,
  450. title: !0,
  451. paragraph: !0
  452. }),
  453. setup(e, t) {
  454. let {
  455. slots: n
  456. } = t;
  457. const {
  458. prefixCls: r,
  459. direction: l
  460. } = W("skeleton", e), [i, a] = Y(r);
  461. return () => {
  462. var d;
  463. const {
  464. loading: y,
  465. avatar: f,
  466. title: p,
  467. paragraph: g,
  468. active: w,
  469. round: B
  470. } = e, s = r.value;
  471. if (y || e.loading === void 0) {
  472. const h = !!f || f === "", u = !!p || p === "", $ = !!g || g === "";
  473. let k;
  474. if (h) {
  475. const b = o(o({
  476. prefixCls: `${s}-avatar`
  477. }, ee(u, $)), R(f));
  478. k = c("div", {
  479. class: `${s}-header`
  480. }, [c(L, b, null)]);
  481. }
  482. let S;
  483. if (u || $) {
  484. let b;
  485. if (u) {
  486. const H = o(o({
  487. prefixCls: `${s}-title`
  488. }, te(h, $)), R(p));
  489. b = c(O, H, null);
  490. }
  491. let A;
  492. if ($) {
  493. const H = o(o({
  494. prefixCls: `${s}-paragraph`
  495. }, ne(h, u)), R(g));
  496. A = c(q, H, null);
  497. }
  498. S = c("div", {
  499. class: `${s}-content`
  500. }, [b, A]);
  501. }
  502. const T = C(s, {
  503. [`${s}-with-avatar`]: h,
  504. [`${s}-active`]: w,
  505. [`${s}-rtl`]: l.value === "rtl",
  506. [`${s}-round`]: B,
  507. [a.value]: !0
  508. });
  509. return i(c("div", {
  510. class: T
  511. }, [k, S]));
  512. }
  513. return (d = n.default) === null || d === void 0 ? void 0 : d.call(n);
  514. };
  515. }
  516. });
  517. export {
  518. L as E,
  519. ie as S,
  520. O as a,
  521. le as s,
  522. Y as u
  523. };