{"version":3,"file":"directive.cjs","sources":["../../../components/spin/directive.ts"],"sourcesContent":["import { Spin } from '@/components/spin'\n\nimport { createVNode, nextTick, render } from 'vue'\n\nimport { isObject } from '@vexip-ui/utils'\n\nimport type { ObjectDirective, VNode } from 'vue'\n\ninterface LoadingRecord {\n  spin: VNode,\n  props: any,\n  originPosition: string\n}\n\nexport const loading: ObjectDirective<HTMLElement & { __loading?: LoadingRecord }, any> = {\n  mounted(el, binding) {\n    nextTick(() => {\n      const props = isObject(binding.value)\n        ? { ...binding.value }\n        : ({ active: binding.value } as any)\n\n      props.inner = true\n\n      const spin = createVNode(Spin, props, null, 0, Object.keys(props))\n      const position = getComputedStyle(el).position\n\n      el.__loading = {\n        spin,\n        props,\n        originPosition: position,\n      }\n\n      if (position === 'static') {\n        el.style.position = 'relative'\n      }\n\n      render(spin, el)\n    })\n  },\n  updated(el, binding) {\n    nextTick(() => {\n      if (!el.__loading) return\n\n      const props = isObject(binding.value) ? binding.value : { active: binding.value }\n      const component = el.__loading.spin.component\n\n      if (component) {\n        Object.keys(props).forEach(key => {\n          component.props[key] = props[key]\n        })\n\n        component.props.inner = true\n      }\n    })\n  },\n  beforeUnmount(el) {\n    if (!el.__loading) return\n\n    render(null, el)\n    delete el.__loading\n  },\n}\n"],"names":["loading","el","binding","nextTick","props","isObject","spin","createVNode","Spin","position","render","component","key"],"mappings":"wLAcaA,EAA6E,CACxF,QAAQC,EAAIC,EAAS,CACnBC,EAAAA,SAAS,IAAM,CACb,MAAMC,EAAQC,EAAAA,SAASH,EAAQ,KAAK,EAChC,CAAE,GAAGA,EAAQ,KAAM,EAClB,CAAE,OAAQA,EAAQ,KAAM,EAE7BE,EAAM,MAAQ,GAER,MAAAE,EAAOC,cAAYC,EAAMJ,EAAO,KAAM,EAAG,OAAO,KAAKA,CAAK,CAAC,EAC3DK,EAAW,iBAAiBR,CAAE,EAAE,SAEtCA,EAAG,UAAY,CACb,KAAAK,EACA,MAAAF,EACA,eAAgBK,CAClB,EAEIA,IAAa,WACfR,EAAG,MAAM,SAAW,YAGtBS,EAAA,OAAOJ,EAAML,CAAE,CAAA,CAChB,CACH,EACA,QAAQA,EAAIC,EAAS,CACnBC,EAAAA,SAAS,IAAM,CACT,GAAA,CAACF,EAAG,UAAW,OAEb,MAAAG,EAAQC,EAAAA,SAASH,EAAQ,KAAK,EAAIA,EAAQ,MAAQ,CAAE,OAAQA,EAAQ,KAAM,EAC1ES,EAAYV,EAAG,UAAU,KAAK,UAEhCU,IACF,OAAO,KAAKP,CAAK,EAAE,QAAeQ,GAAA,CAChCD,EAAU,MAAMC,CAAG,EAAIR,EAAMQ,CAAG,CAAA,CACjC,EAEDD,EAAU,MAAM,MAAQ,GAC1B,CACD,CACH,EACA,cAAcV,EAAI,CACXA,EAAG,YAERS,EAAA,OAAO,KAAMT,CAAE,EACf,OAAOA,EAAG,UAAA,CAEd"}