"use strict";var A=Object.create;var f=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var _=(t,e)=>{for(var r in e)f(t,r,{get:e[r],enumerable:!0})},b=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of v(e))!D.call(t,n)&&n!==r&&f(t,n,{get:()=>e[n],enumerable:!(s=L(e,n))||s.enumerable});return t};var R=(t,e,r)=>(r=t!=null?A(U(t)):{},b(e||!t||!t.__esModule?f(r,"default",{value:t,enumerable:!0}):r,t)),G=t=>b(f({},"__esModule",{value:!0}),t);var J={};_(J,{DEFAULT_CONFIG:()=>P,normalizeConfig:()=>q});module.exports=G(J);var T={isMatch:(t,e)=>{let r=l(t);return e.some(s=>V(r,l(s)))}},I=async t=>{if(t==="micromatch"){let e;try{e=await import("micromatch")}catch{throw new Error("micromatch is not installed. Please add it as a dependency if you want to use it.")}return{isMatch:(r,s)=>{try{return e.isMatch(l(r),s.map(l))}catch(n){throw new Error(`micromatch failed to run isMatch: ${n.message}`)}}}}if(t==="picomatch"){let e;try{e=(await import("picomatch")).default}catch{throw new Error("picomatch is not installed. Please add it as a dependency if you want to use it.")}return{isMatch:(r,s)=>{try{return e(s.map(l))(l(r))}catch(n){throw new Error(`picomatch failed to run isMatch: ${n.message}`)}}}}throw new Error(`Unknown matcher name: ${t}`)},l=t=>{let e="",r=!1;for(let s of t)r?(e+=s,r=!1):s==="\\"?(r=!0,e+="\\"):s==="."?e+="/":e+=s;return e},K=t=>{let e=t.startsWith("!"),r=e?t.slice(1):t,s=[],n="",a=!1;for(let i of r)a?(n+="\\"+i,a=!1):i==="\\"?a=!0:i==="/"?(s.push(n),n=""):n+=i;return a&&(n+="\\"),s.push(n),e&&(s.negated=!0),s},V=(t,e)=>{let r=t.split("/"),s=K(e),n=s.negated===!0,a=$(r,s);return n?!a:a},$=(t,e)=>{let r=0,s=0;for(;r<t.length&&s<e.length;){let n=e[s];if(n==="**"){if(s===e.length-1)return!0;for(let a=0;r+a<=t.length;a++)if($(t.slice(r+a),e.slice(s+1)))return!0;return!1}if(!k(t[r],n))return!1;r++,s++}for(;s<e.length&&e[s]==="**";)s++;return r===t.length&&s===e.length},k=(t,e)=>{let r=!1,s=!1,n="",a="";for(let o=0;o<e.length;o++){let c=e[o];if(r){a+=c,r=!1;continue}if(c==="\\"){r=!0;continue}if(c==="*"){if(!s){s=!0,n=a,a="";continue}a+="*";continue}a+=c}if(r&&(a+="\\"),!s){let o=a.replace(/\\(.)/g,"$1");return t===o}let i=a.replace(/\\(.)/g,"$1"),h=n.replace(/\\(.)/g,"$1");return t.startsWith(h)&&t.endsWith(i)};var P={defaultStrategy:["merge","ours"],include:["**/*.json","**/*.yaml","**/*.yml","**/*.xml","**/*.toml"],exclude:["**/node_modules/**","**/dist/**"],debug:!1,writeConflictSidecar:!1},q=async t=>{let{rules:e,byStrategy:r,defaultStrategy:s,matcher:n,plugins:a,pluginConfig:i,customStrategies:h,...o}={...P,...t},c=await H(a,i),O={...h,...c},p={exact:Object.create(null),exactFields:Object.create(null),patterns:Object.create(null),default:B(s)},W=typeof n=="string"?await I(n):n!=null?n:T,M=0;if(r)for(let[y,g]of Object.entries(r)){if(!g)continue;let{name:u,important:S}=E(y);for(let w of g){let{key:d,important:x}=N(w);F(p,d,{strategies:[{name:u,important:S||x}],order:M++,source:d})}}return e&&C(e,[],(y,g)=>{let{key:u,important:S}=N(y),w=g.map(d=>{let{name:x,important:j}=E(d);return{name:x,important:j||S}});F(p,u,{strategies:w,order:M++,source:u})}),{...o,rules:p,matcher:W,customStrategies:O}},B=t=>(Array.isArray(t)?t:[t]).map(r=>{let s=r.endsWith("!");return z(r.slice(0,-1)),{name:s?r.slice(0,-1):r,important:s}}),E=t=>{let e=t.endsWith("!"),r=e?t.slice(0,-1):t;return z(r),{name:r,important:e}},z=t=>{if(t.endsWith("!"))throw new Error(`Strategy name "${t}" must not end with "!". Use "!" on field/glob to mark rule importance.`)},N=t=>{let e=t.endsWith("!"),r=e?t.slice(0,-1):t;if(!r)throw new Error(`Invalid rule key "${t}".`);return{key:r,important:e}},F=(t,e,r)=>{if(/^\[.*\]$/.test(e)){let n=e.slice(1,-1);if(n.replace(/\\\./g,"").includes(".")||n.trim()==="")throw new Error(`Invalid bracket form "${e}". Use a single bare key like "[id]".`);let a=`**.${n}.**`;m(t.patterns,a,r);return}if(/[*?[\]]/.test(e)){m(t.patterns,e,r);return}e.includes(".")?m(t.exact,e,r):m(t.exactFields,e,r)},C=(t,e,r)=>{for(let[s,n]of Object.entries(t)){let a=[...e,s];Array.isArray(n)?r(a.join("."),n):C(n,a,r)}},m=(t,e,r)=>{var n;((n=t[e])!=null?n:t[e]=[]).push(r)},H=async(t,e)=>{if(!(t!=null&&t.length))return{};let r={};for(let s of t)try{let n=await import(s),a=n.default||n;if(!a.strategies)throw new Error(`Plugin "${s}" does not export strategies`);a.init&&(e!=null&&e[s])&&await a.init(e[s]),Object.assign(r,a.strategies)}catch(n){throw new Error(`Failed to load plugin "${s}": ${n}`)}return r};0&&(module.exports={DEFAULT_CONFIG,normalizeConfig});
