import e from"../../../../../_virtual/index19.mjs";import{declarationValueIndex as t}from"../../utils/nodeFieldIndices.mjs";import r from"../../utils/getDeclarationValue.mjs";import o from"../../utils/isStandardSyntaxColorFunction.mjs";import{isValueFunction as i}from"../../utils/typeGuards.mjs";import n from"../../utils/isVarFunction.mjs";import s from"../../utils/optionsMatches.mjs";import u from"../../utils/report.mjs";import a from"../../utils/ruleMessages.mjs";import l from"../../utils/setDeclarationValue.mjs";import m from"../../utils/validateOptions.mjs";const f="color-function-notation",c=a(f,{expected:e=>`Expected ${e} color-function notation`}),d=/^(?:rgba|hsla)$/i,p=/\b(?:rgba?|hsla?)\(/i,g=/^(?:rgba?|hsla?)$/i,v=(a,v)=>(h,y)=>{if(!m(y,f,{actual:a,possible:["modern","legacy"]},{actual:v,possible:{ignore:["with-var-inside"]},optional:!0}))return;const w=s(v,"ignore","with-var-inside");h.walkDecls(s=>{if(!p.test(s.value))return;if("modern"===a&&!s.value.includes(","))return;const m=e(r(s));m.walk(e=>{if(!i(e))return;if(!o(e))return;const{value:r,sourceIndex:p,sourceEndIndex:v,nodes:h}=e;if(w&&function(e){return e.some(e=>n(e))}(h))return;if(!g.test(r))return;if(!(h.length>=5))return;if("modern"===a&&!b(h))return;if("legacy"===a&&b(h))return;const I=t(s)+p,D=I+(v-p),F="modern"===a?()=>{let t=0;e.nodes=h.map(e=>(j(e)&&(t<2?(e.type="space",e.value=x(e.after),t++):(e.value="/",e.before=x(e.before),e.after=x(e.after))),e)),d.test(r)&&(e.value=r.slice(0,-1)),l(s,m.toString())}:void 0;u({message:c.expected,messageArgs:[a],node:s,index:I,endIndex:D,result:y,ruleName:f,fix:{apply:F,node:s}})})})};function x(e){return""!==e?e:" "}function j(e){return"div"===e.type&&","===e.value}function b(e){let t=0;for(const r of e)if(j(r))t++;else if("/"===r.value)return!1;return t&&(2===t||3===t)}v.ruleName=f,v.messages=c,v.meta={url:"https://stylelint.io/user-guide/rules/color-function-notation",fixable:!0};export{v as default};