UNPKG

cc-ui-plus

Version:

13 lines (11 loc) 13.7 kB
(function(o,x){typeof exports=="object"&&typeof module<"u"?module.exports=x(require("vue")):typeof define=="function"&&define.amd?define(["vue"],x):(o=typeof globalThis<"u"?globalThis:o||self,o.index=x(o.Vue))})(this,function(o){"use strict";function x(e,t){return e.install=n=>{n.component(t,e)},e}const j=(e,t)=>(e.install=n=>{e._context=n._context,n.config.globalProperties[t]=e},e);function C(e,t,n){let r=e;return t&&(r+=`__${t}`),n&&(r+=`--${n}`),r}function O(e){const t=`cc-${e}`;return{b:()=>C(t),e:s=>s?C(t,s):"",m:s=>s?C(t,"",s):"",em:(s,i)=>s&&i?C(t,s,i):""}}const R={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:"0 0 1024 1024"},F=[o.createElementVNode("path",{d:"M699 353h-46.9c-10.2 0-19.9 4.9-25.9 13.3L469 584.3l-71.2-98.8c-6-8.3-15.6-13.3-25.9-13.3H325c-6.5 0-10.3 7.4-6.5 12.7l124.6 172.8a31.8 31.8 0 0 0 51.7 0l210.6-292c3.9-5.3.1-12.7-6.4-12.7z",fill:"currentColor"},null,-1),o.createElementVNode("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"},null,-1)],q=o.defineComponent({name:"CheckCircleOutlined",render:function(t,n){return o.openBlock(),o.createElementBlock("svg",R,F)}}),P={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:"0 0 1024 1024"},W=[o.createElementVNode("path",{d:"M685.4 354.8c0-4.4-3.6-8-8-8l-66 .3L512 465.6l-99.3-118.4l-66.1-.3c-4.4 0-8 3.5-8 8c0 1.9.7 3.7 1.9 5.2l130.1 155L340.5 670a8.32 8.32 0 0 0-1.9 5.2c0 4.4 3.6 8 8 8l66.1-.3L512 564.4l99.3 118.4l66 .3c4.4 0 8-3.5 8-8c0-1.9-.7-3.7-1.9-5.2L553.5 515l130.1-155c1.2-1.4 1.8-3.3 1.8-5.2z",fill:"currentColor"},null,-1),o.createElementVNode("path",{d:"M512 65C264.6 65 64 265.6 64 513s200.6 448 448 448s448-200.6 448-448S759.4 65 512 65zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"},null,-1)],D=o.defineComponent({name:"CloseCircleOutlined",render:function(t,n){return o.openBlock(),o.createElementBlock("svg",P,W)}}),H={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:"0 0 1024 1024"},K=[o.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)],U=o.defineComponent({name:"CloseOutlined",render:function(t,n){return o.openBlock(),o.createElementBlock("svg",H,K)}}),Z={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:"0 0 1024 1024"},G=[o.createElementVNode("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"},null,-1),o.createElementVNode("path",{d:"M464 336a48 48 0 1 0 96 0a48 48 0 1 0-96 0zm72 112h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V456c0-4.4-3.6-8-8-8z",fill:"currentColor"},null,-1)],J=o.defineComponent({name:"InfoCircleOutlined",render:function(t,n){return o.openBlock(),o.createElementBlock("svg",Z,G)}}),Q={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",viewBox:"0 0 32 32"},X=[o.createElementVNode("path",{d:"M16 2a14 14 0 1 0 14 14A14 14 0 0 0 16 2zm0 26a12 12 0 1 1 12-12a12 12 0 0 1-12 12z",fill:"currentColor"},null,-1),o.createElementVNode("path",{d:"M15 8h2v11h-2z",fill:"currentColor"},null,-1),o.createElementVNode("path",{d:"M16 22a1.5 1.5 0 1 0 1.5 1.5A1.5 1.5 0 0 0 16 22z",fill:"currentColor"},null,-1)],Y=o.defineComponent({name:"Warning",render:function(t,n){return o.openBlock(),o.createElementBlock("svg",Q,X)}});function v(e){let t=0;for(let n=0;n<e.length;++n)e[n]==="&"&&++t;return t}const B=/\s*,(?![^(]*\))\s*/g,ee=/\s+/g;function te(e,t){const n=[];return t.split(B).forEach(r=>{let c=v(r);if(c){if(c===1){e.forEach(s=>{n.push(r.replace("&",s))});return}}else{e.forEach(s=>{n.push((s&&s+" ")+r)});return}let l=[r];for(;c--;){const s=[];l.forEach(i=>{e.forEach(f=>{s.push(i.replace("&",f))})}),l=s}l.forEach(s=>n.push(s))}),n}function ne(e,t){const n=[];return t.split(B).forEach(r=>{e.forEach(c=>{n.push((c&&c+" ")+r)})}),n}function oe(e){let t=[""];return e.forEach(n=>{n=n&&n.trim(),n&&(n.includes("&")?t=te(t,n):t=ne(t,n))}),t.join(", ").replace(ee," ")}const re=/[A-Z]/g;function z(e){return e.replace(re,t=>"-"+t.toLowerCase())}function se(e,t=" "){return typeof e=="object"&&e!==null?` { `+Object.entries(e).map(n=>t+` ${z(n[0])}: ${n[1]};`).join(` `)+` `+t+"}":`: ${e};`}function ce(e,t,n){return typeof e=="function"?e({context:t.context,props:n}):e}function V(e,t,n,r){if(!t)return"";const c=ce(t,n,r);if(!c)return"";if(typeof c=="string")return`${e} { ${c} }`;const l=Object.keys(c);if(l.length===0)return n.config.keepEmptyBlock?e+` { }`:"";const s=e?[e+" {"]:[];return l.forEach(i=>{const f=c[i];if(i==="raw"){s.push(` `+f+` `);return}i=z(i),f!=null&&s.push(` ${i}${se(f)}`)}),e&&s.push("}"),s.join(` `)}function y(e,t,n){!e||e.forEach(r=>{if(Array.isArray(r))y(r,t,n);else if(typeof r=="function"){const c=r(t);Array.isArray(c)?y(c,t,n):c&&n(c)}else r&&n(r)})}function A(e,t,n,r,c,l){const s=e.$;!s||typeof s=="string"?t.push(s):typeof s=="function"?t.push(s({context:r.context,props:c})):(s.before&&s.before(r.context),!s.$||typeof s.$=="string"?t.push(s.$):s.$&&t.push(s.$({context:r.context,props:c})));const i=oe(t),f=V(i,e.props,r,c);l&&f&&l.insertRule(f),!l&&f.length&&n.push(f),e.children&&y(e.children,{context:r.context,props:c},u=>{if(typeof u=="string"){const p=V(i,{raw:u},r,c);l?l.insertRule(p):n.push(p)}else A(u,t,n,r,c,l)}),t.pop(),s&&s.after&&s.after(r.context)}function N(e,t,n,r=!1){const c=[];return A(e,[],c,t,n,r?e.instance.__styleSheet:void 0),r?"":c.join(` `)}function le(e){for(var t=0,n,r=0,c=e.length;c>=4;++r,c-=4)n=e.charCodeAt(r)&255|(e.charCodeAt(++r)&255)<<8|(e.charCodeAt(++r)&255)<<16|(e.charCodeAt(++r)&255)<<24,n=(n&65535)*1540483477+((n>>>16)*59797<<16),n^=n>>>24,t=(n&65535)*1540483477+((n>>>16)*59797<<16)^(t&65535)*1540483477+((t>>>16)*59797<<16);switch(c){case 3:t^=(e.charCodeAt(r+2)&255)<<16;case 2:t^=(e.charCodeAt(r+1)&255)<<8;case 1:t^=e.charCodeAt(r)&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 $(e){if(!e)return;const t=e.parentElement;t&&t.removeChild(e)}function k(e){return document.querySelector(`style[cssr-id="${e}"]`)}function ie(e){const t=document.createElement("style");return t.setAttribute("cssr-id",e),t}window&&(window.__cssrContext={});function T(e){const t=e.getAttribute("mount-count");return t===null?null:Number(t)}function E(e,t){e.setAttribute("mount-count",String(t))}function S(e,t,n,r){const{els:c}=t;if(n===void 0)c.forEach($),t.els=[];else{const l=k(n);if(l&&c.includes(l)){const s=T(l);r?s===null?console.error(`[css-render/unmount]: The style with target='${n}' is mounted in count mode.`):s<=1?($(l),t.els=c.filter(i=>i!==l)):E(l,s-1):s!==null?console.error(`[css-render/unmount]: The style with target='${n}' is mounted in no-count mode.`):($(l),t.els=c.filter(i=>i!==l))}}}function fe(e,t){e.push(t)}function ae(e,t,n,r,c,l,s,i,f){if(s&&!f){if(n===void 0){console.error("[css-render/mount]: `id` is required in `boost` mode.");return}const m=window.__cssrContext;m[n]||(m[n]=!0,N(t,e,r,s));return}let u;const{els:p}=t;let h;if(n===void 0&&(h=t.render(r),n=le(h)),f){f(n,h!=null?h:t.render(r));return}const a=k(n);if(i||a===null){if(u=a===null?ie(n):a,h===void 0&&(h=t.render(r)),u.textContent=h,a!==null)return;if(c){const m=document.head.getElementsByTagName("style")[0]||null;document.head.insertBefore(u,m)}else document.head.appendChild(u);l&&E(u,1),fe(p,u)}else{const m=T(a);l?m===null?console.error(`[css-render/mount]: The style with id='${n}' has been mounted in no-count mode.`):E(a,m+1):m!==null&&console.error(`[css-render/mount]: The style with id='${n}' has been mounted in count mode.`)}return a!=null?a:u}function ue(e){return N(this,this.instance,e)}function de(e={}){const{target:t,id:n,ssr:r,props:c,count:l=!1,head:s=!1,boost:i=!1,force:f=!1}=e;return ae(this.instance,this,n!=null?n:t,c,s,l,i,f,r)}function me(e={}){const{id:t,target:n,delay:r=0,count:c=!1}=e;r===0?S(this.instance,this,t!=null?t:n,c):setTimeout(()=>S(this.instance,this,t!=null?t:n,c),r)}const _=function(e,t,n,r){return{instance:e,$:t,props:n,children:r,els:[],render:ue,mount:de,unmount:me}},he=function(e,t,n,r){return Array.isArray(t)?_(e,{$:null},null,t):Array.isArray(n)?_(e,t,null,n):Array.isArray(r)?_(e,t,n,r):_(e,t,n,null)};function ge(e={}){let t=null;const n={c:(...r)=>he(n,...r),use:(r,...c)=>r.install(n,...c),find:k,context:{},config:e,get __styleSheet(){if(!t){const r=document.createElement("style");return document.head.appendChild(r),t=document.styleSheets[document.styleSheets.length-1],t}return t}};return n}const{c:b}=ge(),pe=b(".xicon",{width:"1em",height:"1em",display:"inline-flex"},[b("svg",{width:"1em",height:"1em"}),b("svg:not([fill])",{fill:"currentColor"})]),xe=()=>{pe.mount({id:"xicons-icon"})},M={size:[String,Number],color:String,tag:String},I=Symbol("IconConfigInjection");o.defineComponent({name:"IconConfigProvider",props:M,setup(e,{slots:t}){return o.provide(I,e),()=>o.renderSlot(t,"default")}});const we="span",Ce=o.defineComponent({name:"Icon",props:M,setup(e,{slots:t}){const n=o.inject(I,null),r=o.computed(()=>{var s;const i=(s=e.size)!==null&&s!==void 0?s:n==null?void 0:n.size;if(i!==void 0)return typeof i=="number"||/^\d+$/.test(i)?`${i}px`:i}),c=o.computed(()=>{const{color:s}=e;return s===void 0?n?n.color:void 0:s}),l=o.computed(()=>{var s;const{tag:i}=e;return i===void 0?(s=n==null?void 0:n.tag)!==null&&s!==void 0?s:we:i});return o.onBeforeMount(()=>{xe()}),()=>o.h(l.value,{class:"xicon",style:{color:c.value,fontSize:r.value}},[o.renderSlot(t,"default")])}}),w=x(o.defineComponent({__name:"icon",props:{color:{default:"inherit"},size:{default:16},tag:{default:"span"}},setup(e){return(t,n)=>(o.openBlock(),o.createBlock(o.unref(Ce),{size:e.size,color:e.color,tag:e.tag},{default:o.withCtx(()=>[o.renderSlot(t.$slots,"default")]),_:3},8,["size","color","tag"]))}}),"cc-icon"),_e=["onClick"],ye=o.defineComponent({__name:"message",props:{message:{default:""},type:{default:"info"},center:{type:Boolean,default:!1},showClose:{type:Boolean,default:!1},offset:{default:20}},setup(e,{expose:t}){const n=e,r=O("message"),c=o.ref(!1),l=o.ref(!1),s=o.ref(n.offset),i=(a,m=300)=>new Promise(Be=>{c.value=a,setTimeout(()=>{Be("")},m)}),f=a=>{s.value=a},u=a=>{l.value=a},p=()=>{u(!0),i(!1,0)};t({setVisible:i,setTop:f,setCloseFlag:u,closeFlag:l});const h=o.computed(()=>n.type==="success"?"bg-success":n.type==="info"?"bg-info":n.type==="danger"?"bg-danger":n.type==="warning"?"bg-warning":"");return(a,m)=>(o.openBlock(),o.createBlock(o.Transition,{name:"cc-message"},{default:o.withCtx(()=>[o.withDirectives(o.createElementVNode("div",{style:o.normalizeStyle({top:s.value+"px"}),class:o.normalizeClass([o.unref(r).b(),o.unref(h),e.center?o.unref(r).m("center"):""])},[o.createElementVNode("div",{class:o.normalizeClass([o.unref(r).e("icon")])},[e.type==="success"?(o.openBlock(),o.createBlock(o.unref(w),{key:0,color:"var(--cc-color-success)"},{default:o.withCtx(()=>[o.createVNode(o.unref(q))]),_:1})):o.createCommentVNode("",!0),e.type==="warning"?(o.openBlock(),o.createBlock(o.unref(w),{key:1,color:"var(--cc-color-warning)"},{default:o.withCtx(()=>[o.createVNode(o.unref(Y))]),_:1})):o.createCommentVNode("",!0),e.type==="info"?(o.openBlock(),o.createBlock(o.unref(w),{key:2,color:"var(--cc-color-info)"},{default:o.withCtx(()=>[o.createVNode(o.unref(J))]),_:1})):o.createCommentVNode("",!0),e.type==="danger"?(o.openBlock(),o.createBlock(o.unref(w),{key:3,color:"var(--cc-color-danger)"},{default:o.withCtx(()=>[o.createVNode(o.unref(D))]),_:1})):o.createCommentVNode("",!0)],2),o.createElementVNode("div",null,o.toDisplayString(e.message),1),e.showClose?(o.openBlock(),o.createElementBlock("div",{key:0,class:o.normalizeClass([o.unref(r).e("close-btn")]),onClick:o.withModifiers(p,["stop"])},[o.createVNode(o.unref(w),{color:"var(--cc-message-close-icon-color)",size:"var(--cc-message-close-icon-size)"},{default:o.withCtx(()=>[o.createVNode(o.unref(U))]),_:1})],10,_e)):o.createCommentVNode("",!0)],6),[[o.vShow,c.value]])]),_:1}))}}),$e=60,ke=28,g=o.ref([]),d=e=>{typeof e=="string"&&(e={message:e,duration:3e3});const t=o.createApp(ye,e);Ee(t,e.duration)},Ee=(e,t=3e3)=>{const n=document.createDocumentFragment(),r=e.mount(n);g.value.push(r),L(r),r.setVisible(!0),o.watch(()=>g.value,()=>L(r)),document.body.appendChild(n),be(e,r,t)},be=(e,t,n=3e3)=>{o.watch(()=>t.closeFlag,r=>{r&&(t.closeTimer=setTimeout(()=>{e.unmount(),g.value=g.value.filter(c=>c!==t),clearTimeout(t.closeTimer),t.closeTimer=null,t.closeFlag=!1},300))}),t.timer=setTimeout(async()=>{await t.setVisible(!1),e.unmount(),g.value=g.value.filter(r=>r!==t),clearTimeout(t.timer),t.timer=null},n)},L=e=>{const t=g.value.indexOf(e);e.setTop($e*t+ke)};return d.success=e=>{d(typeof e=="string"?{type:"success",message:e}:{type:"success",message:e.message,...e})},d.info=e=>{d(typeof e=="string"?{type:"info",message:e}:{type:"info",message:e.message,...e})},d.warning=e=>{d(typeof e=="string"?{type:"warning",message:e}:{type:"warning",message:e.message,...e})},d.error=e=>{d(typeof e=="string"?{type:"danger",message:e}:{type:"danger",message:e.message,...e})},j(d,"$message")});