{"version":3,"file":"index.js","sources":["../src/state.ts","../src/config.ts","../src/plugins.ts","../src/transform.ts"],"sourcesContent":["import { parse as parsePath } from 'path'\n// @ts-ignore\nimport camelCase from 'camelcase'\nimport type { ConfigPlugin } from './plugins'\n\nexport interface State {\n  filePath?: string\n  componentName: string\n  caller?: {\n    name?: string\n    previousExport?: string | null\n    defaultPlugins?: ConfigPlugin[]\n  }\n}\n\nconst VALID_CHAR_REGEX = /[^a-zA-Z0-9 _-]/g\n\nconst getComponentName = (filePath?: string): string => {\n  if (!filePath) return 'SvgComponent'\n  const pascalCaseFileName = camelCase(\n    parsePath(filePath).name.replace(VALID_CHAR_REGEX, ''),\n    {\n      pascalCase: true,\n    },\n  )\n  return `Svg${pascalCaseFileName}`\n}\n\nexport const expandState = (state: Partial<State>): State => {\n  return {\n    componentName: state.componentName || getComponentName(state.filePath),\n    ...state,\n  }\n}\n","import { cosmiconfig, cosmiconfigSync } from 'cosmiconfig'\nimport type { Options as PrettierOptions } from 'prettier'\nimport type { Config as SvgoConfig } from 'svgo'\nimport type { Options as TransformOptions } from '@svgr/babel-preset'\nimport type { TransformOptions as BabelTransformOptions } from '@babel/core'\nimport type { ConfigPlugin } from './plugins'\nimport type { State } from './state'\n\nexport interface Config {\n  ref?: boolean\n  titleProp?: boolean\n  descProp?: boolean\n  expandProps?: boolean | 'start' | 'end'\n  dimensions?: boolean\n  icon?: boolean | string | number\n  native?: boolean\n  svgProps?: {\n    [key: string]: string\n  }\n  replaceAttrValues?: {\n    [key: string]: string\n  }\n  runtimeConfig?: boolean\n  typescript?: boolean\n  prettier?: boolean\n  prettierConfig?: PrettierOptions\n  svgo?: boolean\n  svgoConfig?: SvgoConfig\n  configFile?: string\n  template?: TransformOptions['template']\n  memo?: boolean\n  exportType?: 'named' | 'default'\n  namedExport?: string\n  jsxRuntime?: 'classic' | 'classic-preact' | 'automatic'\n  jsxRuntimeImport?: {\n    source: string\n    namespace?: string\n    specifiers?: string[]\n    defaultSpecifier?: string\n  }\n\n  // CLI only\n  index?: boolean\n  plugins?: ConfigPlugin[]\n\n  // JSX\n  jsx?: {\n    babelConfig?: BabelTransformOptions\n  }\n}\n\nexport const DEFAULT_CONFIG: Config = {\n  dimensions: true,\n  expandProps: 'end',\n  icon: false,\n  native: false,\n  typescript: false,\n  prettier: true,\n  prettierConfig: undefined,\n  memo: false,\n  ref: false,\n  replaceAttrValues: undefined,\n  svgProps: undefined,\n  svgo: true,\n  svgoConfig: undefined,\n  template: undefined,\n  index: false,\n  titleProp: false,\n  descProp: false,\n  runtimeConfig: true,\n  namedExport: 'ReactComponent',\n  exportType: 'default',\n}\n\nconst explorer = cosmiconfig('svgr')\nconst explorerSync = cosmiconfigSync('svgr')\n\nexport const resolveConfig = async (\n  searchFrom?: string,\n  configFile?: string,\n): Promise<Config | null> => {\n  if (configFile == null) {\n    const result = await explorer.search(searchFrom)\n    return result ? result.config : null\n  }\n  const result = await explorer.load(configFile)\n  return result ? result.config : null\n}\n\nresolveConfig.sync = (\n  searchFrom?: string,\n  configFile?: string,\n): Config | null => {\n  if (configFile == null) {\n    const result = explorerSync.search(searchFrom)\n    return result ? result.config : null\n  }\n  const result = explorerSync.load(configFile)\n  return result ? result.config : null\n}\n\nexport const resolveConfigFile = async (\n  filePath: string,\n): Promise<string | null> => {\n  const result = await explorer.search(filePath)\n  return result ? result.filepath : null\n}\n\nresolveConfigFile.sync = (filePath: string): string | null => {\n  const result = explorerSync.search(filePath)\n  return result ? result.filepath : null\n}\n\nexport const loadConfig = async (\n  { configFile, ...baseConfig }: Config,\n  state: Pick<State, 'filePath'> = {},\n): Promise<Config> => {\n  const rcConfig =\n    state.filePath && baseConfig.runtimeConfig !== false\n      ? await resolveConfig(state.filePath, configFile)\n      : {}\n  return { ...DEFAULT_CONFIG, ...baseConfig, ...rcConfig }\n}\n\nloadConfig.sync = (\n  { configFile, ...baseConfig }: Config,\n  state: Pick<State, 'filePath'> = {},\n): Config => {\n  const rcConfig =\n    state.filePath && baseConfig.runtimeConfig !== false\n      ? resolveConfig.sync(state.filePath, configFile)\n      : {}\n  return { ...DEFAULT_CONFIG, ...baseConfig, ...rcConfig }\n}\n","import { Config } from './config'\nimport type { State } from './state'\n\nexport interface Plugin {\n  (code: string, config: Config, state: State): string\n}\n\nexport type ConfigPlugin = string | Plugin\n\nconst DEFAULT_PLUGINS: Plugin[] = []\n\nexport const getPlugins = (\n  config: Config,\n  state: Partial<State>,\n): ConfigPlugin[] => {\n  if (config.plugins) {\n    return config.plugins\n  }\n\n  if (state.caller?.defaultPlugins) {\n    return state.caller.defaultPlugins\n  }\n\n  return DEFAULT_PLUGINS\n}\n\nexport const resolvePlugin = (plugin: ConfigPlugin): Plugin => {\n  if (typeof plugin === 'function') {\n    return plugin\n  }\n\n  if (typeof plugin === 'string') {\n    return loadPlugin(plugin)\n  }\n\n  throw new Error(`Invalid plugin \"${plugin}\"`)\n}\n\nconst pluginCache: Record<string, Plugin> = {}\n\nconst resolveModule = (m: any) => (m ? m.default || m : null)\n\nexport const loadPlugin = (moduleName: string): Plugin => {\n  if (pluginCache[moduleName]) {\n    return pluginCache[moduleName]\n  }\n\n  try {\n    // eslint-disable-next-line\n    const plugin = resolveModule(require(moduleName))\n    if (!plugin) {\n      throw new Error(`Invalid plugin \"${moduleName}\"`)\n    }\n    pluginCache[moduleName] = plugin\n    return pluginCache[moduleName]\n  } catch (error) {\n    console.log(error)\n    throw new Error(\n      `Module \"${moduleName}\" missing. Maybe \\`npm install ${moduleName}\\` could help!`,\n    )\n  }\n}\n","import { expandState } from './state'\nimport { loadConfig } from './config'\nimport { resolvePlugin, getPlugins } from './plugins'\nimport type { Config } from './config'\nimport type { State } from './state'\n\nconst run = (code: string, config: Config, state: Partial<State>): string => {\n  const expandedState = expandState(state)\n  const plugins = getPlugins(config, state).map(resolvePlugin)\n  let nextCode = String(code).replace('\\0', '')\n  // eslint-disable-next-line no-restricted-syntax\n  for (const plugin of plugins) {\n    nextCode = plugin(nextCode, config, expandedState)\n  }\n  return nextCode\n}\n\nexport const transform = async (\n  code: string,\n  config: Config = {},\n  state: Partial<State> = {},\n): Promise<string> => {\n  config = await loadConfig(config, state)\n  return run(code, config, state)\n}\n\ntransform.sync = (\n  code: string,\n  config: Config = {},\n  state: Partial<State> = {},\n): string => {\n  config = loadConfig.sync(config, state)\n  return run(code, config, state)\n}\n"],"names":["parsePath","__spreadValues","cosmiconfig","cosmiconfigSync","result"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,gBAAmB,GAAA,kBAAA,CAAA;AAEzB,MAAM,gBAAA,GAAmB,CAAC,QAA8B,KAAA;AACtD,EAAA,IAAI,CAAC,QAAA;AAAU,IAAO,OAAA,cAAA,CAAA;AACtB,EAAA,MAAM,kBAAqB,GAAA,SAAA;AAAA,IACzBA,WAAU,QAAQ,CAAA,CAAE,IAAK,CAAA,OAAA,CAAQ,kBAAkB,EAAE,CAAA;AAAA,IACrD;AAAA,MACE,UAAY,EAAA,IAAA;AAAA,KACd;AAAA,GACF,CAAA;AACA,EAAA,OAAO,CAAM,GAAA,EAAA,kBAAA,CAAA,CAAA,CAAA;AACf,CAAA,CAAA;AAEa,MAAA,WAAA,GAAc,CAAC,KAAiC,KAAA;AAC3D,EAAO,OAAAC,gBAAA,CAAA;AAAA,IACL,aAAe,EAAA,KAAA,CAAM,aAAiB,IAAA,gBAAA,CAAiB,MAAM,QAAQ,CAAA;AAAA,GAClE,EAAA,KAAA,CAAA,CAAA;AAEP,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACkBO,MAAM,cAAyB,GAAA;AAAA,EACpC,UAAY,EAAA,IAAA;AAAA,EACZ,WAAa,EAAA,KAAA;AAAA,EACb,IAAM,EAAA,KAAA;AAAA,EACN,MAAQ,EAAA,KAAA;AAAA,EACR,UAAY,EAAA,KAAA;AAAA,EACZ,QAAU,EAAA,IAAA;AAAA,EACV,cAAgB,EAAA,KAAA,CAAA;AAAA,EAChB,IAAM,EAAA,KAAA;AAAA,EACN,GAAK,E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