{"version":3,"file":"index.cjs","sources":["../../../src/containers/xy-container/index.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T\">\nimport { XYContainer, XYComponentCore, XYContainerConfigInterface, Tooltip, Crosshair, Axis, Annotations } from '@unovis/ts'\nimport { onUnmounted, ref, provide, watch, toRefs, reactive, watchEffect, toRaw } from 'vue'\nimport { componentAccessorKey, tooltipAccessorKey, axisAccessorKey, crosshairAccessorKey, annotationsAccessorKey } from \"../../utils/context\"\nimport { useForwardProps } from \"../../utils/props\"\n\nconst props = defineProps<XYContainerConfigInterface<T> & { data?: T[] }>()\nconst { data } = toRefs(props)\nconst parsedProps = useForwardProps(props)\n\nconst chart = ref<XYContainer<T>>()\nconst config = reactive({\n  components: [],\n  annotations: undefined,\n  crosshair: undefined,\n  tooltip: undefined,\n  xAxis: undefined,\n  yAxis: undefined,\n}) as XYContainerConfigInterface<T>\nconst elRef = ref<HTMLDivElement>()\n\nconst initChart = () => {\n  if (chart.value || !elRef.value) return\n  // config holds only child-registration slots — if all are empty, no slot has registered yet\n  const hasContent = Object.values(config).some(v => Array.isArray(v) ? v.length : v)\n  if (!hasContent) return\n  chart.value = new XYContainer(elRef.value, { ...toRaw(config) }, data.value)\n}\n\nwatchEffect(() => {\n  initChart()\n  // touch deep changes in components config to track them\n  const t = config.components.map(i => i.config)\n  chart.value?.updateContainer({ ...toRaw(parsedProps.value), ...toRaw(config) })\n})\n\nwatch(data, () => {\n  if (chart.value) chart.value.setData(data.value, true)\n  else initChart()\n})\n\nonUnmounted(() => chart.value?.destroy())\n\nprovide(componentAccessorKey, {\n  data,\n  update: (c: XYComponentCore<T>) => config.components = [...config.components!, c],\n  destroy: () => config.components = config.components?.filter(c => !c.isDestroyed()),\n})\n\nprovide(axisAccessorKey, {\n  data,\n  update: (c: Axis<T>) => config[`${c.config.type}Axis`] = c,\n  destroy: (c) => { config[`${c}Axis`] = undefined },\n})\n\nprovide(crosshairAccessorKey, {\n  data,\n  update: (c: Crosshair<T>) => config.crosshair = c,\n  destroy: () => { config.crosshair = 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\ndefineExpose({\n  component: chart\n})\n</script>\n\n<template>\n  <div data-vis-xy-container ref=\"elRef\" class='unovis-xy-container'>\n    <slot />\n  </div>\n</template>\n\n\n<style>\n.unovis-xy-container {\n  display: block;\n  position: relative;\n  width: 100%;\n}\n</style>\n"],"names":["props","__props","data","toRefs","parsedProps","useForwardProps","chart","ref","config","reactive","elRef","initChart","v","XYContainer","toRaw","watchEffect","i","watch","onUnmounted","provide","componentAccessorKey","c","axisAccessorKey","crosshairAccessorKey","tooltipAccessorKey","t","annotationsAccessorKey","a","__expose","_createElementBlock","_renderSlot","_ctx"],"mappings":"mzBAMA,MAAMA,EAAQC,EACR,CAAE,KAAAC,CAAA,EAASC,EAAAA,OAAOH,CAAK,EACvBI,EAAcC,EAAAA,gBAAgBL,CAAK,EAEnCM,EAAQC,EAAAA,IAAA,EACRC,EAASC,EAAAA,SAAS,CACtB,WAAY,CAAA,EACZ,YAAa,OACb,UAAW,OACX,QAAS,OACT,MAAO,OACP,MAAO,MAAA,CACR,EACKC,EAAQH,EAAAA,IAAA,EAERI,EAAY,IAAM,CAClBL,EAAM,OAAS,CAACI,EAAM,OAGtB,CADe,OAAO,OAAOF,CAAM,EAAE,KAAKI,GAAK,MAAM,QAAQA,CAAC,EAAIA,EAAE,OAASA,CAAC,IAElFN,EAAM,MAAQ,IAAIO,EAAAA,YAAYH,EAAM,MAAO,CAAE,GAAGI,EAAAA,MAAMN,CAAM,GAAKN,EAAK,KAAK,EAC7E,EAEAa,OAAAA,EAAAA,YAAY,IAAM,CAChBJ,EAAA,EAEUH,EAAO,WAAW,IAAIQ,GAAKA,EAAE,MAAM,EAC7CV,EAAM,O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