"use strict";var e=require("postcss-value-parser"),t=require("node:fs"),n=require("node:path"),r=require("node:url"),isEnvFunc=e=>e&&"function"===e.type&&"env"===e.value,getReplacedValue=(t,n)=>{const r=e(t);return r.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])}})),r.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(r.pathToFileURL(n.resolve(e)));return importEnvironmentVariablesFromObject("default"in t?t.default:t)}const readFile=e=>new Promise(((n,r)=>{t.readFile(e,"utf8",((e,t)=>{e?r(e):n(t)}))})),readJSON=async e=>JSON.parse(await readFile(e));function creator(e){const t=[].concat(Object(e).importFrom||[]),r=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 r=String(t.from||"");return{type:(t.type||n.extname(r).slice(1)).toLowerCase(),from:r}})).reduce((async(e,t)=>{const{type:n,from:r}=await t;return"js"===n||"cjs"===n?Object.assign(e,await importEnvironmentVariablesFromJSFile(r)):"json"===n?Object.assign(e,await importEnvironmentVariablesFromJSONFile(r)):Object.assign(e,importEnvironmentVariablesFromObject(await t))}),{});const a="disableDeprecationNotice"in Object(e)&&Boolean(e.disableDeprecationNotice);let i=!1;return{postcssPlugin:"postcss-env-fn",async AtRule(e,{result:t}){let n;try{n=getReplacedValue(e.params,await r)}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,a||i||(i=!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 r)}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,a||i||(i=!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,module.exports=creator;