import{tokenize as e,TokenType as t}from"../../../../@csstools/css-tokenizer/dist/index.mjs";import{isFunctionNode as s,isTokenNode as o,walk as i,parseListOfComponentValues as r}from"../../../../@csstools/css-parser-algorithms/dist/index.mjs";import{parseFromTokens as n,isMediaFeature as m}from"../../../../@csstools/media-query-list-parser/dist/index.mjs";import{atRuleParamIndex as a,declarationValueIndex as l}from"../../utils/nodeFieldIndices.mjs";import{isString as u,isRegExp as d}from"../../utils/validateTypes.mjs";import{atRuleRegexes as f}from"../../utils/regexes.mjs";import c from"../../utils/getAtRuleParams.mjs";import p from"../../utils/getDeclarationValue.mjs";import g from"../../utils/hasDimension.mjs";import j from"../../utils/isStandardSyntaxAtRule.mjs";import w from"../../utils/isStandardSyntaxDeclaration.mjs";import x from"../../utils/isStandardSyntaxValue.mjs";import h from"../../utils/isUnicodeRangeDescriptor.mjs";import k from"../../utils/optionsMatches.mjs";import{units as v}from"../../reference/units.mjs";import y from"../../utils/report.mjs";import D from"../../utils/ruleMessages.mjs";import S from"../../utils/validateOptions.mjs";import N from"../../utils/vendor.mjs";const X=new Set(v);X.delete("x");const A="unit-no-unknown",C=D(A,{rejected:e=>`Unexpected unknown unit "${e}"`}),L=/^(?:min-|max-)?resolution$/i,R=(v,D)=>(R,U)=>{if(!S(U,A,{actual:v},{actual:D,possible:{ignoreUnits:[u,d],ignoreFunctions:[u,d]},optional:!0}))return;const F=s=>{if(!g(s))return;const o=e({css:s});return o.some(e=>e[0]===t.Dimension&&!X.has(e[4].unit.toLowerCase()))?o:void 0},T=(e,o,i,r)=>{if(s(i)){const e=i.getName(),t=e.toLowerCase();return"url"===t||k(D,"ignoreFunctions",e)?void(r.ignored=!0):"image-set"===N.unprefixed(t)?void(r.allowX=!0):void 0}const[n,,,m,a]=i.value;if(n!==t.Dimension)return;if(k(D,"ignoreUnits",a.unit))return;const l=a.unit.toLowerCase();if("x"===l&&r.allowX)return;if(X.has(l)&&"x"!==l)return;const u=o(e)+(m+1)-l.length;y({message:C.rejected,messageArgs:[a.unit],node:e,index:u,endIndex:u+l.length,result:U,ruleName:A})};R.walkAtRules(f.mediaName,e=>{if(!j(e))return;const t=c(e),i=F(t);i&&n(i).forEach(t=>{t.walk(({node:t,state:i})=>{if(i&&!i.ignored)if(m(t)){const e=t.getName();L.test(e)&&(i.allowX=!0)}else(s(t)||o(t))&&T(e,a,t,i)},{ignored:!1,allowX:!1})})}),R.walkDecls(e=>{if(!w(e))return;if(h(e))return;const t=p(e);if(!x(t))return;const n=F(t);if(!n)return;const m={ignored:!1,allowX:"image-resolution"===e.prop.toLowerCase()};i(r(n),({node:t,state:i})=>{i&&(i.ignored||(s(t)||o(t))&&T(e,l,t,i))},m)})};R.ruleName=A,R.messages=C,R.meta={url:"https://stylelint.io/user-guide/rules/unit-no-unknown"};export{R as default};