import{tokenize as e,TokenType as t}from"../../../../@csstools/css-tokenizer/dist/index.mjs";import{walk as i,parseListOfComponentValues as s,isFunctionNode as r,isTokenNode as o}from"../../../../@csstools/css-parser-algorithms/dist/index.mjs";import{atRuleParamIndex as n,declarationValueIndex as m}from"../../utils/nodeFieldIndices.mjs";import{isString as u,isRegExp as l}from"../../utils/validateTypes.mjs";import a from"../../utils/getAtRuleParams.mjs";import c from"../../utils/getDeclarationValue.mjs";import p from"../../utils/isNonNegativeInteger.mjs";import d from"../../utils/matchesStringOrRegExp.mjs";import f from"../../utils/optionsMatches.mjs";import g from"../../utils/report.mjs";import j from"../../utils/ruleMessages.mjs";import x from"../../utils/validateObjectWithProps.mjs";import v from"../../utils/validateOptions.mjs";const b="number-max-precision",h=j(b,{expected:(e,t)=>`Expected "${e}" to be "${t}"`}),N=(j,N)=>(P,w)=>{if(!v(w,b,{actual:j,possible:[p]},{optional:!0,actual:N,possible:{ignoreProperties:[u,l],ignoreUnits:[u,l],insideFunctions:[x(p)]}}))return;const k=new Map(Object.entries(N?.insideFunctions??{}));function D(n,m,u){if(!u.includes("."))return;const l="prop"in n?n.prop:void 0;if(f(N,"ignoreProperties",l))return;const a={ignored:!1,precision:j};i(s(e({css:u})),({node:e,state:i})=>{i&&(i.ignored||function(e,i,s,n){if(r(s)){const e=s.getName().toLowerCase();return"url"===e?void(n.ignored=!0):void(n.precision=function(e,t){const i=k.get(e);if(void 0!==i)return i;for(const[t,i]of k)if(d(e,t))return i;return t}(e,n.precision))}if(!o(s))return;const[m,u,l,a,c]=s.value;if(m!==t.Number&&m!==t.Dimension&&m!==t.Percentage)return;let p=0;if(m===t.Dimension){const e=c.unit;if(p=e.length,f(N,"ignoreUnits",e))return}else if(m===t.Percentage&&(p=1,f(N,"ignoreUnits","%")))return;const j=/\d*\.(\d+)/.exec(u);if(null==j||null==j[0]||null==j[1])return;if(j[1].length<=n.precision)return;const x=i(e);g({result:w,ruleName:b,node:e,index:x+l,endIndex:x+(a+1)-p,message:h.expected,messageArgs:[c.value,c.value.toFixed(n.precision)]})}(n,m,e,i))},a)}P.walkAtRules(e=>{"import"!==e.name.toLowerCase()&&D(e,n,a(e))}),P.walkDecls(e=>{D(e,m,c(e))})};N.ruleName=b,N.messages=h,N.meta={url:"https://stylelint.io/user-guide/rules/number-max-precision"};export{N as default};