{"version":3,"sources":["jsdelivr-header.js","/npm/simple-chords@2.5.1/src/Index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,UCNY,OAAQ,wBACR,SAAU,cAEpB,sBACA,qBACK,yCAEL,uBACA,yBACK,sCASL,uBACA,yBACK,qCACE,KAAK,qBAGd,SAAS,2BAA2B,GAClC,MAAM,EAAa,EAAU,MAAM,KACnC,OAAO,EACJ,KAAI,CAAC,EAAG,IAAO,IAAM,EAAW,OAAS,EAAI,MAAQ,IACrD,KAAK,IACV,CAsBA,eAAe,aAAa,GAC1B,MAAM,EAAW,MAAM,QAAQ,GAAO,EAAM,CAAC,GAEvC,EAAS,GACf,IAAK,MAAM,KAAQ,EACjB,GAAI,EAAK,SAAS,cAChB,EAAO,KAAK,OACP,CACL,MAAM,SAAoB,GAAG,QAAQ,IAClC,QAAQ,GAAM,EAAE,SAAS,gBACzB,KAAK,GAAM,KAAK,KAAK,EAAM,KAC9B,EAAO,QAAQ,EACjB,CAEF,OAAO,CACT,QAKO,eAAe,uBAAuB,GAC3C,MAAM,EAAY,EAAK,UACvB,IAAK,EAAW,OAAO,cAAc,GACrC,MAAM,QAAgB,GAAG,SAAS,EAAW,SACvC,EAAQ,qBAAqB,GACnC,OAAO,cAAc,IAAK,EAAM,SAClC,QAKO,eAAe,eAAc,UAClC,EAAS,QACT,EAAO,MACP,EACA,MAAO,IAEP,MAAM,QAAmB,aAAa,GAEtC,GAAI,QACI,sBACJ,EACA,EACA,GAAS,uBACT,QAIJ,IAAK,MAAM,KAAY,EACrB,UACQ,iBACJ,EACA,2BAA2B,GAC3B,GAAS,uBACT,EAEJ,CAAE,MAAO,GACP,QAAQ,MAAM,kBAAkB,eAAuB,EACzD,CAEJ","file":"/npm/simple-chords@2.5.1/src/Index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/simple-chords@2.5.1/src/Index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import * as fs from \"fs/promises\";\nimport * as Path from \"path\";\nimport {\n  renderAllInSingleFile,\n  renderSingleFile,\n} from \"./SongLayout/RenderSongAsPdf.js\";\nimport {\n  DefaultLayoutConfigDto,\n  parseLayoutConfigDto,\n} from \"./SongLayout/LayoutConfig.js\";\n/**\n * @typedef {import(\"./SongLayout/LayoutConfig.js\").LayoutConfigDto} LayoutConfigDto\n * @typedef {import(\"./SongLayout/LayoutConfig.js\").LayoutConfig} LayoutConfig\n * @typedef {import(\"./Drawing/TextConfig.js\").TextConfigArgs} TextConfigArgs\n * @typedef {import(\"./Drawing/TextConfig.js\").TextConfigDto} TextConfigDto\n */\n\nexport {\n  DefaultLayoutConfigDto,\n  parseLayoutConfigDto,\n} from \"./SongLayout/LayoutConfig.js\";\nexport * from \"./Shared/Length.js\";\n\n/** @param {string} inputPath */\nfunction getCorrespondingOutPutPath(inputPath) {\n  const pointSplit = inputPath.split(\".\");\n  return pointSplit\n    .map((e, i) => (i === pointSplit.length - 1 ? \"pdf\" : e))\n    .join(\".\");\n}\n\n/**\n * @typedef {object} MainArgs\n * @property {string | string[]} inputPath\n * @property {string | undefined} outPath\n * @property {boolean} debug\n * @property {LayoutConfigDto=} style\n */\n\n/**\n * @typedef {object} MainPathArgs\n * @property {string | string[]} inputPath\n * @property {string | undefined} outPath\n * @property {boolean} debug\n * @property {string=} stylePath\n */\n\n/**\n * @param {string | string[]} inp\n * @return {Promise<string[]>}\n */\nasync function resolvePaths(inp) {\n  const inputArr = Array.isArray(inp) ? inp : [inp];\n\n  const result = [];\n  for (const path of inputArr) {\n    if (path.endsWith(\".chords.md\")) {\n      result.push(path);\n    } else {\n      const filesInDir = (await fs.readdir(path))\n        .filter((f) => f.endsWith(\".chords.md\"))\n        .map((f) => Path.join(path, f));\n      result.push(...filesInDir);\n    }\n  }\n  return result;\n}\n\n/**\n * @param {MainPathArgs} args\n */\nexport async function printPdfFilesFromPaths(args) {\n  const stylePath = args.stylePath;\n  if (!stylePath) return printPdfFiles(args);\n  const content = await fs.readFile(stylePath, \"utf-8\");\n  const style = parseLayoutConfigDto(content);\n  return printPdfFiles({ ...args, style });\n}\n\n/**\n * @param {MainArgs} args\n */\nexport async function printPdfFiles({\n  inputPath,\n  outPath,\n  debug,\n  style: theme,\n}) {\n  const chordFiles = await resolvePaths(inputPath);\n\n  if (outPath) {\n    await renderAllInSingleFile(\n      chordFiles,\n      outPath,\n      theme || DefaultLayoutConfigDto,\n      debug\n    );\n    return;\n  }\n  for (const filePath of chordFiles) {\n    try {\n      await renderSingleFile(\n        filePath,\n        getCorrespondingOutPutPath(filePath),\n        theme || DefaultLayoutConfigDto,\n        debug\n      );\n    } catch (e) {\n      console.error(`Faild to print ${filePath} with error`, e);\n    }\n  }\n}\n"]}