import e from"cli-table3";function t(e,t=!0){return JSON.stringify(e,null,t?2:0)}function n(t){let n=new e({head:[`Key`,`Value`],colWidths:[30,50],wordWrap:!0});for(let[e,r]of Object.entries(t))n.push([e,a(r)]);return n.toString()}function r(t){let n=new e({head:[`Variant`,`File`,`Status`,`Size`,`Updated`],colWidths:[15,40,12,12,26],wordWrap:!0});for(let e of t)n.push([e.variant,e.path,o(e),s(e.size),c(e.lastModified)]);return n.toString()}function i(e,t){let n=JSON.stringify(e??{},null,2),r=JSON.stringify(t??{},null,2);if(n===r)return null;let i=p(f(n.split(`
`),r.split(`
`))),a=[`--- current`,`+++ variant`];for(let e of i)a.push(`@@ -${e.oldStart},${e.oldLines} +${e.newStart},${e.newLines} @@`),a.push(...e.lines);return a.map(d).join(`
`)}function a(e){return e===null?`null`:e===void 0?`undefined`:typeof e==`string`?e:e instanceof Date?e.toISOString():typeof e==`number`||typeof e==`boolean`?String(e):Array.isArray(e)?JSON.stringify(e):typeof e==`object`?JSON.stringify(e,null,2):String(e)}function o(e){return e.active?e.exists?`active`:`missing`:e.exists?`available`:`missing`}function s(e){if(typeof e!=`number`)return`-`;let t=[`B`,`KB`,`MB`,`GB`],n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n>=10||n%1==0?n.toFixed(0):n.toFixed(1)} ${t[r]}`}function c(e){return e?new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e):`-`}const l={reset:`\x1B[0m`,red:`\x1B[31m`,green:`\x1B[32m`,yellow:`\x1B[33m`,cyan:`\x1B[36m`,dim:`\x1B[90m`,bold:`\x1B[1m`};function u(){return process.env.NO_COLOR||process.env.FORCE_COLOR===`0`?!1:!!process.stdout?.isTTY}function d(e){return u()?e.startsWith(`@@`)?`${l.cyan}${l.bold}${e}${l.reset}`:e.startsWith(`---`)||e.startsWith(`+++`)?`${l.yellow}${e}${l.reset}`:e.startsWith(`+`)?`${l.green}${e}${l.reset}`:e.startsWith(`-`)?`${l.red}${e}${l.reset}`:e.startsWith(` `)?`${l.dim}${e}${l.reset}`:e:e}function f(e,t){let n=e.length,r=t.length,i=Array.from({length:n+1},()=>Array.from({length:r+1},()=>0));for(let a=n-1;a>=0;a--)for(let n=r-1;n>=0;n--)e[a]===t[n]?i[a][n]=i[a+1][n+1]+1:i[a][n]=Math.max(i[a+1][n],i[a][n+1]);let a=[],o=(e,t)=>{let n=a[a.length-1];n&&n.type===e?n.lines.push(t):a.push({type:e,lines:[t]})},s=0,c=0;for(;s<n&&c<r;)e[s]===t[c]?(o(`equal`,e[s]),s++,c++):i[s+1][c]>=i[s][c+1]?(o(`delete`,e[s]),s++):(o(`insert`,t[c]),c++);for(;s<n;)o(`delete`,e[s++]);for(;c<r;)o(`insert`,t[c++]);return a}function p(e){let t=[],n=1,r=1,i=null,a=[],o=()=>{i={oldStart:Math.max(n-a.length,1),newStart:Math.max(r-a.length,1),oldLines:a.length,newLines:a.length,lines:a.map(e=>` ${e}`)},a=[]},s=()=>{i&&=(t.push(i),null)};for(let t of e){if(t.type===`equal`){if(i!==null){let e=i,o=t.lines.slice(0,3);for(let t of o)e.lines.push(` ${t}`),e.oldLines++,e.newLines++;n+=o.length,r+=o.length,t.lines.length>3?(s(),a=t.lines.slice(t.lines.length-3),n+=t.lines.length-o.length,r+=t.lines.length-o.length):a=[...o].slice(-3)}else a.push(...t.lines),a.length>3&&a.splice(0,a.length-3),n+=t.lines.length,r+=t.lines.length;continue}if(i||o(),!i)throw Error(`Failed to initialize diff hunk`);let e=i;for(let i of t.lines)t.type===`delete`?(e.lines.push(`-${i}`),e.oldLines++,n++):(e.lines.push(`+${i}`),e.newLines++,r++)}return s(),t}export{n as i,r as n,t as r,i as t};