omi-vueify
Version:
Bridge between omi and vue
2 lines (1 loc) • 2.06 kB
JavaScript
(function(p,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],r):(p=typeof globalThis<"u"?globalThis:p||self,r(p.OmiVueify={},p.vue))})(this,function(p,r){"use strict";function O(e,o){return r.defineComponent({name:e,inheritAttrs:!1,setup(a,{emit:m,attrs:d,slots:i,expose:h}){const f=r.ref(null),{methodNames:z}=o,w={};z.forEach(t=>{w[t]=(...n)=>{var c,u;if(f.value)return(u=(c=f.value)[t])==null?void 0:u.call(c,...n)}}),h(w);const y=C(d),L=Object.keys(d).filter(t=>t.match(/^on[A-Za-z]/)).map(t=>R(t)),j=new Map;return r.onMounted(()=>{L.forEach(t=>{var u;const n=A(t);if(!T(n)&&t!==n)return;const c=s=>{m(n,s)};j.set(t,c),(u=f.value)==null||u.addEventListener(t,c)}),Object.entries(y.value).forEach(([t,n])=>{typeof n=="function"&&(f.value[E(t)]=n,delete y.value[t])})}),r.onBeforeUnmount(()=>{j.forEach((t,n)=>{var c;(c=f.value)==null||c.removeEventListener(n,t)}),j.clear()}),()=>{const t=[];return i.default&&t.push(...i.default()),Object.keys(i).forEach(n=>{var u;if(n==="default")return;const c=(u=i[n])==null?void 0:u.call(i);c&&c.forEach(s=>{Array.isArray(s)?s.forEach(b=>{b&&typeof b=="object"&&(b.props={...b.props||{},slot:n})}):s&&typeof s=="object"&&(s.props={...s.props||{},slot:n}),t.push(s)})}),r.h(e,{ref:f,...a,...y.value},t)}}})}const R=e=>{const o=e.slice(2);return o[0].toLowerCase()+o.slice(1)},T=e=>e.includes("-"),A=e=>e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase(),E=e=>e.replace(/-([a-z])/g,(o,a)=>a.toUpperCase()),l=e=>{if(r.isRef(e))return l(e.value);if(r.isReactive(e)&&(e=r.toRaw(e)),Array.isArray(e))return e.map(l);if(e&&typeof e=="object"){const o={};for(const a in e)o[a]=l(e[a]);return o}return e},C=e=>{const o=r.ref({});return r.watch(()=>Object.entries(e),a=>{const m={};a.forEach(([d,i])=>{if(!d.match(/^on[A-Za-z]/)){let h=d,f=i;(r.isRef(i)||r.isReactive(i))&&(f=l(i)),f&&typeof f=="object"?h=E(d):h=A(d),m[h]=f}}),o.value=m},{immediate:!0,deep:!0}),o};p.omiVueify=O,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});