ray-template/docs/assets/chunks/Grid.B1c9i2c6.js

2 lines
6.2 KiB
JavaScript

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