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,IACL,SAAS,EAAe,IAAI,IAEN,WAAjB,EAAO,MAChB,GAAG,SAAS,qBAAsB,QAAQ,CAAC,EAAK,KAC9C,GAAI,EACF,QAAQ,IAAI,gBACP,CACL,MAAM,EAAM,EAAQ,OACR,KAAR,EACF,QAAQ,IAAI,WAEZ,QAAQ,IAAI,GACZ,SACG,OAAO,IACH,cACH,KAAM,gBACN,QAAS,OAAO,EAAI,OAAO,EAAG,IAAM,eAErC,MAAM,IACL,IAAoC,IAAhC,EAAc,cAAwB,CACtB,EAAI,MAAM,KAClB,SAAS,IACjB,WAAW,EAAE,IAEf,eACA,aAAa,qBACf,KAGR,KAEwB,mBAAjB,EAAO,MAChB,WAmBE,MAAM,EAAe,SAAS,0BAC3B,QAAQ,IAAO,EAAE,SAAS,WAC1B,KAAK,IACJ,MAAM,EAAO,KAAK,SAAS,EAAG,KAAK,QAAQ,IACrC,EAAY,CAChB,KAAM,EACN,GAAI,KAAK,KAAK,cAAe,GAAG,WAElC,OAAO,MAAM,EAAU,MACpB,KAAK,CAAE,QAAS,GAAI,aAAc,KAClC,OAAO,EAAU,GAAG,IAE3B,QAAQ,IAAI,GAAc,MAAM,IAC9B,QAAQ,IAAI,OAAO,GAEtB,EAlCD,GAmC0B,SAAjB,EAAO,MAChB,QAAQ,OACkB,WAAjB,EAAO,MAChB,QAAQ,IACN,aAAa,KAAI,CAAC,EAAG,IACnB,iBACE,mBAAmB,aAAa,GAAO,YACvC,YAAY,OAGhB,MAAM,IACN,QAAQ,IAAI,OAAO,IAEK,SAAjB,EAAO,OAChB,GAAG,GACD,iBACA,qBACA,CAAE,WAAW,IACZ,IACC,QAAQ,IAAI,OAAO,GAGzB","file":"/npm/caici-data@1.7.6/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/caici-data@1.7.6/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","\"use strict\";\nconst fs = require(\"fs-extra\");\nconst { networkInterfaces } = require(\"os\");\nconst inquirer = require(\"inquirer\");\nconst { globSync } = require(\"glob\");\nconst LZString = require(\"lz-string\");\nconst lodashSet = require(\"lodash.set\");\nconst raw = require(\"./data.json\");\nconst infoListData = require(\"./info-list.json\");\nconst typeListData = infoListData.typeList;\nconst wordListData = require(\"./word-list.json\");\nconst path = require(\"path\");\nconst sharp = require(\"sharp\");\nconst imagemin = require(\"imagemin\");\nconst imageminJpegtran = require(\"imagemin-jpegtran\");\nconst { default: imageminPngquant } = require(\"imagemin-pngquant\");\nconst data = raw.data;\nconst buildEnv = process.env.ENV;\nconst localIP = networkInterfaces()[\"en0\"][0][\"address\"];\nconst localServer = `http://${localIP}:3000`;\nconst githubServer = `https://fastly.jsdelivr.net/gh/iammvp/caici-data@latest`;\nconst version = \"v2\";\nfor (let i = 0; i < typeListData.length; i++) {\n  const info = typeListData[i];\n  // console.log(\n  //   `${info.title}: ${wordListData[i].length} 个词汇, id: ${info.id}`,\n  // );\n}\n\nconst firstPrompt = {\n  type: \"list\",\n  name: \"first\",\n  message: \"想做什么?\",\n  choices: [\n    {\n      name: \"增加词汇\",\n      value: \"add\",\n    },\n    {\n      name: \"删除词汇\",\n      value: \"delete\",\n    },\n    {\n      name: \"压缩json文件\",\n      value: \"compress\",\n    },\n    {\n      name: \"压缩图片文件\",\n      value: \"compress-image\",\n    },\n    {\n      name: \"导出词汇\",\n      value: \"export\",\n    },\n    {\n      name: \"复制信息到项目\",\n      value: \"copy\",\n    },\n    {\n      name: \"退出\",\n      value: \"exit\",\n    },\n  ],\n};\n\nconst typeSelectPrompt = {\n  type: \"list\",\n  choices: () => {\n    let temp = [];\n    for (let i = 1; i < wordListData.length; i++) {\n      temp.push({\n        value: i,\n        name: data[i].title,\n      });\n    }\n    return temp;\n  },\n};\nconst confirmPrompt = {\n  type: \"confirm\",\n  default: false,\n};\n\ninquirer.prompt(firstPrompt).then((answer) => {\n  if (answer.first === \"compress\") {\n    // 压缩文件\n    generateFile();\n  } else if (answer.first === \"add\") {\n    inquirer\n      .prompt({ ...typeSelectPrompt, name: \"add\", message: \"增加哪个类型?\" })\n      .then((addPromptAnser) => {\n        addWords(addPromptAnser.add);\n      });\n  } else if (answer.first === \"delete\") {\n    fs.readFile(\"./files/delete.txt\", \"utf8\", (err, content) => {\n      if (err) {\n        console.log(\"读取删除词汇失败\");\n      } else {\n        const str = content.trim();\n        if (str === \"\") {\n          console.log(\"删除词汇为空\");\n        } else {\n          console.log(str);\n          inquirer\n            .prompt({\n              ...confirmPrompt,\n              name: \"deleteConfirm\",\n              message: `确定删除${str.substr(0, 20) + \"...\"} 等词语?`,\n            })\n            .then((confirmAnswer) => {\n              if (confirmAnswer.deleteConfirm === true) {\n                const tempArray = str.split(\" \");\n                tempArray.forEach((v) => {\n                  deleteWord(v);\n                });\n                generateFile();\n                wipeUsedFile(\"./files/delete.txt\");\n              }\n            });\n        }\n      }\n    });\n  } else if (answer.first === \"compress-image\") {\n    (async () => {\n      // const name = \"guide-slide1\";\n      // const frames = 30;\n      // const width = 18000;\n      // const height = 444;\n      // const per = width / frames;\n      // const promiseArray = globSync(`images/min/${name}.{jpg,png}`).map((v) => {\n      //   for (let i = 0; i < frames; i++) {\n      //     sharp(v)\n      //       .extract({ left: per * i, top: 0, width: per, height: height })\n      //       .webp({ quality: 100 })\n      //       .toFile(\n      //         path.join(\"images/webp\", `${name}_${i + 1}.webp`),\n      //         function (err) {\n      //           console.log(err);\n      //         },\n      //       );\n      //   }\n      // });\n      const promiseArray = globSync(\"images/min/*.{jpg,png}\")\n        .filter((v) => !v.includes(\"guide\"))\n        .map((v) => {\n          const name = path.basename(v, path.extname(v));\n          const filesInfo = {\n            from: v,\n            to: path.join(\"images/webp\", `${name}.webp`),\n          };\n          return sharp(filesInfo.from)\n            .webp({ quality: 10, alphaQuality: 10 })\n            .toFile(filesInfo.to);\n        });\n      Promise.all(promiseArray).then((_) => {\n        console.log(\"压缩完成\");\n      });\n    })();\n  } else if (answer.first === \"exit\") {\n    process.exit();\n  } else if (answer.first === \"export\") {\n    Promise.all(\n      wordListData.map((d, index) =>\n        writeFilePromise(\n          `./files/current/${typeListData[index].title}.txt`,\n          getRawWords(d)\n        )\n      )\n    ).then((res) => {\n      console.log(\"写入完成\");\n    });\n  } else if (answer.first === \"copy\") {\n    fs.cp(\n      \"./compressData\",\n      \"../caici/src/data/\",\n      { recursive: true },\n      (err) => {\n        console.log(\"done\");\n      }\n    );\n  }\n});\n\nfunction generateFile() {\n  fs.writeFileSync(\"./word-list.json\", JSON.stringify(wordListData, null, 2));\n\n  // const devRaw = JSON.stringify(raw).replace(\n  //   // /npm\\/caici-data[^\\/]*/g,\n  //   // `gh/iammvp/caici-data@${gitReleaseVersion}`\n  //   /https:\\/\\/fastly.jsdelivr.net\\/npm\\/caici-data[^\\/]*/g,\n  //   `${buildEnv === \"dev\" ? localServer : githubServer}`,\n  // );\n  transLocalImageToBase64().then(() => {\n    fs.writeFile(\n      \"./compressData/infoList.txt\",\n      LZString.compressToBase64(JSON.stringify(infoListData)),\n      (err) => {\n        if (err) {\n          console.log(\"写入压缩文件失败\");\n        }\n      }\n    );\n    fs.writeFile(\n      \"./compressData/wordList.txt\",\n      LZString.compressToBase64(JSON.stringify(wordListData)),\n      (err) => {\n        if (err) {\n          console.log(\"写入压缩文件失败\");\n        }\n      }\n    );\n  });\n}\n\nfunction transLocalImageToBase64() {\n  const localImageInfo = getAllLocalImage();\n  const arrayPromise = localImageInfo.map((v) => {\n    return new Promise((resolve, reject) => {\n      fs.readFile(v.filePath, (error, data) => {\n        const ext = path.extname(v.filePath);\n        const imageBase64 =\n          `data:image/${ext};base64,` + data.toString(\"base64\");\n        lodashSet(infoListData, v.keyPath, imageBase64);\n        resolve();\n      });\n    });\n  });\n  return new Promise((resolve) => {\n    Promise.all(arrayPromise).then(() => {\n      return resolve();\n    });\n  });\n}\n\nfunction getAllLocalImage() {\n  let result = [];\n  function travel(prefix, data) {\n    for (let key in data) {\n      if (typeof data[key] === \"object\" && data[key] !== null) {\n        travel(prefix === \"\" ? key : `${prefix}['${key}']`, data[key]);\n      } else {\n        const value = data[key];\n        if (\n          typeof value === \"string\" &&\n          value.includes(\"./images/\") &&\n          !value.includes(\"https://\")\n        ) {\n          result.push({\n            keyPath: prefix === \"\" ? key : `${prefix}['${key}']`,\n            filePath: value,\n          });\n        }\n      }\n    }\n  }\n  travel(\"\", infoListData);\n  return result;\n}\nfunction addWords(index) {\n  fs.readFile(\"./files/add.txt\", \"utf8\", (err, content) => {\n    if (err) {\n      console.log(\"读取add文件失败\");\n    } else {\n      const str = content.trim();\n      if (str === \"\") {\n        console.log(\"add文件为空\");\n      } else {\n        inquirer\n          .prompt({\n            ...confirmPrompt,\n            name: \"addConfirm\",\n            message: `确定向 ${typeListData[index].title} 增加 ${\n              str.substr(0, 20) + \"...\"\n            } 等词语?`,\n          })\n          .then((confirmAnswer) => {\n            if (confirmAnswer.addConfirm === true) {\n              let indicator = \" \";\n              if (str.includes(\",\")) {\n                indicator = \",\";\n              } else if (str.includes(\"。\")) {\n                indicator = \"。\";\n              }\n              const tempArray = str.split(indicator);\n              tempArray.forEach((v) => {\n                const trimV = v.trim();\n                if (trimV.length > 0) {\n                  addWordToType(index, trimV); // 增加到对应类型\n                }\n              });\n              generateFile();\n              wipeUsedFile(\"./files/add.txt\");\n            }\n          });\n      }\n    }\n  });\n}\n\nfunction deleteWord(word) {\n  wordListData.forEach((v) => {\n    const index = v.words.findIndex(\n      (w) => w.word.toLowerCase().trim() === word.toLowerCase().trim()\n    );\n    if (index !== -1) {\n      v.words.splice(index, 1);\n      console.log(`${v.title}中找到词汇 ${word}, 删除成功`);\n    }\n  });\n}\n\nfunction savePrevData() {\n  return new Promise((resolve, reject) => {\n    fs.writeFile(\n      \"./files/data.prev.json\",\n      JSON.stringify(raw, null, 2),\n      (err) => {\n        if (err) {\n          reject(err);\n        } else {\n          resolve();\n        }\n      }\n    );\n  });\n}\n\nfunction addWordToType(index, word) {\n  if (\n    wordListData[index].words.findIndex(\n      (w) => w.word.toLowerCase() === word.toLowerCase()\n    ) === -1\n  ) {\n    wordListData[index].words.push({\n      word,\n      l: strlen(word),\n    });\n  } else {\n    console.log(`${word}在${data[index].title}中重复,已经跳过`);\n  }\n}\n\nfunction wipeUsedFile(path) {\n  fs.writeFile(path, \"\", (err) => {\n    if (err) {\n      console.log(\"清理使用文件出错\");\n    }\n  });\n}\nfunction strlen(str) {\n  var len = 0;\n  for (let i = 0; i < str.length; i++) {\n    if (str.charCodeAt(i) > 255 || str.charCodeAt(i) < 0) {\n      len += 2;\n    } else {\n      len += 1;\n    }\n  }\n  return len;\n}\n\nfunction writeFilePromise(path, content) {\n  return new Promise((resolve, reject) => {\n    fs.writeFile(path, content, (err) => {\n      if (err) {\n        reject(err);\n      } else {\n        resolve();\n      }\n    });\n  });\n}\n\nfunction getRawWords(arr) {\n  return arr.reduce((str, wordObj) => str + \" \" + wordObj.word, \"\");\n}\n"]}