UNPKG

@volverjs/ui-vue

Version:

@volverjs/ui-vue is a lightweight Vue 3 component library to accompany @volverjs/style.

2 lines (1 loc) 2.98 kB
import{addCollection as e,addIcon as t,addAPIProvider as r}from"@iconify/vue";import{ref as n}from"vue";const i=new RegExp("([\\p{Ll}\\d])(\\p{Lu})","gu"),s=new RegExp("(\\p{Lu})([\\p{Lu}][\\p{Ll}])","gu"),o=new RegExp("(\\d)\\p{Ll}|(\\p{L})\\d","u"),c=/[^\p{L}\d]+/giu,l="$1\0$2";function a(e){let t=e.trim();t=t.replace(i,l).replace(s,l),t=t.replace(c,"\0");let r=0,n=t.length;for(;"\0"===t.charAt(r);)r++;if(r===n)return[];for(;"\0"===t.charAt(n-1);)n--;return t.slice(r,n).split(/\0/g)}function u(e){const t=a(e);for(let r=0;r<t.length;r++){const e=t[r],n=o.exec(e);if(n){const i=n.index+(n[1]??n[2]).length;t.splice(r,1,e.slice(0,i),e.slice(i))}}return t}function f(e,t){const[r,n,i]=function(e,t={}){const r=t.split??(t.separateNumbers?u:a),n=t.prefixCharacters??"",i=t.suffixCharacters??"";let s=0,o=e.length;for(;s<e.length;){const t=e.charAt(s);if(!n.includes(t))break;s++}for(;o>s;){const t=o-1,r=e.charAt(t);if(!i.includes(r))break;o=t}return[e.slice(0,s),r(e.slice(s,o)),e.slice(o)]}(e,t);return r+n.map((s=t?.locale,!1===s?e=>e.toLowerCase():e=>e.toLocaleLowerCase(s))).join(t?.delimiter??" ")+i;var s}const h=Symbol.for("volver");function p(e,t,r){const n=r||e.name;if(!n)return e;const i=t?.[n],s=e.props;return i&&s?{...e,name:n,props:Object.keys(s).reduce((e,t)=>{if(!(t in i))return e[t]=s[t],e;const r=i[t];return"function"==typeof s[t]||Array.isArray(s[t])?(e[t]={type:s[t],default:r},e):(e[t]={...s[t],default:r},e)},{})}:{...e,name:n}}class d{_fetchOptions={};_iconsCollections=[];_iconsProvider="vv";_nuxt=!1;_experimentalFeatures={};defaults=n({});constructor({fetchWithCredentials:e,fetchOptions:t,iconsProvider:r,nuxt:n,iconsCollections:i,defaults:s,experimentalFeatures:o}={}){t&&(this._fetchOptions=t),e&&(this._fetchOptions={...this._fetchOptions,credentials:"include"}),r&&(this._iconsProvider=r),n&&(this._nuxt=n),i&&Array.isArray(i)&&i.forEach(e=>{this.addCollection(e,this._iconsProvider)}),s&&(this.defaults.value=s),o&&(this._experimentalFeatures=o)}get nuxt(){return this._nuxt}get iconsProvider(){return this._iconsProvider}get iconsCollections(){return this._iconsCollections}get experimentalFeatures(){return this._experimentalFeatures}addCollection(t,r=this._iconsProvider){return this._iconsCollections.push(t),e(t,r)}addIcon(e,r){return t(e,r)}addIconsAPIProvider(e,t){return r(e,t)}fetchIcon(e,t={cache:"force-cache"}){return new Promise((r,n)=>{fetch(e,{...this._fetchOptions,...t}).catch(e=>n(e)).then(e=>e?.text()).then(e=>r(e))})}}const m={install(e,t={}){const r=new d(t);e.config.globalProperties.$vv=r,t.components&&Object.entries(t.components).forEach(([r,n])=>{e.component(r,p(n,t.defaults))}),t.aliases&&Object.entries(t.aliases).forEach(([r,n])=>{e.component(r,p(n,t.defaults,r))}),t.directives&&Object.entries(t.directives).forEach(([t,r])=>{const n=function(e,t){return f(e,{delimiter:"-",...t})}(t);n.startsWith("v-")&&(t=n.substring(2).toLocaleLowerCase()),e.directive(t,r)}),e.provide(h,r)}};export{m as VolverPlugin};