{"version":3,"file":"timeline-item.vue2.cjs","sources":["../../../components/timeline/timeline-item.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { computed, inject, onBeforeUnmount, onMounted, onUpdated, reactive, ref, watch } from 'vue'\n\nimport { emitEvent, useNameHelper, useProps } from '@vexip-ui/config'\nimport { timelineItemProps } from './props'\nimport { TIMELINE_STATE, timelineItemTypes } from './symbol'\n\nimport type { ItemState } from './symbol'\n\ndefineOptions({ name: 'TimelineItem' })\n\nconst _props = defineProps(timelineItemProps)\nconst props = useProps('timelineItem', _props, {\n  type: {\n    default: 'primary',\n    validator: value => timelineItemTypes.includes(value),\n  },\n  color: '',\n  label: {\n    default: null,\n    static: true,\n  },\n  dashed: null,\n  lineColor: null,\n  spacing: null,\n})\n\ndefineSlots<{\n  default: () => any,\n  signal: () => any,\n  line: () => any\n}>()\n\nconst timelineState = inject(TIMELINE_STATE, null)\n\nconst nh = useNameHelper('timeline')\nconst currentLabel = ref(props.label)\nconst content = ref<HTMLElement>()\n\nconst className = computed(() => {\n  return {\n    [nh.be('item')]: true,\n    [nh.bem('item', props.type)]: timelineItemTypes.includes(props.type),\n  }\n})\nconst itemStyle = computed(() => {\n  const spacing = props.spacing || props.spacing === 0 ? props.spacing : timelineState?.spacing\n  const style: Record<string, any> = {\n    [nh.cv('item-span')]: typeof spacing === 'number' ? `${spacing}px` : spacing,\n  }\n\n  if (props.color) {\n    style[nh.cv('pointer-color')] = props.color\n    style[nh.cv('pointer-b-color')] = props.color\n  }\n\n  return style\n})\nconst lineStyle = computed(() => {\n  const isDashed = props.dashed ?? timelineState?.dashed ?? false\n  const color = props.lineColor ?? timelineState?.lineColor\n\n  return {\n    borderInlineStartStyle: isDashed ? ('dashed' as const) : undefined,\n    borderInlineStartColor: color,\n  }\n})\n\ndefineExpose({ currentLabel, content })\n\nif (timelineState) {\n  const state: ItemState = reactive({\n    label: currentLabel,\n    index: 0,\n    total: 0,\n    height: 0,\n  })\n\n  timelineState.increaseItem(state)\n\n  watch(() => timelineState.alternate, updateHeight)\n  watch(() => timelineState.horizontal, updateHeight)\n\n  onMounted(updateHeight)\n  onUpdated(updateHeight)\n\n  onBeforeUnmount(() => {\n    timelineState.decreaseItem(state)\n  })\n\n  function updateHeight() {\n    requestAnimationFrame(() => {\n      if (timelineState?.horizontal && content.value) {\n        state.height = content.value.scrollHeight\n      }\n    })\n  }\n}\n\nfunction handleSignalClick() {\n  emitEvent(props.onSignalClick, currentLabel.value)\n  timelineState?.handleSignalClick(currentLabel.value)\n}\n</script>\n\n<template>\n  <div :class=\"className\" :style=\"itemStyle\">\n    <div :class=\"nh.be('signal')\" @click=\"handleSignalClick\">\n      <slot name=\"signal\">\n        <div :class=\"nh.be('pointer')\"></div>\n      </slot>\n    </div>\n    <div :class=\"nh.be('line')\" :style=\"lineStyle\">\n      <slot name=\"line\"></slot>\n    </div>\n    <div ref=\"content\" :class=\"nh.be('content')\">\n      <slot></slot>\n    </div>\n  </div>\n</template>\n"],"names":["_props","__props","props","useProps","value","timelineItemTypes","timelineState","inject","TIMELINE_STATE","nh","useNameHelper","currentLabel","ref","content","className","computed","itemStyle","spacing","style","lineStyle","isDashed","color","__expose","updateHeight","state","reactive","watch","onMounted","onUpdated","onBeforeUnmount","handleSignalClick","emitEvent","_createElementBlock","_createElementVNode","_normalizeClass","_unref","_renderSlot","_ctx"],"mappings":"mOAWA,MAAMA,EAASC,EACTC,EAAQC,EAAAA,SAAS,eAAgBH,EAAQ,CAC7C,KAAM,CACJ,QAAS,UACT,UAAWI,GAASC,EAAkB,kBAAA,SAASD,CAAK,CACtD,EACA,MAAO,GACP,MAAO,CACL,QAAS,KACT,OAAQ,EACV,EACA,OAAQ,KACR,UAAW,KACX,QAAS,IAAA,CACV,EAQKE,EAAgBC,EAAAA,OAAOC,EAAA,eAAgB,IAAI,EAE3CC,EAAKC,gBAAc,UAAU,EAC7BC,EAAeC,EAAAA,IAAIV,EAAM,KAAK,EAC9BW,EAAUD,EAAAA,IAAiB,EAE3BE,EAA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