{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import * as path from 'path'\nimport * as fs from 'fs'\n\nimport { wrapper, TypeOnEveryFile, TypeToolOptions, TypeToolProp } from '@asset-toolkit/core'\nconst { execSync } = require('child_process')\n\nexport interface TypeProps extends TypeToolOptions {\n  settings?: string\n  preset?: 'low' | 'medium' | 'high' | 'max'\n  mipmap?: boolean\n  linear?: boolean\n}\n\n/**\n * A tool to create a super compressed image, KTX2.\n * @param props - { pathIn, pathOut }\n * @param options - { }\n * @returns { Promise(returns) }\n */\nconst imageSuperCompression: (_props: TypeToolProp, options?: TypeProps) => Promise<unknown> = wrapper(\n  ({ pathIn, pathOut, file, options, next, log }: TypeOnEveryFile) => {\n    const opts = {\n      settings: '-uastc -uastc_level 2 -uastc_rdo_l 1.0',\n      preset: 'high',\n      mipmap: true,\n      linear: true,\n      ...options,\n    }\n\n    if (opts.preset === 'max') opts.settings = '-uastc -uastc_level 3 -uastc_rdo_l 1.0'\n    if (opts.preset === 'medium') opts.settings = '-comp_level 5 -max_endpoints 16128 -max_selectors 16128'\n\n    if (opts.mipmap) opts.settings += ' -mipmap'\n    if (opts.linear) opts.settings += ' -linear'\n\n    log(opts.settings)\n\n    execSync(\n      `\"${path.resolve(__dirname, '../bin/basisu')}\" ${opts.settings} -ktx2 ${path.resolve(pathIn || pathOut, file)}`,\n    )\n\n    const extFile = path.extname(file)\n    const newFile = file.replace(extFile, '.ktx2')\n\n    // move image file from root to destination folder\n    fs.renameSync(path.resolve(process.cwd(), newFile), path.resolve(pathOut, `${file}.ktx2`))\n\n    next()\n  },\n  undefined,\n  { exts: ['png', 'jpg'], name: 'Image Supercompression' },\n)\n\nexport default imageSuperCompression\n"],"names":["execSync","require","imageSuperCompression","wrapper","pathIn","pathOut","file","next","log","opts","settings","preset","mipmap","linear","options","path","resolve","__dirname","extFile","extname","newFile","replace","fs","renameSync","process","cwd","undefined","exts","name"],"mappings":"0SAIA,IAAQA,EAAaC,QAAQ,iBAArBD,SAeFE,EAAyFC,EAC7F,gBAAGC,IAAAA,OAAQC,IAAAA,QAASC,IAAAA,KAAeC,IAAAA,KAAMC,IAAAA,IACjCC,KACJC,SAAU,yCACVC,OAAQ,OACRC,QAAQ,EACRC,QAAQ,KALcC,SASJ,QAAhBL,EAAKE,SAAkBF,EAAKC,SAAW,0CACvB,WAAhBD,EAAKE,SAAqBF,EAAKC,SAAW,2DAE1CD,EAAKG,SAAQH,EAAKC,UAAY,YAC9BD,EAAKI,SAAQJ,EAAKC,UAAY,YAElCF,EAAIC,EAAKC,UAETV,MACMe,EAAKC,QAAQC,UAAW,sBAAqBR,EAAKC,mBAAkBK,EAAKC,QAAQZ,GAAUC,EAASC,IAG1G,IAAMY,EAAUH,EAAKI,QAAQb,GACvBc,EAAUd,EAAKe,QAAQH,EAAS,SAGtCI,EAAGC,WAAWR,EAAKC,QAAQQ,QAAQC,MAAOL,GAAUL,EAAKC,QAAQX,EAAYC,YAE7EC,UAEFmB,EACA,CAAEC,KAAM,CAAC,MAAO,OAAQC,KAAM"}