"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileWXSS=compileWXSS;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),tools_1=require("../../../../../utils/tools"),locales_1=tslib_1.__importDefault(require("../../../../../utils/locales/locales")),config_1=require("../../../../../config/config"),taskstatus_1=require("../../../../../utils/taskstatus"),workerThread_1=require("../../workerThread"),common_1=require("../../../../../utils/common");async function compileWXSS(e,t,o){const{root:r="",setting:s={},onProgressUpdate:i=(()=>{}),devToolsCompileCache:a}=o,{minifyWXSS:l,postcss:c}=s,n=new taskstatus_1.TaskStatus(t),_=path_1.default.posix.join(r,t),u=await e.getFile(r,t);if(!l&&!c){i(n);const e=(0,tools_1.bufferToUtf8String)(u);return void 0===e&&(0,common_1.throwError)({msg:locales_1.default.config.FILE_NOT_UTF8.format(_),code:config_1.FILE_NOT_UTF8,filePath:_}),n.done(),i(n),{filePath:t,code:e}}async function f(){const o=await(0,workerThread_1.runTask)(workerThread_1.TASK_NAME.COMPILE_WXSS,{projectPath:e.projectPath,root:r,filePath:t,setting:s,code:u},e=>{e===workerThread_1.ETaskStatus.progress?i(n):e===workerThread_1.ETaskStatus.done&&(n.done(),i(n))});return o.error&&(0,common_1.throwError)({msg:o.error.message,code:o.error.code,filePath:_}),o.code}let d="";if(a){const o=(0,tools_1.normalizePath)(path_1.default.posix.join(e.projectPath,r,t)),i=`${o}_${JSON.stringify(s)}`;d=await a.getFile(o,i),d&&!s.uglifyFileName||(d=await f(),a.setFile(o,d,i))}else d=await f();return{filePath:t,code:d}}