"use strict";var e=require("postcss-value-parser"),t=require("@csstools/utilities");const n=/^(?:cross-fade|image|(?:repeating-)?(?:conic|linear|radial)-gradient|url|var)$/i;function getImage(t){return!(!t||!t.type)&&("string"===t.type?"url("+e.stringify(t)+")":!("function"!==t.type||!n.test(t.value))&&e.stringify(t))}const i=new Map([["dpcm",2.54],["dpi",1],["dppx",96],["x",96]]);function getMedia(e,t,n){if("boolean"==typeof e)return!1;const i=Math.floor(e/96*100)/100;return t.atRule({name:"media",params:`(-webkit-min-device-pixel-ratio: ${i}), (min-resolution: ${e}dpi)`,source:n.source})}function getMediaDPI(t){if(!t)return!1;if("word"!==t.type)return!1;if(!isNumericNode(t))return!1;const n=e.unit(t.value);if(!n)return!1;const r=i.get(n.unit.toLowerCase());return!!r&&Number(n.number)*r}function isNumericNode(t){if(!t||!t.value)return!1;try{return!1!==e.unit(t.value)}catch{return!1}}const handleInvalidation=(e,t,n)=>{if("warn"===e.oninvalid)e.decl.warn(e.result,t,{word:String(n)});else if("throw"===e.oninvalid)throw e.decl.error(t,{word:String(n)})},processImageSet=(t,n,i)=>{const r=n.parent;if(!r)return;const o=new Map,s=n.value;for(let r=0;re-t)),u=l.map((e=>o.get(e)?.atRule)).filter((e=>!!e));if(!u.length)return;const c=o.get(l[0])?.value;if(!c)return;const f=u.slice(1);f.length&&r.after(f),n.cloneBefore({value:c.trim()}),i.preserve||(n.remove(),r.nodes?.length||r.remove())},r=/(?:^|[^\w-])(?:-webkit-)?image-set\(/i,o=/^(?:-webkit-)?image-set$/i,creator=n=>{const i=!("preserve"in Object(n))||Boolean(n?.preserve),s="onInvalid"in Object(n)?n?.onInvalid:"ignore";if("oninvalid"in Object(n))throw new Error('"oninvalid" was changed to "onInvalid" to match other plugins with similar options');return{postcssPlugin:"postcss-image-set-function",Declaration(n,{result:a,postcss:l}){const u=n.value;if(!r.test(u))return;if(t.hasFallback(n))return;let c;try{c=e(u)}catch{n.warn(a,`Failed to parse value '${u}' as an image-set function. Leaving the original value intact.`)}if(void 0===c)return;const f=[];c.walk((t=>{if("function"!==t.type)return;if(!o.test(t.value))return;let i=!1;if(e.walk(t.nodes,(e=>{"function"===e.type&&o.test(e.value)&&(i=!0)})),i)return handleInvalidation({decl:n,oninvalid:s,result:a},"nested image-set functions are not allowed",e.stringify(t)),!1;const r=t.nodes.filter((e=>"comment"!==e.type&&"space"!==e.type));f.push({imageSetFunction:t,imageSetOptionNodes:r})})),processImageSet(f,n,{decl:n,oninvalid:s,preserve:i,result:a,postcss:l})}}};creator.postcss=!0,module.exports=creator;