{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/directives/BScrollspy/index.ts"],"sourcesContent":["import {type Directive, type DirectiveBinding} from 'vue'\nimport {useScrollspy} from '../../composables/useScrollspy'\nimport {omit} from '../../utils/object'\nimport {getDirectiveUid} from '../utils'\nimport {getSafeDocument} from '../../utils/dom'\n\nexport interface ElementWithScrollspy extends HTMLElement {\n  $__scrollspy?: Record<number, ReturnType<typeof useScrollspy>>\n}\n\nconst bind = (el: ElementWithScrollspy, binding: Readonly<DirectiveBinding>) => {\n  // SSR guard: skip on server\n  const doc = getSafeDocument()\n  if (doc === null) return\n\n  const uid = getDirectiveUid(binding)\n\n  // Initialize UID namespace for this directive\n  const elWithScrollspy = el as ElementWithScrollspy & Record<string, unknown>\n  elWithScrollspy.$__scrollspy = elWithScrollspy.$__scrollspy ?? Object.create(null)\n\n  // Clean up existing instance if present\n  const existingInstance = elWithScrollspy.$__scrollspy![uid]\n  if (existingInstance) {\n    existingInstance.cleanup()\n  }\n\n  const {arg, value} = binding\n  const isObject = typeof value === 'object' && value !== null\n  const content = arg\n    ? arg\n    : typeof value === 'string'\n      ? value\n      : isObject\n        ? value.content || value.element\n        : null\n\n  // Store scrollspy instance for this component instance\n  elWithScrollspy.$__scrollspy![uid] = useScrollspy(\n    content,\n    el,\n    isObject ? omit(value, ['content', 'element']) : {}\n  )\n}\n\nexport const vBScrollspy: Directive<ElementWithScrollspy> = {\n  mounted: bind,\n  updated: bind,\n  beforeUnmount(el, binding) {\n    const uid = getDirectiveUid(binding)\n    const elWithScrollspy = el as ElementWithScrollspy & Record<string, unknown>\n    const instance = elWithScrollspy.$__scrollspy?.[uid]\n\n    if (!instance) return\n\n    instance.cleanup()\n    delete elWithScrollspy.$__scrollspy![uid]\n  },\n}\n"],"mappings":";;;;;;AAUA,IAAM,QAAQ,IAA0B,YAAwC;AAG9E,KADY,iBAAiB,KACjB,KAAM;CAElB,MAAM,MAAM,gBAAgB,QAAQ;CAGpC,MAAM,kBAAkB;AACxB,iBAAgB,eAAe,gBAAgB,gBAAgB,OAAO,OAAO,KAAK;CAGlF,MAAM,mBAAmB,gBAAgB,aAAc;AACvD,KAAI,iBACF,kBAAiB,SAAS;CAG5B,MAAM,EAAC,KAAK,UAAS;CACrB,MAAM,WAAW,OAAO,UAAU,YAAY,UAAU;CACxD,MAAM,UAAU,MACZ,MACA,OAAO,UAAU,WACf,QACA,WACE,MAAM,WAAW,MAAM,UACvB;AAGR,iBAAgB,aAAc,OAAO,aACnC,SACA,IACA,WAAW,KAAK,OAAO,CAAC,WAAW,UAAU,CAAC,GAAG,EAAE,CACpD;;AAGH,IAAa,cAA+C;CAC1D,SAAS;CACT,SAAS;CACT,cAAc,IAAI,SAAS;EACzB,MAAM,MAAM,gBAAgB,QAAQ;EACpC,MAAM,kBAAkB;EACxB,MAAM,WAAW,gBAAgB,eAAe;AAEhD,MAAI,CAAC,SAAU;AAEf,WAAS,SAAS;AAClB,SAAO,gBAAgB,aAAc;;CAExC"}