{"version":3,"file":"index.cjs","sources":["../../../src/containers/single-container/index.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T\">\nimport { SingleContainer, ComponentCore, SingleContainerConfigInterface, Tooltip, Annotations } from '@unovis/ts'\nimport { onUnmounted, ref, provide, watch, toRefs, watchEffect, reactive, toRaw } from 'vue'\nimport { annotationsAccessorKey, componentAccessorKey, tooltipAccessorKey,  } from \"../../utils/context\"\nimport { useForwardProps } from \"../../utils/props\"\n\nconst props = defineProps<SingleContainerConfigInterface<T> & { data?: T }>()\nconst { data } = toRefs(props)\nconst parsedProps = useForwardProps(props)\n\nlet chart: SingleContainer<T>\nconst config = reactive({\n  component: undefined,\n  tooltip: undefined,\n  annotations: undefined,\n}) as SingleContainerConfigInterface<T>\nconst elRef = ref<HTMLDivElement>()\n\nconst initChart = () => {\n  if (chart) return\n  if (elRef.value && config.component)\n    chart = new SingleContainer(elRef.value, { ...toRaw(config) }, data.value)\n}\n\nwatchEffect(() => {\n  initChart()\n  // watch deep changes in components config\n  const t = config.component?.config\n  chart?.updateContainer({ ...toRaw(parsedProps.value), ...toRaw(config) })\n})\n\nwatch(data, () => {\n  if (chart) {\n    chart.setData(data.value, true)\n  } else {\n    initChart()\n  }\n})\n\nonUnmounted(() => chart?.destroy())\n\nprovide(componentAccessorKey, {\n  data,\n  update: (c: ComponentCore<T>) => config.component = c,\n  destroy: () => config.component = undefined,\n})\n\nprovide(tooltipAccessorKey, {\n  data,\n  update: (t: Tooltip) => config.tooltip = t,\n  destroy: () => { config.tooltip = undefined },\n})\n\nprovide(annotationsAccessorKey, {\n  data,\n  update: (a: Annotations) => config.annotations = a,\n  destroy: () => { config.annotations = undefined },\n})\n\n\ndefineExpose({\n  component: chart\n})\n</script>\n\n<template>\n  <div data-vis-single-container ref=\"elRef\" class='unovis-single-container'>\n    <slot />\n  </div>\n</template>\n\n\n\n<style>\n.unovis-single-container {\n  display: block;\n  position: relative;\n  width: 100%;\n}\n</style>\n"],"names":["props","__props","data","toRefs","parsedProps","useForwardProps","chart","config","reactive","elRef","ref","initChart","SingleContainer","toRaw","watchEffect","watch","onUnmounted","provide","componentAccessorKey","c","tooltipAccessorKey","t","annotationsAccessorKey","a","__expose","_createElementBlock","_renderSlot","_ctx"],"mappings":"ycAMA,MAAMA,EAAQC,EACR,CAAE,KAAAC,CAAA,EAASC,EAAAA,OAAOH,CAAK,EACvBI,EAAcC,EAAAA,gBAAgBL,CAAK,EAEzC,IAAIM,EACJ,MAAMC,EAASC,EAAAA,SAAS,CACtB,UAAW,OACX,QAAS,OACT,YAAa,MAAA,CACd,EACKC,EAAQC,EAAAA,IAAA,EAERC,EAAY,IAAM,CAClBL,GACAG,EAAM,OAASF,EAAO,YACxBD,EAAQ,IAAIM,EAAAA,gBAAgBH,EAAM,MAAO,CAAE,GAAGI,EAAAA,MAAMN,CAAM,CAAA,EAAKL,EAAK,KAAK,EAC7E,EAEAY,OAAAA,EAAAA,YAAY,IAAM,CAChBH,EAAA,EAEUJ,EAAO,WAAW,OAC5BD,GAAO,gBAAgB,CAAE,GAAGO,QAAMT,EAAY,KAAK,EAAG,GAAGS,EAAAA,MAAMN,CAAM,EAAG,CAC1E,CAAC,EAEDQ,EAAAA,MAAMb,EAAM,IAAM,CACZI,EACFA,EAAM,QAAQJ,EAAK,MAAO,EAAI,EAE9BS,EAAA,CAEJ,CAAC,EAEDK,cAAY,IAAMV,GAAO,SAAS,EAElCW,EAAAA,QAAQC,EAAAA,qBAAsB,CAC5B,KAAAhB,EACA,OAASiB,GAAwBZ,EAAO,UAAYY,EACpD,QAAS,IAAMZ,EAAO,UAAY,MAAA,CACnC,EAEDU,EAAAA,QAAQG,EAAAA,mBAAoB,CAC1B,KAAAlB,EACA,OAASmB,GAAed,EAAO,QAAUc,EACzC,QAAS,IAAM,CAAEd,EAAO,QAAU,MAAU,CAAA,CAC7C,EAEDU,EAAAA,QAAQK,EAAAA,uBAAwB,CAC9B,KAAApB,EACA,OAASqB,GAAmBhB,EAAO,YAAcgB,EACjD,QAAS,IAAM,CAAEhB,EAAO,YAAc,MAAU,CAAA,CACjD,EAGDiB,EAAa,CACX,UAAWlB,CAAA,CACZ,wBAICmB,EAAAA,mBAEM,MAAA,CAFD,4BAAA,WAA8B,QAAJ,IAAIhB,EAAQ,MAAM,yBAAA,GAC/CiB,aAAQC,EAAA,OAAA,SAAA,CAAA"}