{"version":3,"file":"utils/file.mjs","sources":["../../src/utils/file.tsx"],"sourcesContent":["import { get } from 'es-toolkit/compat';\nimport { Common, SDK } from '@rsdoctor/types';\nimport { message, Space, TreeNodeProps, UploadFile } from 'antd';\nimport { FieldDataNode } from 'rc-tree';\nimport {\n  FolderOpenTwoTone,\n  FolderTwoTone,\n  FileOutlined,\n  RightOutlined,\n} from '@ant-design/icons';\nimport { getFileCom } from 'src/components/FileTree';\n\nexport type DataNode = FieldDataNode<{\n  key: string | number;\n  title?: React.ReactNode | ((data: DataNode) => React.ReactNode);\n}> & { __BASENAME__?: any; __RESOURCEPATH__?: any; children?: DataNode[] };\n\nexport const rootDirname = (file: string, sep = '/'): string | null => {\n  const idx = file?.indexOf(sep);\n  if (idx === -1) {\n    return null;\n  }\n  if (idx === 0) {\n    return sep + (rootDirname(file?.slice(1), sep) || '');\n  }\n  return file?.slice(0, idx);\n};\n\nexport function mapFileKey(\n  arr: DataNode[],\n  depth = 2,\n  filter: (node: DataNode) => boolean = () => true,\n): DataNode['key'][] {\n  let d = 0;\n  const res: DataNode['key'][] = [];\n  let parent: DataNode[] = arr;\n  while (d < depth) {\n    parent.filter(filter).forEach((e) => {\n      if (!e.isLeaf) {\n        res.push(e.key);\n      }\n    });\n    parent = parent.reduce<DataNode[]>(\n      (t, e) => t.concat(e.children || []),\n      [],\n    );\n    if (!parent.length) break;\n    d++;\n  }\n  return res;\n}\n\nconst basenameKey = '__BASENAME__';\n\nexport function flattenDirectory(\n  n: DataNode,\n  parent: DataNode,\n  sep = '/',\n  inlinedResourcePathKey: keyof DataNode,\n  dirTitle = (\n    _dir: DataNode,\n    defaultTitle: string,\n  ): React.JSX.Element | string => defaultTitle,\n) {\n  if (n.isLeaf) return;\n  if (parent.children && parent.children.length === 1) {\n    const defaultTitle = [parent[basenameKey], n[basenameKey]].join(sep);\n    parent[inlinedResourcePathKey] = n[inlinedResourcePathKey];\n    parent[basenameKey] = defaultTitle;\n    parent.key = [parent.key, n.key].join('-');\n    parent.children = n.children;\n    parent.title = dirTitle(parent, defaultTitle);\n\n    if (n.children) {\n      n.children.forEach((c) => {\n        flattenDirectory(c, parent, sep, inlinedResourcePathKey, dirTitle);\n      });\n    }\n  } else {\n    // parent has more than 1 child.\n    n.title = dirTitle(n, n[basenameKey]);\n\n    if (n.children) {\n      n.children.forEach((c) => {\n        flattenDirectory(c, n, sep, inlinedResourcePathKey, dirTitle);\n      });\n    }\n  }\n}\n\nexport function createFileStructures({\n  files,\n  inlinedResourcePathKey = '__RESOURCEPATH__',\n  fileTitle = (_file: string, basename: string) => basename,\n  dirTitle = (_dir: DataNode, defaultTitle: string) => defaultTitle,\n  page = 'other',\n}: {\n  files: string[];\n  cwd?: string;\n  inlinedResourcePathKey?: keyof DataNode;\n  dirTitle?(dir: DataNode, defaultTitle: string): React.JSX.Element | string;\n  fileTitle?(file: string, basename: string): React.JSX.Element | string;\n  page?: 'bundle' | 'other';\n}): DataNode[] {\n  // Normalize all paths to use forward slash as internal separator for consistency\n  // This ensures Windows paths (using backslash) are properly converted to forward slashes\n  const normalizedFiles = files.map((file) => {\n    // Always convert backslashes to forward slashes for internal processing\n    return file.replace(/\\\\/g, '/');\n  });\n\n  // Use forward slash as the internal separator for consistency\n  const internalSep = '/';\n  const sepRegexp = new RegExp(internalSep);\n\n  const res = normalizedFiles.reduce<DataNode>(\n    (t, file) => {\n      let dir = rootDirname(file, internalSep);\n      let basename = dir ? file?.slice(dir.length + 1) : file;\n      let parent: DataNode = t;\n\n      while (dir) {\n        // find the match directory.\n        let exist = parent.children!.find((e) => e.title === dir) as DataNode;\n        if (!exist) {\n          const p = [parent[inlinedResourcePathKey], dir]\n            .filter(Boolean)\n            .join(internalSep);\n          exist = {\n            title: dir,\n            icon:\n              page === 'bundle'\n                ? (props) => getFileIcon(props as TreeNodeProps, false)\n                : null,\n            // key: [parent.key, parent.children!.length].join('-'),\n            key: p,\n            children: [],\n            [inlinedResourcePathKey]: p,\n            [basenameKey]: dir,\n          };\n          parent.children!.push(exist);\n        }\n\n        parent = exist;\n        dir = rootDirname(basename, internalSep);\n        basename = dir\n          ? basename.slice(dir.length).replace(sepRegexp, '')\n          : basename;\n      }\n\n      // uniq\n      if (parent.children!.some((e) => get(e, inlinedResourcePathKey) === file))\n        return t;\n\n      parent.children!.push({\n        title() {\n          return fileTitle(file, basename);\n        },\n        icon:\n          page === 'bundle'\n            ? (props) => getFileIcon(props as TreeNodeProps)\n            : null,\n        key: file,\n        isLeaf: true,\n        [inlinedResourcePathKey]: file,\n        [basenameKey]: basename,\n      });\n\n      return t;\n    },\n    { key: '0', children: [] },\n  ).children!;\n\n  res.forEach((e) => {\n    if (e.children) {\n      e.children.forEach((item) =>\n        flattenDirectory(\n          item,\n          e,\n          internalSep,\n          inlinedResourcePathKey,\n          dirTitle,\n        ),\n      );\n    }\n  });\n\n  return res;\n}\n\nexport function beautifyPath(path: string, cwd: string) {\n  if (path.startsWith(cwd)) {\n    return path.replace(cwd, '.');\n  }\n\n  return path;\n}\n\nexport function readJSONByFileReader<T extends Common.PlainObject>(\n  file: UploadFile,\n): Promise<T>;\nexport function readJSONByFileReader<T extends Common.PlainObject>(\n  file: Blob,\n): Promise<T>;\nexport function readJSONByFileReader<T extends Common.PlainObject>(\n  file: unknown,\n): Promise<T> {\n  return new Promise((resolve, reject) => {\n    const reader = new FileReader();\n    reader.onloadend = () => {\n      const { result } = reader;\n      try {\n        const json = JSON.parse(result!.toString());\n        resolve(json);\n      } catch (err) {\n        message.error('json parse error');\n        reject(err);\n      }\n    };\n    reader.onerror = () => {\n      const msg = 'upload json file error, please try again.';\n      message.error(msg);\n      reject(new Error(msg));\n    };\n    reader.readAsText(((file as UploadFile).originFileObj || file) as Blob);\n  });\n}\n\n/**\n * beautify module path, will replace cwd & last 'node_modules'\n */\nexport function beautifyModulePath(modulePath: string, cwd: string) {\n  const res = beautifyPath(modulePath, cwd);\n\n  const str = '/node_modules/';\n\n  const idx = res.lastIndexOf(str);\n\n  if (idx > -1) {\n    return {\n      alias: res.slice(idx + str.length),\n      inNodeModules: true,\n    };\n  }\n\n  return {\n    alias: res,\n    inNodeModules: false,\n  };\n}\n\nexport function getFileIcon(props: TreeNodeProps, addRowIcon = true) {\n  const { data } = props;\n  const expanded = props.expanded;\n  if (data?.children) {\n    return (\n      <Space>\n        {addRowIcon ? (\n          <RightOutlined\n            className={`file-tree-switcher-arrow ${expanded ? 'file-tree-switcher-arrow-expand' : ''}`}\n          />\n        ) : (\n          <></>\n        )}\n        {expanded ? <FolderOpenTwoTone /> : <FolderTwoTone />}\n      </Space>\n    );\n  }\n  if (props.eventKey && typeof props.eventKey === 'string') {\n    return getFileCom(props.eventKey);\n  }\n  return <FileOutlined />;\n}\n\ntype TreeNode = {\n  name: string;\n  value?: number;\n  children?: TreeNode[];\n  path?: string;\n  sourceSize?: number;\n  bundledSize?: number;\n  gzipSize?: number;\n  id?: string | number;\n  // Internal helper, not exported\n  _map?: Map<string, TreeNode>;\n};\n\nexport function buildTreemapData(\n  modules: SDK.ModuleData[],\n  rootName = 'dist',\n): TreeNode {\n  const root: TreeNode = { name: rootName, children: [], _map: new Map() };\n\n  for (const mod of modules) {\n    const parts = mod.path.split(/[\\\\/]/).filter(Boolean);\n    let current = root;\n\n    for (let i = 0; i < parts.length; i++) {\n      const part = parts[i];\n      if (i === parts.length - 1) {\n        // File node\n        if (!current.children) current.children = [];\n        current.children.push({\n          name: part,\n          path: mod.path,\n          sourceSize: mod.size?.sourceSize ?? 0,\n          bundledSize: mod.size?.parsedSize ?? 0,\n          gzipSize: mod.size?.gzipSize ?? 0,\n          id: mod.id,\n        });\n      } else {\n        // Directory node\n        if (!current._map) current._map = new Map();\n        let child = current._map.get(part);\n        if (!child) {\n          child = { name: part, children: [], _map: new Map() };\n          current.children!.push(child);\n          current._map.set(part, child);\n        }\n        current = child;\n      }\n    }\n  }\n\n  // Clean up _map property\n  function clean(node: TreeNode) {\n    delete node._map;\n    if (node.children) node.children.forEach(clean);\n  }\n  clean(root);\n\n  return root;\n}\n\nfunction flattenSingleChildDirs(node: TreeNode): TreeNode {\n  // Return directly if leaf node\n  if (!node.children || node.children.length === 0) return node;\n\n  let current = node;\n  // As long as children has only one child and it's not a leaf, merge\n  while (\n    current.children &&\n    current.children.length === 1 &&\n    !current.children[0].sourceSize // Not a leaf\n  ) {\n    current = {\n      name: current.name + '/' + current.children[0].name,\n      children: current.children[0].children,\n    };\n  }\n\n  // Recursively process all child nodes\n  if (current.children) {\n    current.children = current.children.map(flattenSingleChildDirs);\n  }\n  return current;\n}\n\nfunction sumDirValue(node: TreeNode): {\n  sourceSize: number;\n  bundledSize: number;\n  gzipSize: number;\n} {\n  if (!node.children || node.children.length === 0) {\n    // Leaf node, just return value\n    return {\n      sourceSize: node.sourceSize ?? 0,\n      bundledSize: node.bundledSize ?? 0,\n      gzipSize: node.gzipSize ?? 0,\n    };\n  }\n  // Recursively sum all child nodes\n  let sourceSum = 0;\n  let bundledSum = 0;\n  let gzipSum = 0;\n  for (const child of node.children) {\n    const { sourceSize, bundledSize, gzipSize } = sumDirValue(child);\n    sourceSum += sourceSize;\n    bundledSum += bundledSize;\n    gzipSum += gzipSize;\n  }\n  node.sourceSize = sourceSum;\n  node.bundledSize = bundledSum;\n  node.gzipSize = gzipSum;\n  return { sourceSize: sourceSum, bundledSize: bundledSum, gzipSize: gzipSum };\n}\n\nexport function flattenTreemapData(\n  modules: SDK.ModuleData[],\n  rootName = 'dist',\n): TreeNode {\n  const rawTree = buildTreemapData(modules, rootName);\n  const flattenedTree = flattenSingleChildDirs(rawTree);\n  sumDirValue(flattenedTree); // Recursive sum\n  return flattenedTree;\n}\n"],"names":["rootDirname","file","sep","idx","mapFileKey","arr","depth","filter","d","res","parent","e","t","basenameKey","flattenDirectory","n","inlinedResourcePathKey","dirTitle","_dir","defaultTitle","c","createFileStructures","files","fileTitle","_file","basename","page","normalizedFiles","internalSep","sepRegexp","RegExp","dir","exist","p","Boolean","props","getFileIcon","get","item","beautifyPath","path","cwd","readJSONByFileReader","Promise","resolve","reject","reader","FileReader","result","json","JSON","err","message","msg","Error","beautifyModulePath","modulePath","str","addRowIcon","data","expanded","Space","RightOutlined","FolderOpenTwoTone","FolderTwoTone","getFileCom","FileOutlined","buildTreemapData","modules","rootName","root","Map","mod","parts","current","i","part","child","clean","node","flattenSingleChildDirs","sumDirValue","sourceSum","bundledSum","gzipSum","sourceSize","bundledSize","gzipSize","flattenTreemapData","rawTree","flattenedTree"],"mappings":";;;;;AAiBO,MAAMA,cAAc,CAACC,MAAcC,MAAM,GAAG;IACjD,MAAMC,MAAMF,MAAM,QAAQC;IAC1B,IAAIC,AAAQ,OAARA,KACF,OAAO;IAET,IAAIA,AAAQ,MAARA,KACF,OAAOD,MAAOF,CAAAA,YAAYC,MAAM,MAAM,IAAIC,QAAQ,EAAC;IAErD,OAAOD,MAAM,MAAM,GAAGE;AACxB;AAEO,SAASC,WACdC,GAAe,EACfC,QAAQ,CAAC,EACTC,SAAsC,IAAM,IAAI;IAEhD,IAAIC,IAAI;IACR,MAAMC,MAAyB,EAAE;IACjC,IAAIC,SAAqBL;IACzB,MAAOG,IAAIF,MAAO;QAChBI,OAAO,MAAM,CAACH,QAAQ,OAAO,CAAC,CAACI;YAC7B,IAAI,CAACA,EAAE,MAAM,EACXF,IAAI,IAAI,CAACE,EAAE,GAAG;QAElB;QACAD,SAASA,OAAO,MAAM,CACpB,CAACE,GAAGD,IAAMC,EAAE,MAAM,CAACD,EAAE,QAAQ,IAAI,EAAE,GACnC,EAAE;QAEJ,IAAI,CAACD,OAAO,MAAM,EAAE;QACpBF;IACF;IACA,OAAOC;AACT;AAEA,MAAMI,cAAc;AAEb,SAASC,iBACdC,CAAW,EACXL,MAAgB,EAChBR,MAAM,GAAG,EACTc,sBAAsC,EACtCC,WAAW,CACTC,MACAC,eAC+BA,YAAY;IAE7C,IAAIJ,EAAE,MAAM,EAAE;IACd,IAAIL,OAAO,QAAQ,IAAIA,AAA2B,MAA3BA,OAAO,QAAQ,CAAC,MAAM,EAA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