"use strict";var S=Object.create;var m=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var R=(e,s)=>{for(var r in s)m(e,r,{get:s[r],enumerable:!0})},P=(e,s,r,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let a of N(s))!A.call(e,a)&&a!==r&&m(e,a,{get:()=>s[a],enumerable:!(n=k(s,a))||n.enumerable});return e};var f=(e,s,r)=>(r=e!=null?S(b(e)):{},P(s||!e||!e.__esModule?m(r,"default",{value:e,enumerable:!0}):r,e)),F=e=>P(m({},"__esModule",{value:!0}),e);var $={};R($,{normalizeParsers:()=>j,parseConflictContent:()=>L,parseFormat:()=>E,runParser:()=>h});module.exports=F($);var x=require("child_process"),T=require("util"),g=(0,T.promisify)(x.execFile),L=async(e,s)=>{var y;let r=e.split(`
`),n=[],a=[],d;(i=>(i[i.Normal=0]="Normal",i[i.InOurs=1]="InOurs",i[i.InTheirs=2]="InTheirs"))(d||(d={}));let o=0;for(let t of r){if(t.startsWith("<<<<<<<")){o=1;continue}else if(t.startsWith("=======")){o===1&&(o=2);continue}else if(t.startsWith(">>>>>>>")){o===2&&(o=0);continue}switch(o){case 0:n.push(t),a.push(t);break;case 1:n.push(t);break;case 2:a.push(t);break}}let l=n.join(`
`),c=a.join(`
`),w=await g("git",["show",`:1:${s.filename}`],{maxBuffer:1024*1024*50}).then(({stdout:t})=>t).catch(()=>null);if(l===c&&(l=(y=await g("git",["show",`HEAD:${s.filename}`],{maxBuffer:1024*1024*50}).then(({stdout:t})=>t).catch(()=>null))!=null?y:l),!l||!c)throw new Error("Conflict parsing resulted in empty content.");let C=j(s),[O,p]=await h(l,C),[[I],u]=await Promise.all((w?[c,w]:[c]).map(t=>h(t,[p])));return{ours:O,theirs:I,base:u==null?void 0:u[0],format:typeof p=="string"?p:p.name}},_={json:"json",json5:"json5",yaml:"yaml",yml:"yaml",toml:"toml",xml:"xml"},j=e=>{var s,r;if(Array.isArray(e.parsers))return e.parsers;if(e.parsers)return e.parsers==="auto"?["json","json5","yaml","toml","xml"]:[e.parsers];if(e.filename){let n=_[(r=(s=e.filename.split(".").pop())==null?void 0:s.toLowerCase())!=null?r:""];if(n)return[n]}return["json"]},h=async(e,s)=>{for(let r of s)try{return typeof r!="string"?[r.parser(e),r]:[await E(r,e),r]}catch(n){console.debug(`Parser ${typeof r=="string"?r:r.name} failed:`,n)}throw new Error(`Failed to parse content. Tried parsers: ${s.map(r=>typeof r=="string"?r:r.name).join(", ")}`)},E=async(e,s)=>{switch(e){case"json":return JSON.parse(s);case"json5":try{let{parse:r}=await import("json5");return r(s)}catch{throw new Error("json5 parser not installed. Please install as peer dependency.")}case"yaml":try{let{parse:r}=await import("yaml");return r(s)}catch{throw new Error("yaml parser not installed. Please install as peer dependency.")}case"toml":try{let{parse:r}=await import("smol-toml");return r(s)}catch{throw new Error("toml parser not installed. Please install as peer dependency.")}case"xml":try{let{XMLParser:r}=await import("fast-xml-parser");return new r().parse(s)}catch{throw new Error("fast-xml-parser not installed. Please install as peer dependency.")}}};0&&(module.exports={normalizeParsers,parseConflictContent,parseFormat,runParser});
