import e from"../../../../../_virtual/index19.mjs";import{declarationValueIndex as t}from"../../utils/nodeFieldIndices.mjs";import r from"../../utils/getDeclarationValue.mjs";import n from"../../utils/isStandardSyntaxValue.mjs";import s from"../../utils/report.mjs";import i from"../../utils/ruleMessages.mjs";import o from"../../utils/setDeclarationValue.mjs";import u from"../../utils/validateOptions.mjs";const l="lightness-notation",a=i(l,{expected:(e,t)=>`Expected "${e}" to be "${t}"`}),m=new Set(["oklch","oklab"]),c=new Set(["lch","lab"]),f=new Set([...m,...c]),p=new RegExp(`\\b(?:${[...f].join("|")})\\(`,"i"),d=i=>(d,x)=>{u(x,l,{actual:i,possible:["percentage","number"]})&&d.walkDecls(u=>{if(!p.test(u.value))return;const d=e(r(u));d.walk(r=>{if("function"!==r.type)return;const p=r.value.toLowerCase();if(!f.has(p))return;const b=function({nodes:e}){return e.find(({type:e})=>"word"===e||"function"===e)}(r);if(!b)return;const{value:h}=b;if(!n(h))return;const $=e.unit(h);if(!$)return;const j="%"===$.unit,w=""===$.unit;if(!j&&!w)return;if("percentage"===i&&j)return;if("number"===i&&w)return;const v="percentage"===i?function(e,t){let r=Number.parseFloat(e);if(c.has(t))return`${r}%`;m.has(t)&&(r*=100);if(Number.isInteger(r))return`${r}%`;return`${g(r,e)}%`}(h,p):function(e,t){let r=Number.parseFloat(e);if(m.has(t))return r/=100,`${g(r,e)}`;return`${r}`}(h,p),S=t(u);s({message:a.expected,messageArgs:[h,v],node:u,index:S+b.sourceIndex,endIndex:S+b.sourceEndIndex,result:x,ruleName:l,fix:{apply:()=>{b.value=v,o(u,d.toString())},node:u}})})})};function g(e,t){if(0===e)return"0";const r=t.replaceAll("%","").replaceAll(".","").length;return 0===r?`${e}`:e.toPrecision(r).replace(/0+$/,"")}d.ruleName=l,d.messages=a,d.meta={url:"https://stylelint.io/user-guide/rules/lightness-notation",fixable:!0};export{d as default};