import{tokenize as e,TokenType as t,NumberType as s}from"../../../../@csstools/css-tokenizer/dist/index.mjs";import{isTokenNode as r,walk as i,parseListOfComponentValues as o,isFunctionNode as a}from"../../../../@csstools/css-parser-algorithms/dist/index.mjs";import{parseFromTokens as m,isMediaFeature as n}from"../../../../@csstools/media-query-list-parser/dist/index.mjs";import{atRuleParamIndex as u,declarationValueIndex as l}from"../../utils/nodeFieldIndices.mjs";import{isString as d,isRegExp as p}from"../../utils/validateTypes.mjs";import{atRuleRegexes as c}from"../../utils/regexes.mjs";import f from"../../utils/getAtRuleParams.mjs";import g from"../../utils/getDeclarationValue.mjs";import j from"../../utils/hasDimension.mjs";import N from"../../utils/isUnicodeRangeDescriptor.mjs";import y from"../../utils/optionsMatches.mjs";import F from"../../utils/report.mjs";import h from"../../utils/ruleMessages.mjs";import v from"../../utils/validateObjectWithArrayProps.mjs";import w from"../../utils/validateOptions.mjs";const x="unit-disallowed-list",D=h(x,{rejected:e=>`Unexpected unit "${e}"`}),b=(e,s)=>(h,b)=>{if(!w(b,x,{actual:e,possible:[d]},{optional:!0,actual:s,possible:{ignoreFunctions:[d,p],ignoreProperties:[v(d,p)],ignoreMediaFeatureNames:[v(d,p)]}}))return;const A=[e].flat();function P(e,s,i,o,a){if(!r(i))return;if(i.value[0]!==t.Dimension)return;const[,,,m,{unit:n}]=i.value,u=n.toLowerCase();if(!A.includes(u))return;if(a&&y(a,u,o))return;const l=s(e)+(m+1)-n.length;F({index:l,endIndex:l+n.length,message:D.rejected,messageArgs:[n],node:e,result:b,ruleName:x})}h.walkAtRules(c.mediaName,e=>{const t=f(e);j(t)&&m(k(t)).forEach(t=>{const i={mediaFeatureName:void 0};t.walk(({node:t,state:i})=>{i&&(n(t)&&(i.mediaFeatureName=t.getName().toLowerCase()),i.mediaFeatureName&&r(t)&&P(e,u,t,i.mediaFeatureName,s?.ignoreMediaFeatureNames))},i)})}),h.walkDecls(e=>{if(N(e))return;const t=g(e);if(!j(t))return;i(o(k(t)),({node:t,state:i})=>{i&&(i.ignored||(r(t)?P(e,l,t,e.prop,s?.ignoreProperties):function(e){if(!a(e))return!1;const t=e.getName().toLowerCase();return"url"===t||y(s,"ignoreFunctions",t)}(t)&&(i.ignored=!0)))},{ignored:!1})})};function k(r){return e({css:r}).map(e=>e[0]!==t.Percentage?e:[t.Dimension,e[1],e[2],e[3],{value:e[4].value,unit:"%",type:s.Number}])}b.primaryOptionArray=!0,b.ruleName=x,b.messages=D,b.meta={url:"https://stylelint.io/user-guide/rules/unit-disallowed-list"};export{b as default};