import e from"postcss-value-parser";import t from"node:fs";import n from"node:path";import a from"node:url";var isEnvFunc=e=>e&&"function"===e.type&&"env"===e.value,getReplacedValue=(t,n)=>{const a=e(t);return a.walk(e=>{if(isEnvFunc(e)){const[t]=e.nodes;"word"===t.type&&void 0!==n[t.value]&&(e.nodes=[],e.type="word",e.value=n[t.value])}}),a.toString()};function importEnvironmentVariablesFromObject(e){return Object.assign({},Object(e).environmentVariables||Object(e)["environment-variables"])}async function importEnvironmentVariablesFromJSONFile(e){return importEnvironmentVariablesFromObject(await readJSON(n.resolve(e)))}async function importEnvironmentVariablesFromJSFile(e){const t=await import(a.pathToFileURL(n.resolve(e)));return importEnvironmentVariablesFromObject("default"in t?t.default:t)}const readFile=e=>new Promise((n,a)=>{t.readFile(e,"utf8",(e,t)=>{e?a(e):n(t)})}),readJSON=async e=>JSON.parse(await readFile(e)),creator=e=>{const t=[].concat(Object(e).importFrom||[]),a=t.map(e=>{if(e instanceof Promise)return e;if(e instanceof Function)return e();const t=e===Object(e)?e:{from:String(e)};if(t.environmentVariables||t["environment-variables"])return t;const a=String(t.from||"");return{type:(t.type||n.extname(a).slice(1)).toLowerCase(),from:a}}).reduce(async(e,t)=>{const{type:n,from:a}=await t;return"js"===n||"cjs"===n?Object.assign(e,await importEnvironmentVariablesFromJSFile(a)):"json"===n?Object.assign(e,await importEnvironmentVariablesFromJSONFile(a)):Object.assign(e,importEnvironmentVariablesFromObject(await t))},{});const o="disableDeprecationNotice"in Object(e)&&Boolean(e.disableDeprecationNotice);let r=!1;return{postcssPlugin:"postcss-env-fn",async AtRule(e,{result:t}){let n;try{n=getReplacedValue(e.params,await a)}catch{e.warn(t,`Failed to parse params '${e.params}' as an environment value. Leaving the original value intact.`)}void 0!==n&&n!==e.params&&(e.params=n,o||r||(r=!0,e.warn(t,"postcss-env-function is deprecated and will be removed.\nCheck the discussion on github for more details. https://github.com/csstools/postcss-plugins/discussions/192")))},async Declaration(e,{result:t}){let n;try{n=getReplacedValue(e.value,await a)}catch{e.warn(t,`Failed to parse value '${e.value}' as an environment value. Leaving the original value intact.`)}void 0!==n&&n!==e.value&&(e.value=n,o||r||(r=!0,e.warn(t,"postcss-env-function is deprecated and will be removed.\nWe are looking for insights and anecdotes on how these features are used so that we can design the best alternative.\nPlease let us know if our proposal will work for you.\nVisit the discussion on github for more details. https://github.com/csstools/postcss-plugins/discussions/192")))}}};creator.postcss=!0;export{creator as default,creator as"module.exports"};
