import e from"../../../../../_virtual/index19.mjs";import{isString as t,isRegExp as o,assert as n}from"../../utils/validateTypes.mjs";import{declarationValueIndex as r}from"../../utils/nodeFieldIndices.mjs";import i from"../../utils/getDeclarationValue.mjs";import s from"../../utils/isStandardSyntaxValue.mjs";import{isValueWord as u}from"../../utils/typeGuards.mjs";import l from"../../utils/optionsMatches.mjs";import a from"../../utils/report.mjs";import c from"../../utils/ruleMessages.mjs";import p from"../../utils/setDeclarationValue.mjs";import m from"../../utils/validateOptions.mjs";const f="alpha-value-notation",d=c(f,{expected:(e,t)=>`Expected "${e}" to be "${t}"`}),b=/^(?:opacity|shape-image-threshold|fill-opacity|flood-opacity|stop-opacity|stroke-opacity)$/i,x=/(?:color|hsla?|rgba?|hwb|lab|lch|oklab|oklch)\(/i,g=/^(?:color|hsla?|rgba?|hwb|lab|lch|oklab|oklch)$/i,h=/\d/,v=(n,c)=>(v,w)=>{if(!m(w,f,{actual:n,possible:["number","percentage"]},{actual:c,possible:{exceptProperties:[t,o]},optional:!0}))return;const N=Object.freeze({number:{expFunc:F,fixFunc:j},percentage:{expFunc:k,fixFunc:y}});v.walkDecls(t=>{const o=i(t),m=b.test(t.prop);if(!(m||x.test(o))||!h.test(o))return;const v=e(o);v.walk(e=>{const o=m&&h.test(e.value),i="function"===e.type&&g.test(e.value),b=o?function(e){return"word"===e.type||"function"===e.type?e:void 0}(e):i?function(e){const t=e.nodes.some(({type:e,value:t})=>"div"===e&&","===t);if(t){const t=e.nodes.filter(({type:e})=>"word"===e||"function"===e);return 4===t.length?t[3]:void 0}const o=e.nodes.findIndex(({type:e,value:t})=>"div"===e&&"/"===t);if(-1!==o){return e.nodes.slice(o+1,e.nodes.length).find(u)}return}(e):void 0;if(!b)return;const{value:x}=b;if(!s(x))return;if(!F(x)&&!k(x))return;let y=n;if(l(c,"exceptProperties",t.prop)&&("number"===y?y="percentage":"percentage"===y&&(y="number")),N[y].expFunc(x))return;const j=N[y].fixFunc(x),$=x,I=r(t)+b.sourceIndex,P=I+b.value.length;a({message:d.expected,messageArgs:[$,j],node:t,index:I,endIndex:P,result:w,ruleName:f,fix:{apply:()=>{b.value=j,p(t,v.toString())},node:t}})})})};function y(e){const t=Number(e);return`${Number((100*t).toPrecision(3))}%`}function j(t){const o=e.unit(t);n(o);const r=Number(o.number);return Number((r/100).toPrecision(3)).toString()}function k(t){const o=e.unit(t);return o&&"%"===o.unit}function F(t){const o=e.unit(t);return o&&""===o.unit}v.ruleName=f,v.messages=d,v.meta={url:"https://stylelint.io/user-guide/rules/alpha-value-notation",fixable:!0};export{v as default};