{"version":3,"file":"label.mjs","sources":["../src/label/Label.ts","../src/label/Label.vue"],"sourcesContent":["import type { PrimitiveProps } from '../primitive/index.ts'\nimport { type EmitsToHookProps, mergePrimitiveAttrs, type PrimitiveDefaultProps, type RadixPrimitiveReturns } from '../shared/index.ts'\n\nexport interface LabelProps {\n  as?: PrimitiveProps['as']\n}\n\nexport const DEFAULT_LABEL_PROPS = {\n  as: 'label',\n} satisfies PrimitiveDefaultProps<LabelProps>\n\nexport type LabelEmits = {\n  mousedown: [event: MouseEvent]\n}\n\nexport interface UseLabelProps extends EmitsToHookProps<LabelEmits> {}\n\nexport function useLabel(props?: UseLabelProps): RadixPrimitiveReturns {\n  function onMousedown(event: MouseEvent) {\n    // only prevent text selection if clicking inside the label itself\n    const target = event.target as HTMLElement\n    if (target.closest('button, input, select, textarea'))\n      return\n\n    props?.onMousedown?.(event)\n    // prevent text selection when double clicking label\n    if (!event.defaultPrevented && event.detail > 1)\n      event.preventDefault()\n  }\n\n  return {\n    attrs(extraAttrs) {\n      const attrs = {\n        onMousedown,\n      }\n\n      if (extraAttrs && extraAttrs.length > 0) {\n        mergePrimitiveAttrs(attrs, extraAttrs)\n      }\n\n      return attrs\n    },\n  }\n}\n","<script setup lang=\"ts\">\nimport { Primitive } from '../primitive/index.ts'\nimport { type EmitsToHookProps, normalizeAttrs } from '../shared/index.ts'\nimport { DEFAULT_LABEL_PROPS, type LabelEmits, type LabelProps, useLabel } from './Label.ts'\n\ndefineOptions({\n  name: 'RadixLabel',\n  inheritAttrs: false,\n})\n\nwithDefaults(defineProps<LabelProps>(), DEFAULT_LABEL_PROPS)\nconst emit = defineEmits<LabelEmits>()\n\nconst label = useLabel({\n  onMousedown(event) {\n    emit('mousedown', event)\n  },\n} satisfies Required<EmitsToHookProps<LabelEmits>>)\n</script>\n\n<template>\n  <Primitive v-bind=\"normalizeAttrs(label.attrs([$attrs, { as }]))\">\n    <slot />\n  </Primitive>\n</template>\n"],"names":[],"mappings":";;;;AAOO,MAAM,mBAAsB,GAAA;AAAA,EACjC,EAAI,EAAA;AACN,CAAA;AAQO,SAAS,SAAS,KAA8C,EAAA;AACrE,EAAA,SAAS,YAAY,KAAmB,EAAA;AAEtC,IAAA,MAAM,SAAS,KAAM,CAAA,MAAA;AACrB,IAAI,IAAA,MAAA,CAAO,QAAQ,iCAAiC,CAAA;AAClD,MAAA;AAEF,IAAA,KAAA,EAAO,cAAc,KAAK,CAAA;AAE1B,IAAA,IAAI,CAAC,KAAA,CAAM,gBAAoB,IAAA,KAAA,CAAM,MAAS,GAAA,CAAA;AAC5C,MAAA,KAAA,CAAM,cAAe,EAAA;AAAA;AAGzB,EAAO,OAAA;AAAA,IACL,MAAM,UAAY,EAAA;AAChB,MAAA,MAAM,KAAQ,GAAA;AAAA,QACZ;AAAA,OACF;AAEA,MAAI,IAAA,UAAA,IAAc,UAAW,CAAA,MAAA,GAAS,CAAG,EAAA;AACvC,QAAA,mBAAA,CAAoB,OAAO,UAAU,CAAA;AAAA;AAGvC,MAAO,OAAA,KAAA;AAAA;AACT,GACF;AACF;;;;;;;;;;;;;AChCA,IAAA,MAAM,IAAO,GAAA,MAAA;AAEb,IAAA,MAAM,QAAQ,QAAS,CAAA;AAAA,MACrB,YAAY,KAAO,EAAA;AACjB,QAAA,IAAA,CAAK,aAAa,KAAK,CAAA;AAAA;AACzB,KACgD,CAAA;;;;;;;;;;;;;;"}