cc-ui-plus
Version:
13 lines (11 loc) • 8.64 kB
JavaScript
(function(i,p){typeof exports=="object"&&typeof module<"u"?module.exports=p(require("vue")):typeof define=="function"&&define.amd?define(["vue"],p):(i=typeof globalThis<"u"?globalThis:i||self,i.index=p(i.Vue))})(this,function(i){"use strict";function p(n,e){return n.install=t=>{t.component(e,n)},n}function g(n,e,t){let o=n;return e&&(o+=`__${e}`),t&&(o+=`--${t}`),o}function R(n){const e=`cc-${n}`;return{b:()=>g(e),e:r=>r?g(e,r):"",m:r=>r?g(e,"",r):"",em:(r,f)=>r&&f?g(e,r,f):""}}const I=(n,e)=>{if(e.value==="")return"";if(e.value==="small")return n.m("small");if(e.value==="large")return n.m("large")},N=(n,e)=>{if(e.value==="")return n.m("default");if(e.value==="primary")return n.m("primary");if(e.value==="success")return n.m("success");if(e.value==="warning")return n.m("warning");if(e.value==="danger")return n.m("danger");if(e.value==="info")return n.m("info")};function q(n){let e=0;for(let t=0;t<n.length;++t)n[t]==="&"&&++e;return e}const E=/\s*,(?![^(]*\))\s*/g,L=/\s+/g;function P(n,e){const t=[];return e.split(E).forEach(o=>{let s=q(o);if(s){if(s===1){n.forEach(r=>{t.push(o.replace("&",r))});return}}else{n.forEach(r=>{t.push((r&&r+" ")+o)});return}let u=[o];for(;s--;){const r=[];u.forEach(f=>{n.forEach(l=>{r.push(f.replace("&",l))})}),u=r}u.forEach(r=>t.push(r))}),t}function M(n,e){const t=[];return e.split(E).forEach(o=>{n.forEach(s=>{t.push((s&&s+" ")+o)})}),t}function V(n){let e=[""];return n.forEach(t=>{t=t&&t.trim(),t&&(t.includes("&")?e=P(e,t):e=M(e,t))}),e.join(", ").replace(L," ")}const D=/[A-Z]/g;function A(n){return n.replace(D,e=>"-"+e.toLowerCase())}function O(n,e=" "){return typeof n=="object"&&n!==null?` {
`+Object.entries(n).map(t=>e+` ${A(t[0])}: ${t[1]};`).join(`
`)+`
`+e+"}":`: ${n};`}function W(n,e,t){return typeof n=="function"?n({context:e.context,props:t}):n}function k(n,e,t,o){if(!e)return"";const s=W(e,t,o);if(!s)return"";if(typeof s=="string")return`${n} {
${s}
}`;const u=Object.keys(s);if(u.length===0)return t.config.keepEmptyBlock?n+` {
}`:"";const r=n?[n+" {"]:[];return u.forEach(f=>{const l=s[f];if(f==="raw"){r.push(`
`+l+`
`);return}f=A(f),l!=null&&r.push(` ${f}${O(l)}`)}),n&&r.push("}"),r.join(`
`)}function x(n,e,t){!n||n.forEach(o=>{if(Array.isArray(o))x(o,e,t);else if(typeof o=="function"){const s=o(e);Array.isArray(s)?x(s,e,t):s&&t(s)}else o&&t(o)})}function B(n,e,t,o,s,u){const r=n.$;!r||typeof r=="string"?e.push(r):typeof r=="function"?e.push(r({context:o.context,props:s})):(r.before&&r.before(o.context),!r.$||typeof r.$=="string"?e.push(r.$):r.$&&e.push(r.$({context:o.context,props:s})));const f=V(e),l=k(f,n.props,o,s);u&&l&&u.insertRule(l),!u&&l.length&&t.push(l),n.children&&x(n.children,{context:o.context,props:s},c=>{if(typeof c=="string"){const h=k(f,{raw:c},o,s);u?u.insertRule(h):t.push(h)}else B(c,e,t,o,s,u)}),e.pop(),r&&r.after&&r.after(o.context)}function S(n,e,t,o=!1){const s=[];return B(n,[],s,e,t,o?n.instance.__styleSheet:void 0),o?"":s.join(`
`)}function K(n){for(var e=0,t,o=0,s=n.length;s>=4;++o,s-=4)t=n.charCodeAt(o)&255|(n.charCodeAt(++o)&255)<<8|(n.charCodeAt(++o)&255)<<16|(n.charCodeAt(++o)&255)<<24,t=(t&65535)*1540483477+((t>>>16)*59797<<16),t^=t>>>24,e=(t&65535)*1540483477+((t>>>16)*59797<<16)^(e&65535)*1540483477+((e>>>16)*59797<<16);switch(s){case 3:e^=(n.charCodeAt(o+2)&255)<<16;case 2:e^=(n.charCodeAt(o+1)&255)<<8;case 1:e^=n.charCodeAt(o)&255,e=(e&65535)*1540483477+((e>>>16)*59797<<16)}return e^=e>>>13,e=(e&65535)*1540483477+((e>>>16)*59797<<16),((e^e>>>15)>>>0).toString(36)}function C(n){if(!n)return;const e=n.parentElement;e&&e.removeChild(n)}function b(n){return document.querySelector(`style[cssr-id="${n}"]`)}function U(n){const e=document.createElement("style");return e.setAttribute("cssr-id",n),e}window&&(window.__cssrContext={});function T(n){const e=n.getAttribute("mount-count");return e===null?null:Number(e)}function w(n,e){n.setAttribute("mount-count",String(e))}function _(n,e,t,o){const{els:s}=e;if(t===void 0)s.forEach(C),e.els=[];else{const u=b(t);if(u&&s.includes(u)){const r=T(u);o?r===null?console.error(`[css-render/unmount]: The style with target='${t}' is mounted in count mode.`):r<=1?(C(u),e.els=s.filter(f=>f!==u)):w(u,r-1):r!==null?console.error(`[css-render/unmount]: The style with target='${t}' is mounted in no-count mode.`):(C(u),e.els=s.filter(f=>f!==u))}}}function Z(n,e){n.push(e)}function F(n,e,t,o,s,u,r,f,l){if(r&&!l){if(t===void 0){console.error("[css-render/mount]: `id` is required in `boost` mode.");return}const m=window.__cssrContext;m[t]||(m[t]=!0,S(e,n,o,r));return}let c;const{els:h}=e;let a;if(t===void 0&&(a=e.render(o),t=K(a)),l){l(t,a!=null?a:e.render(o));return}const d=b(t);if(f||d===null){if(c=d===null?U(t):d,a===void 0&&(a=e.render(o)),c.textContent=a,d!==null)return;if(s){const m=document.head.getElementsByTagName("style")[0]||null;document.head.insertBefore(c,m)}else document.head.appendChild(c);u&&w(c,1),Z(h,c)}else{const m=T(d);u?m===null?console.error(`[css-render/mount]: The style with id='${t}' has been mounted in no-count mode.`):w(d,m+1):m!==null&&console.error(`[css-render/mount]: The style with id='${t}' has been mounted in count mode.`)}return d!=null?d:c}function G(n){return S(this,this.instance,n)}function H(n={}){const{target:e,id:t,ssr:o,props:s,count:u=!1,head:r=!1,boost:f=!1,force:l=!1}=n;return F(this.instance,this,t!=null?t:e,s,r,u,f,l,o)}function J(n={}){const{id:e,target:t,delay:o=0,count:s=!1}=n;o===0?_(this.instance,this,e!=null?e:t,s):setTimeout(()=>_(this.instance,this,e!=null?e:t,s),o)}const y=function(n,e,t,o){return{instance:n,$:e,props:t,children:o,els:[],render:G,mount:H,unmount:J}},Q=function(n,e,t,o){return Array.isArray(e)?y(n,{$:null},null,e):Array.isArray(t)?y(n,e,null,t):Array.isArray(o)?y(n,e,t,o):y(n,e,t,null)};function X(n={}){let e=null;const t={c:(...o)=>Q(t,...o),use:(o,...s)=>o.install(t,...s),find:b,context:{},config:n,get __styleSheet(){if(!e){const o=document.createElement("style");return document.head.appendChild(o),e=document.styleSheets[document.styleSheets.length-1],e}return e}};return t}const{c:$}=X(),Y=$(".xicon",{width:"1em",height:"1em",display:"inline-flex"},[$("svg",{width:"1em",height:"1em"}),$("svg:not([fill])",{fill:"currentColor"})]),v=()=>{Y.mount({id:"xicons-icon"})},z={size:[String,Number],color:String,tag:String},j=Symbol("IconConfigInjection");i.defineComponent({name:"IconConfigProvider",props:z,setup(n,{slots:e}){return i.provide(j,n),()=>i.renderSlot(e,"default")}});const ee="span",ne=i.defineComponent({name:"Icon",props:z,setup(n,{slots:e}){const t=i.inject(j,null),o=i.computed(()=>{var r;const f=(r=n.size)!==null&&r!==void 0?r:t==null?void 0:t.size;if(f!==void 0)return typeof f=="number"||/^\d+$/.test(f)?`${f}px`:f}),s=i.computed(()=>{const{color:r}=n;return r===void 0?t?t.color:void 0:r}),u=i.computed(()=>{var r;const{tag:f}=n;return f===void 0?(r=t==null?void 0:t.tag)!==null&&r!==void 0?r:ee:f});return i.onBeforeMount(()=>{v()}),()=>i.h(u.value,{class:"xicon",style:{color:s.value,fontSize:o.value}},[i.renderSlot(e,"default")])}}),te=p(i.defineComponent({__name:"icon",props:{color:{default:"inherit"},size:{default:16},tag:{default:"span"}},setup(n){return(e,t)=>(i.openBlock(),i.createBlock(i.unref(ne),{size:n.size,color:n.color,tag:n.tag},{default:i.withCtx(()=>[i.renderSlot(e.$slots,"default")]),_:3},8,["size","color","tag"]))}}),"cc-icon"),oe=["nativeType","onClick"];return p(i.defineComponent({__name:"button",props:{size:{default:""},type:{default:""},plain:{type:Boolean,default:!1},round:{type:Boolean,default:!1},circle:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},nativeType:{default:"button"},icon:null},emits:["click"],setup(n,{emit:e}){const t=n,o=R("button"),s=a=>{t.disabled||e("click",a)},u=I(o,i.computed(()=>t.size)),r=N(o,i.computed(()=>t.type)),f=i.computed(()=>t.plain?"is-plain":""),l=i.computed(()=>t.round?"is-round":""),c=i.computed(()=>t.disabled?"is-disabled":""),h=i.computed(()=>t.circle?"is-circle":"");return(a,d)=>(i.openBlock(),i.createElementBlock("button",{nativeType:n.nativeType,class:i.normalizeClass([i.unref(o).b(),i.unref(u),i.unref(r),i.unref(f),i.unref(l),i.unref(c),i.unref(h)]),onClick:i.withModifiers(s,["prevent","stop"])},[n.icon?(i.openBlock(),i.createBlock(i.unref(te),{key:0},{default:i.withCtx(()=>[(i.openBlock(),i.createBlock(i.resolveDynamicComponent(n.icon),{color:n.type?"#fff":"#000"},null,8,["color"]))]),_:1})):i.createCommentVNode("",!0),a.$slots.default?(i.openBlock(),i.createElementBlock("span",{key:1,style:i.normalizeStyle({marginLeft:n.icon?"8px":"0"})},[i.renderSlot(a.$slots,"default")],4)):i.createCommentVNode("",!0)],10,oe))}}),"cc-button")});