{"version":3,"file":"methods-BIHzAhXc.mjs","names":[],"sources":["../src/composables/methods.js"],"sourcesContent":["import { determineRouteUrl } from '../js/utilities'\n\nconst isEmpty = (d) => {\n  for (const i in d) {\n    return false\n  }\n\n  return true\n}\n\nexport const useMethods = () => {\n  const toggleActiveClass = (classList) => {\n    let index = classList.indexOf('active')\n\n    if (index !== -1) {\n      classList[index] = 'inactive'\n    } else {\n      index = classList.indexOf('inactive')\n      if (index !== -1) {\n        classList[index] = 'active'\n      }\n    }\n  }\n\n  const separateIds = (element, targetId) => {\n    const ids = element.getAttribute('ids')\n    if (ids !== null) {\n      let splitIds = ids.split(' ')\n      const targetIndex = splitIds.indexOf(targetId)\n      if (targetId && targetIndex !== -1) {\n        splitIds.splice(targetIndex, 1)\n        splitIds.unshift(targetId)\n      }\n      return { id: splitIds.shift(), extraIds: splitIds }\n    }\n    return {}\n  }\n\n  const dataObject = (element, additionalClasses) => {\n    let dO = {}\n\n    let classes = [...element.classList]\n    if (additionalClasses) {\n      classes = classes.concat(additionalClasses)\n    }\n\n    const id = extractId(element)\n    const attributes = extractAttributes(element)\n\n    if (classes.length) {\n      dO['class'] = classes\n    }\n    if (!isEmpty(attributes) || !isEmpty(id)) {\n      dO['attrs'] = {\n        ...id,\n        ...attributes,\n      }\n    }\n\n    return dO\n  }\n\n  const extractAttributes = (element) => {\n    const unrequiredAttrs = ['uri', 'ids', 'names', 'candidates', 'classes']\n    const styleAttrs = ['width']\n    let style = ''\n    let attrDict = {}\n    for (const attr of element.attributes) {\n      if (styleAttrs.includes(attr.name)) {\n        style += `${attr.name}: ${attr.value};`\n      } else if (!unrequiredAttrs.includes(attr.name)) {\n        attrDict[attr.name] = attr.value\n      }\n    }\n    if (style) {\n      attrDict.style = style\n    }\n    return attrDict\n  }\n\n  const extractId = (element) => {\n    // Inserting the id of the first term in a collection as the contents of the item.\n    const id = element.getAttribute('id')\n    if (id) {\n      return { id }\n    }\n    if (element.getAttribute('ids') && element.getAttribute('ids').length > 0) {\n      const ids = element.getAttribute('ids').split(' ')\n      const id = ids[0]\n      return {\n        id,\n      }\n    }\n    return {}\n  }\n\n  const determinePageLocation = (element) => {\n    const elementRefUri = element.getAttribute('refuri')\n    const hash = elementRefUri.split('#')[1]\n    return hash ? '#' + hash : ''\n  }\n\n  const determinePageName = (element, route) => {\n    const baseRefUri = determineRouteUrl(route)\n    const elementRefUri = element.getAttribute('refuri')\n    // Remove page from reference uri\n    let splitRefUri = elementRefUri.split('/')\n    let routePath = route.path.replace(baseRefUri, '')\n    // Remove the baseRefUri and make that our root location\n    let splitRoutePath = routePath.split('/')\n    // Remove the empty string from the beginning of the array\n    splitRoutePath.shift()\n    if (route.path !== baseRefUri) {\n      // The base reference uri is a special case usually we have to\n      // remove the page name from the route as well.\n      splitRoutePath.pop()\n    }\n    // Get the file name from the reference uri\n    const filePart = splitRefUri.pop()\n    const fileBaseName = filePart.split('#')[0]\n    // Remove up route if parent directory name found\n    while (splitRefUri[0] === '..') {\n      splitRefUri.shift()\n      splitRoutePath.pop()\n    }\n    return [...splitRoutePath, ...splitRefUri, fileBaseName].join('/')\n  }\n\n  const isInternalReference = (element) => {\n    const value = element.getAttribute('internal')\n    const internal = value && (value.toLowerCase() === 'true' || value === '1')\n    return internal || isReferenceToCurrentPage(element)\n  }\n\n  const isReferenceToCurrentPage = (element) => {\n    return element.hasAttribute('refid')\n  }\n\n  const parentLevelsInRefURI = (element) => {\n    let splitRefUri = element.getAttribute('refuri').split('/')\n    let count = 0\n    while (splitRefUri[0] === '..') {\n      splitRefUri.shift()\n      count++\n    }\n\n    return count\n  }\n\n  return {\n    dataObject,\n    determinePageLocation,\n    determinePageName,\n    extractId,\n    isInternalReference,\n    isReferenceToCurrentPage,\n    parentLevelsInRefURI,\n    separateIds,\n    toggleActiveClass,\n  }\n}\n"],"mappings":";;AAEA,IAAM,KAAW,MAAM;CACrB,KAAK,IAAM,KAAK,GACd,OAAO;CAGT,OAAO;AACT,GAEa,UAAmB;CAC9B,IAAM,KAA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