/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@runforest/sass@2.4.0-alpha.0/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
const path=require("path"),fs=require("fs-extra"),postcss=require("postcss"),autoprefixer=require("autoprefixer"),sass=require("sass"),cssnano=require("cssnano"),Watcher=require("@runforest/node-sass-watcher"),chalk=require("chalk"),isGlob=require("is-glob"),globParent=require("glob-parent"),globby=require("globby"),Tasks=require("@runforest/run/utils/tasks"),Observable=require("@runforest/run/utils/observable");function formatError(e){return e.formatted?chalk`{red ${e.formatted}}`:e.message?chalk`{red ${e.message}}`:e.toString()}async function findNodeModulesInParents(e){const t=path.join(e,"..");if(e===t||0===path.relative(process.cwd(),t).indexOf(".."))return Promise.reject();const r=path.join(t,"node_modules");return await fs.pathExists(r)?r:findNodeModulesInParents(t)}async function findNPMPackageInParents(e,t){const r=await findNodeModulesInParents(e),s=path.join(r,t);return await fs.pathExists(s)?s:findNPMPackageInParents(path.join(r,".."),t)}const frontendFrameworkImporter=function(e,t,r){if(!r)return null;if("fjaka/normalize.css"===e){let e;try{e=require.resolve("normalize.css",{paths:[path.resolve(process.cwd(),"node_modules")]})}catch(e){e instanceof Error?r(e):r(new Error("Can't resolve normalize.css module."))}e&&fs.readFile(e,"utf-8",((e,t)=>r(e||{contents:t.toString()})))}else if(0===e.indexOf("fjaka/")){let t;try{t=require.resolve("fjaka",{paths:[path.resolve(process.cwd(),"node_modules")]})}catch(e){e instanceof Error?r(e):r(new Error("Can't resolve fjaka module."))}if(t){t=path.dirname(t);const s=path.resolve(t,"sass",path.relative("fjaka/",e));r({file:s})}}else if(0===e.indexOf("~")){const s=1===e.indexOf("@");let n,o="";if(s){const t=e.substring(1).split("/");[n]=t,t.length>1&&(n+=`/${t[1]}`),o="",t.length>2&&(o=t.slice(2).join("/"))}else{const t=e.substring(1).split("/");[n]=t,o="",t.length>1&&(o=t.slice(1).join("/"))}findNPMPackageInParents(t,n).then((e=>{o.match(/\.css$/)&&fs.existsSync(path.join(e,o))?fs.readFile(path.join(e,o),"utf-8",((e,t)=>r(e||{contents:t.toString()}))):r({file:path.join(e,o)})})).catch((()=>{r(null)}))}else r(null)};function compileSass(e,t){return new Promise(((r,s)=>{sass.render({file:e,outFile:t,sourceMap:!0,sourceMapContents:!0,outputStyle:"expanded",indentType:"tab",indentWidth:2,importer:frontendFrameworkImporter},((e,t)=>e?s(formatError(e)):r(t)))}))}function compilePostCSS(e,t,r,s,n){return new Promise(((o,i)=>{const a=postcss();a.use(autoprefixer),t&&a.use(cssnano({preset:"default"})),a.process(e,{from:r,to:s,map:{prev:n?n.toString():void 0}}).then((e=>{o(e)})).catch((e=>{i(e)}))}))}async function writeResultToFiles(e,t){return await Promise.all([fs.writeFile(e,t.css),t.map?fs.writeFile(`${e}.map`,t.map.toString()):Promise.resolve()]),t}async function validate({compress:e=!0,source:t,destination:r,additionalSourcesToWatch:s=[],mode:n="build"}){if(!t)throw new Error("Source is required!");if(!r)throw new Error("Destination is required!");return await fs.ensureDir(r),{compress:Boolean(e),source:t,destination:r,additionalSourcesToWatch:s,mode:"watch"===n?"watch":"build"}}async function ensureOutFile(e,t){await Promise.all([fs.ensureFile(e),t?fs.ensureFile(`${e}.map`):Promise.resolve()])}function compile(e,t,r){return Promise.resolve().then((()=>compileSass(t,r))).then((s=>compilePostCSS(s.css,e,t,r,s.map))).then((t=>ensureOutFile(r,e).then((()=>t)))).then((e=>writeResultToFiles(r,e)))}function getOutputFile(e,t,r){return path.join(r,path.relative(t,e).replace(/\.(sass|scss)$/i,".css"))}function watch(e,t,r,s){const{mode:n}=r;if("watch"!==n)return Promise.resolve(r);const{compress:o}=r;return new Promise((()=>{const n=new Watcher([e,...r.additionalSourcesToWatch],{verbosity:0,includePaths:[],rootDir:path.resolve(process.cwd(),path.dirname(e)),follow:!1});let i;const a=function(){return i&&clearTimeout(i),s.next(chalk`Compiling {blue ${e}} ...`),compile(o,e,t).then((()=>{s.next(chalk`{blue ${e}} is compiled to {green ${t}}.`),i=setTimeout((()=>{s.next("Waiting...")}),2e3)})).catch((t=>{s.next(chalk`{red Watcher is stopped. Error in compiling process }`+chalk`{red of {blue ${e}}.}\n`+formatError(t))}))};n.on("init",a),n.on("update",a),n.run()}))}async function build(e,t,r){const{mode:s}=r;if("build"!==s)return r;const{compress:n}=r;return await compile(n,e,t),r}function runTask(e,t,r){return new Observable((s=>{Promise.resolve(r).then((r=>watch(e,t,r,s))).then((r=>build(e,t,r))).then((()=>s.complete())).catch((e=>{"string"==typeof e?s.error(new Error(e)):s.error(e)}))}))}function runSubtasks(e,t,r){const s=new Tasks([],{concurrent:!0});for(let n=0;n<e.length;n+=1){const o=e[n],i=getOutputFile(o,t,r.destination);s.add({title:o,task:()=>runTask(o,i,r)})}return s}module.exports=async function(e){const t=await validate(e),{source:r,destination:s}=t;if(!isGlob(r))return runTask(r,getOutputFile(r,path.dirname(r),s),t);const n=globParent(r);return new Tasks([{title:"prepare",task:e=>globby([r,"!**/_*.{sass,scss}"]).then((t=>{e.paths=t}))},{title:"compile",task:e=>runSubtasks(e.paths,n,t)}])};
//# sourceMappingURL=/sm/cfcc92b6c1bf9dd09a8029c24b185ddd04a49f8e99f2f5b0b8b96642557c2522.map