UNPKG

tools-vue3

Version:
2 lines (1 loc) 3.72 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["tools-vue3"]={},e.vue)}(this,function(e,t){"use strict";const n="__scopeObjFun";class o{static map={};static get(e,n){const r=o,s=t.getCurrentInstance();return s?(r.map[e]||(r.map[e]={value:n(),refs:new Set}),r.map[e].refs.add(s),t.onUnmounted(()=>{r.map[e]?.refs.delete(s),0===r.map[e]?.refs.size&&delete r.map[e]}),r.map[e].value):n()}}e.CRouter=class{static init=e=>{const t=e.root||"/src/views";if(!e.modules)throw new Error("modules is required");const n=e.modules,o={},r=e.diffModules||{},s={},c=e.pathHook||(e=>e),a=(n,o)=>{Object.keys(o).forEach(r=>{let s=r.replace(t,"").replace(".vue","");const a=e.mapKeyPathHook?.(s)||r;n[a]={path:c(s),component:o[r],useNum:0}})};a(o,n),a(s,r);((e,t)=>{for(const n in t)n in e||(e[n]=t[n])})(o,s);const i=e.children||[],u=[],l=e=>{const t=Object.keys(o);for(let n=0;n<t.length;n++)if(o[t[n]].path===e)return o[t[n]]};if(i.length){const e=t=>{if(t.children=t.children||[],t.childrenList&&t.childrenList.forEach(e=>{const n=l(e);n&&(t.children.push({path:e,component:n.component}),n.useNum++)}),t.children&&t.children.forEach(t=>{e(t)}),t.component){const e=l(t.component);e&&(t.component=e.component,e.useNum++)}if(t.childrenReg){const e=(n=t.childrenReg,Array.isArray(n)?n.map(e=>e instanceof RegExp?e:new RegExp(e)):n instanceof RegExp?[n]:n?[new RegExp(n)]:[]);Object.keys(o).forEach(n=>{e.some(e=>e.test(n))&&(t.children.push({path:n,component:o[n].component}),o[n].useNum++)})}var n};for(let t=0;t<i.length;t++){const n=i[t];e(n),u.push(n)}}Object.keys(o).forEach(e=>{0===o[e].useNum&&u.push({path:e,component:o[e].component})});const p=t=>{t.path=o[t.path].path,e.setInfoHook?.(t),t.children&&t.children.forEach(e=>{p(e)})};u.forEach(e=>{p(e)});const f={};return Object.keys(o).forEach(e=>{f[o[e].path]=o[e]}),{array:u,map:f}}},e.CVue3=class{static onDispose=e=>{const n=t.getCurrentInstance();let o=n.vnode.el?.parentElement?.parentElement,r=!1;const s=setInterval(()=>{if(r)return void clearInterval(s);const t=n.vnode.el?.parentElement?.parentElement;return void 0===o&&(o=t),o&&!t?(clearInterval(s),void e()):void 0},50);t.onUnmounted(()=>{r=!0,e()})};static createCom=e=>{let n=e.domOrIdOrClass||document.body;"string"==typeof n&&(n=document.querySelector(n));const o=(...e)=>{r.unmount(),r=void 0,e.forEach(e=>{e&&n.removeChild(e)}),n.removeChild(s)};e.props||(e.props={}),e.props.remove=o;let r=t.createApp(e.component,e.props);const s=document.createElement("div");return e.beforeMount&&e.beforeMount(r),r.mount(s),e.first?n.insertBefore(s,n.firstChild):n.appendChild(s),{vm:r,remove:o}}},e.Minxins=o,e.Scope=class{static setConf=(e,o)=>{o||"string"==typeof e||(o=e,e="conf");const r=t.getCurrentInstance();let s=o;if("function"!=typeof s&&(s=()=>o),r){let t=r[n];t||(t=[]),t.push({key:e,fun:s}),r[n]=t}};static getConf=(e,o)=>{e?"number"==typeof e&&(o=e,e="conf"):e="conf",o||(o=1);let r=t.getCurrentInstance(),s=0,c=()=>null;for(;r=r.parent;){const t=r[n];if(t)for(let n=0;n<t.length;n++){const r=t[n];if(r.key===e&&(s++,c=r.fun,s===o))return r.fun()}}return c()};static CEventBean=null;static CEventBeanDeactivated=!1;static Event=()=>{if(!this.CEventBean)return null;const e=t.getCurrentInstance(),n=new this.CEventBean;return n.vm=()=>()=>e.isDeactivated?this.CEventBeanDeactivated:!e.isUnmounted,n};static TimerBean=null;static TimerBeanDeactivated="pause";static Timer=()=>{if(!this.TimerBean)return null;const e=new this.TimerBean,n=t.getCurrentInstance();return e.vm=()=>()=>n.isDeactivated?this.TimerBeanDeactivated:!n.isUnmounted,e}}});