UNPKG

cc-ui-plus

Version:

13 lines (11 loc) 13.5 kB
(function(e,y){typeof exports=="object"&&typeof module<"u"?module.exports=y(require("vue")):typeof define=="function"&&define.amd?define(["vue"],y):(e=typeof globalThis<"u"?globalThis:e||self,e.index=y(e.Vue))})(this,function(e){"use strict";function y(n,t){return n.install=o=>{o.component(t,n)},n}function C(n,t,o){let l=n;return t&&(l+=`__${t}`),o&&(l+=`--${o}`),l}function W(n){const t=`cc-${n}`;return{b:()=>C(t),e:r=>r?C(t,r):"",m:r=>r?C(t,"",r):"",em:(r,i)=>r&&i?C(t,r,i):""}}const D={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:"0 0 1024 1024"},X=[e.createElementVNode("path",{d:"M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8L295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512L196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1l216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z",fill:"currentColor"},null,-1)],K=e.defineComponent({name:"CloseOutlined",render:function(t,o){return e.openBlock(),e.createElementBlock("svg",D,X)}}),F={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:"0 0 1024 1024"},H=[e.createElementVNode("path",{d:"M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 0 0 0 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281l360-281.1c3.8-3 6.1-7.7 6.1-12.6z",fill:"currentColor"},null,-1)],U=e.defineComponent({name:"LeftOutlined",render:function(t,o){return e.openBlock(),e.createElementBlock("svg",F,H)}}),Z={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:"0 0 1024 1024"},G=[e.createElementVNode("path",{d:"M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1l-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z",fill:"currentColor"},null,-1)],J=e.defineComponent({name:"RightOutlined",render:function(t,o){return e.openBlock(),e.createElementBlock("svg",Z,G)}});function Q(n){let t=0;for(let o=0;o<n.length;++o)n[o]==="&"&&++t;return t}const V=/\s*,(?![^(]*\))\s*/g,Y=/\s+/g;function v(n,t){const o=[];return t.split(V).forEach(l=>{let c=Q(l);if(c){if(c===1){n.forEach(r=>{o.push(l.replace("&",r))});return}}else{n.forEach(r=>{o.push((r&&r+" ")+l)});return}let s=[l];for(;c--;){const r=[];s.forEach(i=>{n.forEach(d=>{r.push(i.replace("&",d))})}),s=r}s.forEach(r=>o.push(r))}),o}function ee(n,t){const o=[];return t.split(V).forEach(l=>{n.forEach(c=>{o.push((c&&c+" ")+l)})}),o}function te(n){let t=[""];return n.forEach(o=>{o=o&&o.trim(),o&&(o.includes("&")?t=v(t,o):t=ee(t,o))}),t.join(", ").replace(Y," ")}const ne=/[A-Z]/g;function A(n){return n.replace(ne,t=>"-"+t.toLowerCase())}function oe(n,t=" "){return typeof n=="object"&&n!==null?` { `+Object.entries(n).map(o=>t+` ${A(o[0])}: ${o[1]};`).join(` `)+` `+t+"}":`: ${n};`}function le(n,t,o){return typeof n=="function"?n({context:t.context,props:o}):n}function T(n,t,o,l){if(!t)return"";const c=le(t,o,l);if(!c)return"";if(typeof c=="string")return`${n} { ${c} }`;const s=Object.keys(c);if(s.length===0)return o.config.keepEmptyBlock?n+` { }`:"";const r=n?[n+" {"]:[];return s.forEach(i=>{const d=c[i];if(i==="raw"){r.push(` `+d+` `);return}i=A(i),d!=null&&r.push(` ${i}${oe(d)}`)}),n&&r.push("}"),r.join(` `)}function _(n,t,o){!n||n.forEach(l=>{if(Array.isArray(l))_(l,t,o);else if(typeof l=="function"){const c=l(t);Array.isArray(c)?_(c,t,o):c&&o(c)}else l&&o(l)})}function L(n,t,o,l,c,s){const r=n.$;!r||typeof r=="string"?t.push(r):typeof r=="function"?t.push(r({context:l.context,props:c})):(r.before&&r.before(l.context),!r.$||typeof r.$=="string"?t.push(r.$):r.$&&t.push(r.$({context:l.context,props:c})));const i=te(t),d=T(i,n.props,l,c);s&&d&&s.insertRule(d),!s&&d.length&&o.push(d),n.children&&_(n.children,{context:l.context,props:c},u=>{if(typeof u=="string"){const w=T(i,{raw:u},l,c);s?s.insertRule(w):o.push(w)}else L(u,t,o,l,c,s)}),t.pop(),r&&r.after&&r.after(l.context)}function j(n,t,o,l=!1){const c=[];return L(n,[],c,t,o,l?n.instance.__styleSheet:void 0),l?"":c.join(` `)}function re(n){for(var t=0,o,l=0,c=n.length;c>=4;++l,c-=4)o=n.charCodeAt(l)&255|(n.charCodeAt(++l)&255)<<8|(n.charCodeAt(++l)&255)<<16|(n.charCodeAt(++l)&255)<<24,o=(o&65535)*1540483477+((o>>>16)*59797<<16),o^=o>>>24,t=(o&65535)*1540483477+((o>>>16)*59797<<16)^(t&65535)*1540483477+((t>>>16)*59797<<16);switch(c){case 3:t^=(n.charCodeAt(l+2)&255)<<16;case 2:t^=(n.charCodeAt(l+1)&255)<<8;case 1:t^=n.charCodeAt(l)&255,t=(t&65535)*1540483477+((t>>>16)*59797<<16)}return t^=t>>>13,t=(t&65535)*1540483477+((t>>>16)*59797<<16),((t^t>>>15)>>>0).toString(36)}function $(n){if(!n)return;const t=n.parentElement;t&&t.removeChild(n)}function E(n){return document.querySelector(`style[cssr-id="${n}"]`)}function ce(n){const t=document.createElement("style");return t.setAttribute("cssr-id",n),t}window&&(window.__cssrContext={});function R(n){const t=n.getAttribute("mount-count");return t===null?null:Number(t)}function B(n,t){n.setAttribute("mount-count",String(t))}function I(n,t,o,l){const{els:c}=t;if(o===void 0)c.forEach($),t.els=[];else{const s=E(o);if(s&&c.includes(s)){const r=R(s);l?r===null?console.error(`[css-render/unmount]: The style with target='${o}' is mounted in count mode.`):r<=1?($(s),t.els=c.filter(i=>i!==s)):B(s,r-1):r!==null?console.error(`[css-render/unmount]: The style with target='${o}' is mounted in no-count mode.`):($(s),t.els=c.filter(i=>i!==s))}}}function se(n,t){n.push(t)}function ie(n,t,o,l,c,s,r,i,d){if(r&&!d){if(o===void 0){console.error("[css-render/mount]: `id` is required in `boost` mode.");return}const g=window.__cssrContext;g[o]||(g[o]=!0,j(t,n,l,r));return}let u;const{els:w}=t;let h;if(o===void 0&&(h=t.render(l),o=re(h)),d){d(o,h!=null?h:t.render(l));return}const p=E(o);if(i||p===null){if(u=p===null?ce(o):p,h===void 0&&(h=t.render(l)),u.textContent=h,p!==null)return;if(c){const g=document.head.getElementsByTagName("style")[0]||null;document.head.insertBefore(u,g)}else document.head.appendChild(u);s&&B(u,1),se(w,u)}else{const g=R(p);s?g===null?console.error(`[css-render/mount]: The style with id='${o}' has been mounted in no-count mode.`):B(p,g+1):g!==null&&console.error(`[css-render/mount]: The style with id='${o}' has been mounted in count mode.`)}return p!=null?p:u}function ae(n){return j(this,this.instance,n)}function fe(n={}){const{target:t,id:o,ssr:l,props:c,count:s=!1,head:r=!1,boost:i=!1,force:d=!1}=n;return ie(this.instance,this,o!=null?o:t,c,r,s,i,d,l)}function de(n={}){const{id:t,target:o,delay:l=0,count:c=!1}=n;l===0?I(this.instance,this,t!=null?t:o,c):setTimeout(()=>I(this.instance,this,t!=null?t:o,c),l)}const k=function(n,t,o,l){return{instance:n,$:t,props:o,children:l,els:[],render:ae,mount:fe,unmount:de}},ue=function(n,t,o,l){return Array.isArray(t)?k(n,{$:null},null,t):Array.isArray(o)?k(n,t,null,o):Array.isArray(l)?k(n,t,o,l):k(n,t,o,null)};function me(n={}){let t=null;const o={c:(...l)=>ue(o,...l),use:(l,...c)=>l.install(o,...c),find:E,context:{},config:n,get __styleSheet(){if(!t){const l=document.createElement("style");return document.head.appendChild(l),t=document.styleSheets[document.styleSheets.length-1],t}return t}};return o}const{c:S}=me(),he=S(".xicon",{width:"1em",height:"1em",display:"inline-flex"},[S("svg",{width:"1em",height:"1em"}),S("svg:not([fill])",{fill:"currentColor"})]),pe=()=>{he.mount({id:"xicons-icon"})},P={size:[String,Number],color:String,tag:String},O=Symbol("IconConfigInjection");e.defineComponent({name:"IconConfigProvider",props:P,setup(n,{slots:t}){return e.provide(O,n),()=>e.renderSlot(t,"default")}});const ge="span",xe=e.defineComponent({name:"Icon",props:P,setup(n,{slots:t}){const o=e.inject(O,null),l=e.computed(()=>{var r;const i=(r=n.size)!==null&&r!==void 0?r:o==null?void 0:o.size;if(i!==void 0)return typeof i=="number"||/^\d+$/.test(i)?`${i}px`:i}),c=e.computed(()=>{const{color:r}=n;return r===void 0?o?o.color:void 0:r}),s=e.computed(()=>{var r;const{tag:i}=n;return i===void 0?(r=o==null?void 0:o.tag)!==null&&r!==void 0?r:ge:i});return e.onBeforeMount(()=>{pe()}),()=>e.h(s.value,{class:"xicon",style:{color:c.value,fontSize:l.value}},[e.renderSlot(t,"default")])}}),N=y(e.defineComponent({__name:"icon",props:{color:{default:"inherit"},size:{default:16},tag:{default:"span"}},setup(n){return(t,o)=>(e.openBlock(),e.createBlock(e.unref(xe),{size:n.size,color:n.color,tag:n.tag},{default:e.withCtx(()=>[e.renderSlot(t.$slots,"default")]),_:3},8,["size","color","tag"]))}}),"cc-icon"),z=Symbol("TabsProvide"),ye={style:{overflow:"hidden"}},we=["id","onClick"],be={key:1},Ce=["onClick"],ke=["onClick"],_e=e.defineComponent({__name:"tabs",props:{modelValue:null,type:{default:""},closable:{type:Boolean,default:!1},addable:{type:Boolean,default:!1},editable:{type:Boolean,default:!1}},emits:["update:modelValue","tab-click","tab-remove","tab-change"],setup(n,{emit:t}){var M;const o=n,l=W("tabs"),c=(M=e.getCurrentInstance())==null?void 0:M.uid,s=e.ref([]),r=e.ref(o.modelValue),i=e.ref(""),d=e.ref(""),u=e.ref(),w=e.ref(),h=e.ref(!1),p=e.ref(0),g=a=>{a.disabled||s.value.push(a)},Ne=(a,m)=>{s.value.length===1?(r.value="",s.value=[]):(m===s.value.length-1&&m>=0&&(r.value=s.value[m-1].name),s.value=s.value.filter(f=>f.name!==a),t("tab-remove",a))},ze=(a,m)=>{a.disabled||(r.value=a.name,q(r.value,!0),t("tab-click",a,m))},q=(a,m=!1)=>{a&&e.nextTick(()=>{const f=document.querySelector(`#tab-${a}-${c}`),x=window.getComputedStyle(f,null),b=Number(x.paddingLeft.replace("px","")),Te=Number(x.paddingRight.replace("px","")),Le=Number(x.width.replace("px",""));i.value=`${Le-b-Te}px`,m&&(d.value=`${f.offsetLeft+b}px`)})},Ve=()=>{p.value=0},Ae=()=>{e.nextTick(()=>{const a=Number(window.getComputedStyle(u.value,null).width.replace("px",""));let m=0;for(let f=0;f<s.value.length;f++)m+=Number(window.getComputedStyle(document.querySelector(`#tab-${s.value[f].name}-${c}`)).width.replace("px",""));p.value=-(m-a+20*2)})};return e.watch(()=>o.modelValue,a=>{r.value=a,t("tab-change",a)}),e.watch(()=>r.value,a=>{e.nextTick(()=>{q(a)})},{immediate:!0}),e.watch(()=>s.value,a=>{let m=0;e.nextTick(()=>{const f=Number(window.getComputedStyle(u.value,null).width.replace("px",""));a.forEach(x=>{m+=Number(window.getComputedStyle(document.querySelector(`#tab-${x.name}-${c}`)).width.replace("px",""))}),h.value=m>f})},{deep:!0}),e.provide(z,{addTabPaneContext:g,currentName:e.computed(()=>r.value)}),(a,m)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([e.unref(l).b()])},[e.createElementVNode("div",{ref_key:"wrap",ref:u,class:e.normalizeClass([e.unref(l).e("wrap")]),style:e.normalizeStyle({padding:h.value?"0 20px":"0"})},[h.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass([e.unref(l).e("icon-left")]),onClick:Ve},[e.createVNode(e.unref(N),null,{default:e.withCtx(()=>[e.createVNode(e.unref(U))]),_:1})],2)):e.createCommentVNode("",!0),e.createElementVNode("div",ye,[e.createElementVNode("div",{ref_key:"label",ref:w,class:e.normalizeClass([e.unref(l).e("label")]),style:e.normalizeStyle({transform:`translateX(${p.value}px)`})},[n.type?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass([e.unref(l).e("active-bar")]),style:e.normalizeStyle({width:i.value,transform:`translateX(${d.value})`})},null,6)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.value,(f,x)=>(e.openBlock(),e.createElementBlock("div",{id:`tab-${f.name}-${e.unref(c)}`,key:f.name,class:e.normalizeClass([e.unref(l).e("label-item"),e.unref(l).m(`${n.type}`),,{"is-disabled":f.disabled}]),style:e.normalizeStyle({color:f.name===r.value?"var(--cc-color-primary)":"inherit",paddingLeft:x===0&&!n.type?0:"12px"}),onClick:b=>ze(f,b)},[f.slot?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(f.slot),{key:0})):(e.openBlock(),e.createElementBlock("span",be,e.toDisplayString(f.label),1)),n.closable||f.closable?(e.openBlock(),e.createElementBlock("div",{key:2,class:e.normalizeClass([e.unref(l).e("close-btn")]),onClick:e.withModifiers(b=>Ne(f.name,x),["stop"])},[e.createVNode(e.unref(N),null,{default:e.withCtx(()=>[e.createVNode(e.unref(K))]),_:1})],10,Ce)):e.createCommentVNode("",!0)],14,we))),128))],6)]),h.value?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass([e.unref(l).e("icon-right")]),onClick:e.withModifiers(Ae,["stop"])},[e.createVNode(e.unref(N),null,{default:e.withCtx(()=>[e.createVNode(e.unref(J))]),_:1})],10,ke)):e.createCommentVNode("",!0)],6),e.createElementVNode("div",{class:e.normalizeClass([e.unref(l).e("content")])},[e.renderSlot(a.$slots,"default")],2)],2))}}),$e={style:{display:"none"}},Ee=e.defineComponent({__name:"tab-pane",props:{label:{default:""},name:null,disabled:{type:Boolean,default:!1},closable:{type:Boolean,default:!1}},setup(n){var c,s;const t=n,o=(c=e.inject(z))==null?void 0:c.addTabPaneContext,l=(s=e.inject(z))==null?void 0:s.currentName;return o({label:e.computed(()=>t.label).value,name:e.computed(()=>t.name).value,disabled:e.computed(()=>t.disabled).value,closable:e.computed(()=>t.closable).value,slot:e.useSlots().label}),(r,i)=>e.withDirectives((e.openBlock(),e.createElementBlock("div",null,[e.renderSlot(r.$slots,"default"),e.createElementVNode("div",$e,[r.$slots.label?e.renderSlot(r.$slots,"label",{key:0}):e.createCommentVNode("",!0)])],512)),[[e.vShow,e.unref(l)===n.name]])}}),Be=y(_e,"cc-tabs"),Se=y(Ee,"cc-tab-pane");return{Tabs:Be,TabPane:Se}});