{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/resolvers/index.ts"],"sourcesContent":["import type {ComponentResolver} from 'unplugin-vue-components'\nimport {\n  componentNames,\n  componentsWithExternalPath,\n  type ComponentType,\n  type ConfigurationOption,\n  directiveNames,\n  directivesWithExternalPath,\n  type DirectiveType,\n} from '../types/BootstrapVueOptions'\n\nconst bvKey = 'bootstrap-vue-next'\n\nconst parseActiveImports = <Type extends string, Base extends ConfigurationOption<Type>>(\n  options: Readonly<Base>,\n  values: readonly Type[]\n): Type[] => {\n  const {all, ...others} = options\n  const valuesCopy: Partial<Record<keyof Base, boolean>> = {}\n  if (all) {\n    values.forEach((el) => {\n      valuesCopy[el] = all\n    })\n  }\n  const merge: Record<string, boolean> = {...valuesCopy, ...others}\n  return (\n    Object.entries(merge)\n      // filtering possible invalid keys\n      .filter(([name, value]) => !!value && values.includes(name as Type))\n      .map(([name]) => name as Type)\n  )\n}\n\nconst usedComponents = new Set<string>()\nconst usedDirectives = new Set<string>()\n\n/**\n * Resolver for unplugin-vue-components\n *\n * Contains two hidden properties `__usedComponents` and `__usedDirectives` (both are `Set<string>`)\n * which are used to get the list of used components and directives.. You can use this list of used components.\n * It may not be fully accurate. It can be used to get a list of stuff to trim down, like css\n * @example\n * ```ts\n * const bootstrapVueNextResolver = BootstrapVueNextResolver()\n * console.info(bootstrapVueNextResolver.__usedComponents)\n * console.info(bootstrapVueNextResolver.__usedDirectives)\n *\n * // ... blah blah blah, `plugins: [Components({resolvers: [bootstrapVueNextResolver]})]` ...\n * ```\n */\nexport const BootstrapVueNextResolver = Object.assign(\n  ({\n    aliases = {},\n    directives = true,\n    components = true,\n  }: Readonly<{\n    components?: boolean | ConfigurationOption<ComponentType>\n    directives?: boolean | ConfigurationOption<DirectiveType>\n    aliases?: Record<string, ComponentType>\n  }> = {}): ComponentResolver[] => {\n    const selectedComponents = typeof components === 'boolean' ? {all: components} : components\n    // <ComponentType, ImportPath>\n    const compImports = parseActiveImports(selectedComponents, componentNames).reduce(\n      (map, name) => {\n        map.set(name, `${bvKey}${componentsWithExternalPath[name]}`)\n        return map\n      },\n      new Map<string, string>()\n    )\n\n    const selectedDirectives = typeof directives === 'boolean' ? {all: directives} : directives\n    // <DirectiveType, ImportPath>\n    const dirImports = parseActiveImports(selectedDirectives, directiveNames).reduce(\n      (map, directive) => {\n        const key = (\n          directive.toLowerCase().startsWith('v') ? directive : `v${directive}`\n        ) as DirectiveType\n        map.set(key, `${bvKey}${directivesWithExternalPath[key]}`)\n        return map\n      },\n      new Map<string, string>()\n    )\n\n    return [\n      {\n        type: 'component',\n        resolve(name) {\n          const destination = compImports.get(name)\n          const aliasDestination =\n            aliases[name] === undefined ? undefined : compImports.get(aliases[name])\n          if (aliasDestination) {\n            const val = aliases[name]\n            if (val !== undefined) {\n              usedComponents.add(val)\n            }\n            return {\n              name: val,\n              from: aliasDestination,\n            }\n          }\n\n          if (destination) {\n            usedComponents.add(name)\n            return {\n              name,\n              from: destination,\n            }\n          }\n        },\n      },\n      {\n        type: 'directive',\n        resolve(name) {\n          const prefixedName = `v${name}`\n          const destination = dirImports.get(prefixedName)\n          if (destination) {\n            usedDirectives.add(prefixedName)\n            return {\n              name: prefixedName,\n              from: destination,\n            }\n          }\n        },\n      },\n    ]\n  },\n  {\n    __usedComponents: usedComponents,\n    __usedDirectives: usedDirectives,\n  }\n)\n"],"mappings":";;;;AAWA,IAAM,QAAQ;AAEd,IAAM,sBACJ,SACA,WACW;CACX,MAAM,EAAC,KAAK,GAAG,WAAU;CACzB,MAAM,aAAmD,EAAE;AAC3D,KAAI,IACF,QAAO,SAAS,OAAO;AACrB,aAAW,MAAM;GACjB;CAEJ,MAAM,QAAiC;EAAC,GAAG;EAAY,GAAG;EAAO;AACjE,QACE,OAAO,QAAQ,MAAM,CAElB,QAAQ,CAAC,MAAM,WAAW,CAAC,CAAC,SAAS,OAAO,SAAS,KAAa,CAAC,CACnE,KAAK,CAAC,UAAU,KAAa;;AAIpC,IAAM,iCAAiB,IAAI,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