ray-template/assets/Grid-b5fe1ca4.js
2023-07-05 17:16:47 +08:00

2 lines
6.1 KiB
JavaScript

import{b0 as Q,l as X,b1 as w,f as F,ar as B,i as z,V as H,b2 as U,x as Y,b3 as J}from"./index-1016cc88.js";import{H as O,l as S,r as N,j as W,d as P,f as Z,h as E,a as K,b as ee,q as te,x as A,G as j,I as k}from"./vue-vendor-dfef56cd.js";function se(e){if(typeof e=="number")return{"":e.toString()};const t={};return e.split(/ +/).forEach(r=>{if(r==="")return;const[n,s]=r.split(":");s===void 0?t[""]=n:t[n]=s}),t}function G(e,t){var r;if(e==null)return;const n=se(e);if(t===void 0)return n[""];if(typeof t=="string")return(r=n[t])!==null&&r!==void 0?r:n[""];if(Array.isArray(t)){for(let s=t.length-1;s>=0;--s){const i=t[s];if(i in n)return n[i]}return n[""]}else{let s,i=-1;return Object.keys(n).forEach(o=>{const a=Number(o);!Number.isNaN(a)&&t>=a&&a>=i&&(i=a,s=n[o])}),s}}function ne(e){var t;const r=(t=e.dirs)===null||t===void 0?void 0:t.find(({dir:n})=>n===O);return!!(r&&r.value===!1)}const re={xs:0,s:640,m:1024,l:1280,xl:1536,"2xl":1920};function ie(e){return`(min-width: ${e}px)`}const C={};function oe(e=re){if(!Q)return S(()=>[]);if(typeof window.matchMedia!="function")return S(()=>[]);const t=N({}),r=Object.keys(e),n=(s,i)=>{s.matches?t.value[i]=!0:t.value[i]=!1};return r.forEach(s=>{const i=e[s];let o,a;C[i]===void 0?(o=window.matchMedia(ie(i)),o.addEventListener?o.addEventListener("change",d=>{a.forEach(f=>{f(d,s)})}):o.addListener&&o.addListener(d=>{a.forEach(f=>{f(d,s)})}),a=new Set,C[i]={mql:o,cbs:a}):(o=C[i].mql,a=C[i].cbs),a.add(n),o.matches&&a.forEach(d=>{d(o,s)})}),W(()=>{r.forEach(s=>{const{cbs:i}=C[e[s]];i.has(n)&&i.delete(n)})}),S(()=>{const{value:s}=t;return r.filter(i=>s[i])})}const V=1,T=X("n-grid"),L=1,ae={span:{type:[Number,String],default:L},offset:{type:[Number,String],default:0},suffix:Boolean,privateOffset:Number,privateSpan:Number,privateColStart:Number,privateShow:{type:Boolean,default:!0}},pe=P({__GRID_ITEM__:!0,name:"GridItem",alias:["Gi"],props:ae,setup(){const{isSsrRef:e,xGapRef:t,itemStyleRef:r,overflowRef:n,layoutShiftDisabledRef:s}=Z(T),i=K();return{overflow:n,itemStyle:r,layoutShiftDisabled:s,mergedXGap:S(()=>w(t.value||0)),deriveStyle:()=>{e.value;const{privateSpan:o=L,privateShow:a=!0,privateColStart:d=void 0,privateOffset:f=0}=i.vnode.props,{value:x}=t,g=w(x||0);return{display:a?"":"none",gridColumn:`${d??`span ${o}`} / span ${o}`,marginLeft:f?`calc((100% - (${o} - 1) * ${g}) / ${o} * ${f} + ${g} * ${f})`:""}}}},render(){var e,t;if(this.layoutShiftDisabled){const{span:r,offset:n,mergedXGap:s}=this;return E("div",{style:{gridColumn:`span ${r} / span ${r}`,marginLeft:n?`calc((100% - (${r} - 1) * ${s}) / ${r} * ${n} + ${s} * ${n})`:""}},this.$slots)}return E("div",{style:[this.itemStyle,this.deriveStyle()]},(t=(e=this.$slots).default)===null||t===void 0?void 0:t.call(e,{overflow:this.overflow}))}}),le={xs:0,s:640,m:1024,l:1280,xl:1536,xxl:1920},q=24,D="__ssr__",fe={layoutShiftDisabled:Boolean,responsive:{type:[String,Boolean],default:"self"},cols:{type:[Number,String],default:q},itemResponsive:Boolean,collapsed:Boolean,collapsedRows:{type:Number,default:1},itemStyle:[Object,String],xGap:{type:[Number,String],default:0},yGap:{type:[Number,String],default:0}},ce=P({name:"Grid",inheritAttrs:!1,props:fe,setup(e){const{mergedClsPrefixRef:t,mergedBreakpointsRef:r}=F(e),n=/^\d+$/,s=N(void 0),i=oe((r==null?void 0:r.value)||le),o=B(()=>!!(e.itemResponsive||!n.test(e.cols.toString())||!n.test(e.xGap.toString())||!n.test(e.yGap.toString()))),a=S(()=>{if(o.value)return e.responsive==="self"?s.value:i.value}),d=B(()=>{var u;return(u=Number(G(e.cols.toString(),a.value)))!==null&&u!==void 0?u:q}),f=B(()=>G(e.xGap.toString(),a.value)),x=B(()=>G(e.yGap.toString(),a.value)),g=u=>{s.value=u.contentRect.width},v=u=>{U(g,u)},_=N(!1),y=S(()=>{if(e.responsive==="self")return v}),p=N(!1),h=N();return ee(()=>{const{value:u}=h;u&&u.hasAttribute(D)&&(u.removeAttribute(D),p.value=!0)}),te(T,{layoutShiftDisabledRef:A(e,"layoutShiftDisabled"),isSsrRef:p,itemStyleRef:A(e,"itemStyle"),xGapRef:f,overflowRef:_}),{isSsr:!z,contentEl:h,mergedClsPrefix:t,style:S(()=>e.layoutShiftDisabled?{width:"100%",display:"grid",gridTemplateColumns:`repeat(${e.cols}, minmax(0, 1fr))`,columnGap:w(e.xGap),rowGap:w(e.yGap)}:{width:"100%",display:"grid",gridTemplateColumns:`repeat(${d.value}, minmax(0, 1fr))`,columnGap:w(f.value),rowGap:w(x.value)}),isResponsive:o,responsiveQuery:a,responsiveCols:d,handleResize:y,overflow:_}},render(){if(this.layoutShiftDisabled)return E("div",j({ref:"contentEl",class:`${this.mergedClsPrefix}-grid`,style:this.style},this.$attrs),this.$slots);const e=()=>{var t,r,n,s,i,o,a;this.overflow=!1;const d=Y(J(this)),f=[],{collapsed:x,collapsedRows:g,responsiveCols:v,responsiveQuery:_}=this;d.forEach(l=>{var $,m,c,R;if((($=l==null?void 0:l.type)===null||$===void 0?void 0:$.__GRID_ITEM__)!==!0)return;if(ne(l)){const b=k(l);b.props?b.props.privateShow=!1:b.props={privateShow:!1},f.push({child:b,rawChildSpan:0});return}l.dirs=((m=l.dirs)===null||m===void 0?void 0:m.filter(({dir:b})=>b!==O))||null;const I=k(l),M=Number((R=G((c=I.props)===null||c===void 0?void 0:c.span,_))!==null&&R!==void 0?R:V);M!==0&&f.push({child:I,rawChildSpan:M})});let y=0;const p=(t=f[f.length-1])===null||t===void 0?void 0:t.child;if(p!=null&&p.props){const l=(r=p.props)===null||r===void 0?void 0:r.suffix;l!==void 0&&l!==!1&&(y=(s=(n=p.props)===null||n===void 0?void 0:n.span)!==null&&s!==void 0?s:V,p.props.privateSpan=y,p.props.privateColStart=v+1-y,p.props.privateShow=(i=p.props.privateShow)!==null&&i!==void 0?i:!0)}let h=0,u=!1;for(const{child:l,rawChildSpan:$}of f){if(u&&(this.overflow=!0),!u){const m=Number((a=G((o=l.props)===null||o===void 0?void 0:o.offset,_))!==null&&a!==void 0?a:0),c=Math.min($+m,v);if(l.props?(l.props.privateSpan=c,l.props.privateOffset=m):l.props={privateSpan:c,privateOffset:m},x){const R=h%v;c+R>v&&(h+=v-R),c+h+y>g*v?u=!0:h+=c}}u&&(l.props?l.props.privateShow!==!0&&(l.props.privateShow=!1):l.props={privateShow:!1})}return E("div",j({ref:"contentEl",class:`${this.mergedClsPrefix}-grid`,style:this.style,[D]:this.isSsr||void 0},this.$attrs),f.map(({child:l})=>l))};return this.isResponsive&&this.responsive==="self"?E(H,{onResize:this.handleResize},{default:e}):e()}});export{ce as N,pe as a,fe as g};