{"version":3,"file":"index.mjs","sources":["../../../packages/mousetool/index.ts"],"sourcesContent":["import { defineComponent, onBeforeMount, onUnmounted } from \"vue\";\r\nimport type { ToolInstances } from \"./types\";\r\nimport { useMapRoot } from \"~/use/mapRoot\";\r\nimport { EVENTS, PROPS, useEvent, useInit, useWatch } from \"./use\";\r\n\r\nexport const TdtMousetool = defineComponent({\r\n  name: \"TdtMousetool\",\r\n  props: PROPS,\r\n  emits: EVENTS,\r\n  setup(props, { emit, expose }) {\r\n    onBeforeMount(async () => {\r\n      onUnmounted(() => clearAll());\r\n\r\n      expose?.({ open, close, clear, clearAll });\r\n\r\n      const tdtMap = await useMapRoot();\r\n      const tdtComponent = useInit(props, tdtMap);\r\n      useEvent({ emit, instances: tdtComponent });\r\n      useWatch({ props, instances: tdtComponent });\r\n      emit(\"init\", tdtComponent);\r\n\r\n      function open(toolName: keyof ToolInstances) {\r\n        tdtComponent[toolName]?.open();\r\n      }\r\n\r\n      function close(toolName: keyof ToolInstances) {\r\n        tdtComponent[toolName]?.close();\r\n      }\r\n\r\n      function clear(toolName: keyof ToolInstances) {\r\n        try {\r\n          tdtComponent[toolName]?.clear();\r\n        } catch (e) {\r\n          // 当图层中没有该类型的图形时会报错，可忽略\r\n          console.error(e);\r\n        }\r\n      }\r\n\r\n      function clearAll() {\r\n        Object.keys(tdtComponent).forEach(toolName => {\r\n          close(toolName as keyof ToolInstances);\r\n          clear(toolName as keyof ToolInstances);\r\n        });\r\n      }\r\n    });\r\n\r\n    return () => {};\r\n  }\r\n});\r\n\r\nexport type TdtMousetoolInstance = InstanceType<typeof TdtMousetool>;\r\n"],"names":["TdtMousetool","defineComponent","PROPS","EVENTS","props","emit","expose","onBeforeMount","onUnmounted","clearAll","open","close","clear","tdtMap","useMapRoot","tdtComponent","useInit","useEvent","useWatch","toolName","_a","e"],"mappings":";;;;;;AAKO,MAAMA,IAAeC,EAAgB;AAAA,EAC1C,MAAM;AAAA,EACN,OAAOC;AAAA,EACP,OAAOC;AAAA,EACP,MAAMC,GAAO,EAAE,MAAAC,GAAM,QAAAC,KAAU;AAC7B,WAAAC,EAAc,YAAY;AACZ,MAAAC,EAAA,MAAMC,GAAU,GAE5BH,KAAA,QAAAA,EAAS,EAAE,MAAAI,GAAM,OAAAC,GAAO,OAAAC,GAAO,UAAAH;AAEzB,YAAAI,IAAS,MAAMC,EAAW,GAC1BC,IAAeC,EAAQZ,GAAOS,CAAM;AAC1C,MAAAI,EAAS,EAAE,MAAAZ,GAAM,WAAWU,EAAA,CAAc,GAC1CG,EAAS,EAAE,OAAAd,GAAO,WAAWW,EAAA,CAAc,GAC3CV,EAAK,QAAQU,CAAY;AAEzB,eAASL,EAAKS,GAA+B;;AAC9B,SAAAC,IAAAL,EAAAI,CAAQ,MAAR,QAAAC,EAAW;AAAA,MAAK;AAG/B,eAAST,EAAMQ,GAA+B;;AAC/B,SAAAC,IAAAL,EAAAI,CAAQ,MAAR,QAAAC,EAAW;AAAA,MAAM;AAGhC,eAASR,EAAMO,GAA+B;;AACxC,YAAA;AACW,WAAAC,IAAAL,EAAAI,CAAQ,MAAR,QAAAC,EAAW;AAAA,iBACjBC,GAAG;AAEV,kBAAQ,MAAMA,CAAC;AAAA,QAAA;AAAA,MACjB;AAGF,eAASZ,IAAW;AAClB,eAAO,KAAKM,CAAY,EAAE,QAAQ,CAAYI,MAAA;AAC5C,UAAAR,EAAMQ,CAA+B,GACrCP,EAAMO,CAA+B;AAAA,QAAA,CACtC;AAAA,MAAA;AAAA,IACH,CACD,GAEM,MAAM;AAAA,IAAC;AAAA,EAAA;AAElB,CAAC;"}