Col.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. import { g as E, m as _, d as g, u as k, bt as T, bu as w, c as F, _ as C, bq as N } from "./index2.js";
  2. import { inject as D, computed as $, provide as V, defineComponent as L, ref as R, onMounted as X, onBeforeUnmount as H, createVNode as W } from "vue";
  3. import { u as K } from "./useFlexGapSupport.js";
  4. const B = Symbol("rowContextKey"), P = (e) => {
  5. V(B, e);
  6. }, q = () => D(B, {
  7. gutter: $(() => {
  8. }),
  9. wrap: $(() => {
  10. }),
  11. supportFlexGap: $(() => {
  12. })
  13. }), J = (e) => {
  14. const {
  15. componentCls: t
  16. } = e;
  17. return {
  18. // Grid system
  19. [t]: {
  20. display: "flex",
  21. flexFlow: "row wrap",
  22. minWidth: 0,
  23. "&::before, &::after": {
  24. display: "flex"
  25. },
  26. "&-no-wrap": {
  27. flexWrap: "nowrap"
  28. },
  29. // The origin of the X-axis
  30. "&-start": {
  31. justifyContent: "flex-start"
  32. },
  33. // The center of the X-axis
  34. "&-center": {
  35. justifyContent: "center"
  36. },
  37. // The opposite of the X-axis
  38. "&-end": {
  39. justifyContent: "flex-end"
  40. },
  41. "&-space-between": {
  42. justifyContent: "space-between"
  43. },
  44. "&-space-around ": {
  45. justifyContent: "space-around"
  46. },
  47. "&-space-evenly ": {
  48. justifyContent: "space-evenly"
  49. },
  50. // Align at the top
  51. "&-top": {
  52. alignItems: "flex-start"
  53. },
  54. // Align at the center
  55. "&-middle": {
  56. alignItems: "center"
  57. },
  58. "&-bottom": {
  59. alignItems: "flex-end"
  60. }
  61. }
  62. };
  63. }, U = (e) => {
  64. const {
  65. componentCls: t
  66. } = e;
  67. return {
  68. // Grid system
  69. [t]: {
  70. position: "relative",
  71. maxWidth: "100%",
  72. // Prevent columns from collapsing when empty
  73. minHeight: 1
  74. }
  75. };
  76. }, Q = (e, t) => {
  77. const {
  78. componentCls: u,
  79. gridColumns: a
  80. } = e, o = {};
  81. for (let s = a; s >= 0; s--)
  82. s === 0 ? (o[`${u}${t}-${s}`] = {
  83. display: "none"
  84. }, o[`${u}-push-${s}`] = {
  85. insetInlineStart: "auto"
  86. }, o[`${u}-pull-${s}`] = {
  87. insetInlineEnd: "auto"
  88. }, o[`${u}${t}-push-${s}`] = {
  89. insetInlineStart: "auto"
  90. }, o[`${u}${t}-pull-${s}`] = {
  91. insetInlineEnd: "auto"
  92. }, o[`${u}${t}-offset-${s}`] = {
  93. marginInlineEnd: 0
  94. }, o[`${u}${t}-order-${s}`] = {
  95. order: 0
  96. }) : (o[`${u}${t}-${s}`] = {
  97. display: "block",
  98. flex: `0 0 ${s / a * 100}%`,
  99. maxWidth: `${s / a * 100}%`
  100. }, o[`${u}${t}-push-${s}`] = {
  101. insetInlineStart: `${s / a * 100}%`
  102. }, o[`${u}${t}-pull-${s}`] = {
  103. insetInlineEnd: `${s / a * 100}%`
  104. }, o[`${u}${t}-offset-${s}`] = {
  105. marginInlineStart: `${s / a * 100}%`
  106. }, o[`${u}${t}-order-${s}`] = {
  107. order: s
  108. });
  109. return o;
  110. }, O = (e, t) => Q(e, t), Y = (e, t, u) => ({
  111. [`@media (min-width: ${t}px)`]: g({}, O(e, u))
  112. }), Z = E("Grid", (e) => [J(e)]), z = E("Grid", (e) => {
  113. const t = _(e, {
  114. gridColumns: 24
  115. // Row is divided into 24 parts in Grid
  116. }), u = {
  117. "-sm": t.screenSMMin,
  118. "-md": t.screenMDMin,
  119. "-lg": t.screenLGMin,
  120. "-xl": t.screenXLMin,
  121. "-xxl": t.screenXXLMin
  122. };
  123. return [U(t), O(t, ""), O(t, "-xs"), Object.keys(u).map((a) => Y(t, u[a], a)).reduce((a, o) => g(g({}, a), o), {})];
  124. }), ee = () => ({
  125. align: N([String, Object]),
  126. justify: N([String, Object]),
  127. prefixCls: String,
  128. gutter: N([Number, Array, Object], 0),
  129. wrap: {
  130. type: Boolean,
  131. default: void 0
  132. }
  133. }), ue = L({
  134. compatConfig: {
  135. MODE: 3
  136. },
  137. name: "ARow",
  138. inheritAttrs: !1,
  139. props: ee(),
  140. setup(e, t) {
  141. let {
  142. slots: u,
  143. attrs: a
  144. } = t;
  145. const {
  146. prefixCls: o,
  147. direction: s
  148. } = k("row", e), [G, y] = Z(o);
  149. let b;
  150. const v = T(), x = R({
  151. xs: !0,
  152. sm: !0,
  153. md: !0,
  154. lg: !0,
  155. xl: !0,
  156. xxl: !0
  157. }), S = R({
  158. xs: !1,
  159. sm: !1,
  160. md: !1,
  161. lg: !1,
  162. xl: !1,
  163. xxl: !1
  164. }), h = (n) => $(() => {
  165. if (typeof e[n] == "string")
  166. return e[n];
  167. if (typeof e[n] != "object")
  168. return "";
  169. for (let r = 0; r < w.length; r++) {
  170. const l = w[r];
  171. if (!S.value[l]) continue;
  172. const i = e[n][l];
  173. if (i !== void 0)
  174. return i;
  175. }
  176. return "";
  177. }), f = h("align"), p = h("justify"), d = K();
  178. X(() => {
  179. b = v.value.subscribe((n) => {
  180. S.value = n;
  181. const r = e.gutter || 0;
  182. (!Array.isArray(r) && typeof r == "object" || Array.isArray(r) && (typeof r[0] == "object" || typeof r[1] == "object")) && (x.value = n);
  183. });
  184. }), H(() => {
  185. v.value.unsubscribe(b);
  186. });
  187. const m = $(() => {
  188. const n = [void 0, void 0], {
  189. gutter: r = 0
  190. } = e;
  191. return (Array.isArray(r) ? r : [r, void 0]).forEach((i, M) => {
  192. if (typeof i == "object")
  193. for (let A = 0; A < w.length; A++) {
  194. const I = w[A];
  195. if (x.value[I] && i[I] !== void 0) {
  196. n[M] = i[I];
  197. break;
  198. }
  199. }
  200. else
  201. n[M] = i;
  202. }), n;
  203. });
  204. P({
  205. gutter: m,
  206. supportFlexGap: d,
  207. wrap: $(() => e.wrap)
  208. });
  209. const j = $(() => F(o.value, {
  210. [`${o.value}-no-wrap`]: e.wrap === !1,
  211. [`${o.value}-${p.value}`]: p.value,
  212. [`${o.value}-${f.value}`]: f.value,
  213. [`${o.value}-rtl`]: s.value === "rtl"
  214. }, a.class, y.value)), c = $(() => {
  215. const n = m.value, r = {}, l = n[0] != null && n[0] > 0 ? `${n[0] / -2}px` : void 0, i = n[1] != null && n[1] > 0 ? `${n[1] / -2}px` : void 0;
  216. return l && (r.marginLeft = l, r.marginRight = l), d.value ? r.rowGap = `${n[1]}px` : i && (r.marginTop = i, r.marginBottom = i), r;
  217. });
  218. return () => {
  219. var n;
  220. return G(W("div", C(C({}, a), {}, {
  221. class: j.value,
  222. style: g(g({}, c.value), a.style)
  223. }), [(n = u.default) === null || n === void 0 ? void 0 : n.call(u)]));
  224. };
  225. }
  226. });
  227. function te(e) {
  228. return typeof e == "number" ? `${e} ${e} auto` : /^\d+(\.\d+)?(px|em|rem|%)$/.test(e) ? `0 0 ${e}` : e;
  229. }
  230. const ne = () => ({
  231. span: [String, Number],
  232. order: [String, Number],
  233. offset: [String, Number],
  234. push: [String, Number],
  235. pull: [String, Number],
  236. xs: {
  237. type: [String, Number, Object],
  238. default: void 0
  239. },
  240. sm: {
  241. type: [String, Number, Object],
  242. default: void 0
  243. },
  244. md: {
  245. type: [String, Number, Object],
  246. default: void 0
  247. },
  248. lg: {
  249. type: [String, Number, Object],
  250. default: void 0
  251. },
  252. xl: {
  253. type: [String, Number, Object],
  254. default: void 0
  255. },
  256. xxl: {
  257. type: [String, Number, Object],
  258. default: void 0
  259. },
  260. prefixCls: String,
  261. flex: [String, Number]
  262. }), re = ["xs", "sm", "md", "lg", "xl", "xxl"], ae = L({
  263. compatConfig: {
  264. MODE: 3
  265. },
  266. name: "ACol",
  267. inheritAttrs: !1,
  268. props: ne(),
  269. setup(e, t) {
  270. let {
  271. slots: u,
  272. attrs: a
  273. } = t;
  274. const {
  275. gutter: o,
  276. supportFlexGap: s,
  277. wrap: G
  278. } = q(), {
  279. prefixCls: y,
  280. direction: b
  281. } = k("col", e), [v, x] = z(y), S = $(() => {
  282. const {
  283. span: f,
  284. order: p,
  285. offset: d,
  286. push: m,
  287. pull: j
  288. } = e, c = y.value;
  289. let n = {};
  290. return re.forEach((r) => {
  291. let l = {};
  292. const i = e[r];
  293. typeof i == "number" ? l.span = i : typeof i == "object" && (l = i || {}), n = g(g({}, n), {
  294. [`${c}-${r}-${l.span}`]: l.span !== void 0,
  295. [`${c}-${r}-order-${l.order}`]: l.order || l.order === 0,
  296. [`${c}-${r}-offset-${l.offset}`]: l.offset || l.offset === 0,
  297. [`${c}-${r}-push-${l.push}`]: l.push || l.push === 0,
  298. [`${c}-${r}-pull-${l.pull}`]: l.pull || l.pull === 0,
  299. [`${c}-rtl`]: b.value === "rtl"
  300. });
  301. }), F(c, {
  302. [`${c}-${f}`]: f !== void 0,
  303. [`${c}-order-${p}`]: p,
  304. [`${c}-offset-${d}`]: d,
  305. [`${c}-push-${m}`]: m,
  306. [`${c}-pull-${j}`]: j
  307. }, n, a.class, x.value);
  308. }), h = $(() => {
  309. const {
  310. flex: f
  311. } = e, p = o.value, d = {};
  312. if (p && p[0] > 0) {
  313. const m = `${p[0] / 2}px`;
  314. d.paddingLeft = m, d.paddingRight = m;
  315. }
  316. if (p && p[1] > 0 && !s.value) {
  317. const m = `${p[1] / 2}px`;
  318. d.paddingTop = m, d.paddingBottom = m;
  319. }
  320. return f && (d.flex = te(f), G.value === !1 && !d.minWidth && (d.minWidth = 0)), d;
  321. });
  322. return () => {
  323. var f;
  324. return v(W("div", C(C({}, a), {}, {
  325. class: S.value,
  326. style: [h.value, a.style]
  327. }), [(f = u.default) === null || f === void 0 ? void 0 : f.call(u)]));
  328. };
  329. }
  330. });
  331. export {
  332. ue as A,
  333. ae as C
  334. };