import{parse as e}from"../../../../css-tree/lib/index.mjs";import{isString as r,isRegExp as t}from"../../utils/validateTypes.mjs";import{colorProperties as i}from"../../reference/properties.mjs";import o from"../../utils/eachDeclarationBlock.mjs";import s from"../../utils/isCustomProperty.mjs";import n from"../../utils/isStandardSyntaxProperty.mjs";import a from"../../utils/isStandardSyntaxValue.mjs";import{namedColorsKeywords as u}from"../../reference/keywords.mjs";import l from"../../utils/optionsMatches.mjs";import p from"../../utils/report.mjs";import c from"../../utils/ruleMessages.mjs";import m from"../../utils/validateOptions.mjs";import f from"../../utils/vendor.mjs";import{List as d}from"../../../../css-tree/lib/utils/List.mjs";const y="declaration-block-no-duplicate-properties",h=c(y,{rejected:e=>`Unexpected duplicate "${e}"`}),v=e=>"children"in e&&e.children instanceof d,g=(e,r,t)=>{if(e.length!==r.length)return!1;for(let o=0;o<e.length;o++){const n=e[o],a=r[o];if(void 0===n||void 0===a||n.type!==a.type)return!1;const l="name"in n?String(n.name):"",p="name"in a?String(a.name):"";if("Identifier"===n.type&&s(l)&&"Identifier"===a.type&&s(p))continue;if("Identifier"===n.type&&"Identifier"===a.type&&i.has(t.toLowerCase())&&u.has(l.toLowerCase())&&u.has(p.toLowerCase()))continue;if(l.toLowerCase()!==p.toLowerCase())return!1;if(("unit"in n?n.unit:"")!==("unit"in a?a.unit:""))return!1;const c=v(n)?n.children.toArray():null,m=v(a)?a.children.toArray():null;if(Array.isArray(c)&&Array.isArray(m)){if(g(c,m,t))continue;return!1}}return!0},j=(i,u)=>(c,d)=>{if(!m(d,y,{actual:i},{actual:u,possible:{ignore:["consecutive-duplicates","consecutive-duplicates-with-different-values","consecutive-duplicates-with-different-syntaxes","consecutive-duplicates-with-same-prefixless-values"],ignoreProperties:[r,t]},optional:!0}))return;const j=l(u,"ignore","consecutive-duplicates"),x=l(u,"ignore","consecutive-duplicates-with-different-values"),w=l(u,"ignore","consecutive-duplicates-with-different-syntaxes"),A=l(u,"ignore","consecutive-duplicates-with-same-prefixless-values"),C=e=>()=>{e.remove()};o(c,r=>{const t=[];r(r=>{const i=r.prop,o=r.prop.toLowerCase(),c=r.value,m=r.important;if(!n(i))return;if(s(i))return;if(l(u,"ignoreProperties",i))return;if("src"===o)return;const L=t.findIndex(e=>e.prop.toLowerCase()===o);-1===L&&t.push(r);const b=t[L];if(!b)return;const S=b.value||"",I=b.important||!1,k=!m&&I,P=L===t.length-1,N=f.unprefixed(c)===f.unprefixed(S),M=()=>{const e=k?r:b,o=k?i:b.prop;k||(t[L]=r),p({message:h.rejected,messageArgs:[o],node:e,result:d,ruleName:y,word:o,fix:{apply:C(e),node:e.parent}})};if(x||w||A){if(!P||A&&!N)return void M();if(w){if(((r,t,i)=>{if(r===t)return!0;if(!a(r)||!a(t))return!1;let o,s;try{o=e(r,{context:"value"}),s=e(t,{context:"value"})}catch{return!1}const n=v(o)?o.children.toArray():[],u=v(s)?s.children.toArray():[];return g(n,u,i)})(c,S,i))return void M()}if(c!==S)return;return p({message:h.rejected,messageArgs:[b.prop],node:b,result:d,ruleName:y,word:b.prop,fix:{apply:C(b),node:b.parent}})}j&&P||M()})})};j.ruleName=y,j.messages=h,j.meta={url:"https://stylelint.io/user-guide/rules/declaration-block-no-duplicate-properties",fixable:!0};export{j as default};