UNPKG

agent-device

Version:

Open source device layer for AI coding agents: a CLI, MCP server, and typed Node.js API to control mobile, web, TV, and desktop apps on devices and simulators, locally or in the cloud.

1 lines • 1.31 kB
const e=.78,t={r:220,g:0,b:0};function n(n){let{baselineData:a,currentData:o,maxColorDistance:s}=n,c=n.width*n.height,l=Buffer.alloc(c*4),u=new Uint8Array(c),d=0,f=n.width*(n.overlapHeight??n.height);for(let n=0,c=0;n<a.length;n+=4,c+=1){let p=a[n]-o[n],m=a[n+1]-o[n+1],h=a[n+2]-o[n+2],g=Math.sqrt(p**2+m**2+h**2);if(c>=f||g>s){d+=1,u[c]=1;let a=r(o,n);l[n]=i(a,t.r,e),l[n+1]=i(a,t.g,e),l[n+2]=i(a,t.b,e),l[n+3]=255;continue}let _=r(o,n);l[n]=_,l[n+1]=_,l[n+2]=_,l[n+3]=255}return{diffData:l,diffMask:u,differentPixels:d}}function r(e,t){return i(Math.round(e[t]*.299+e[t+1]*.587+e[t+2]*.114),255,.72)}function i(e,t,n){return Math.round(e*(1-n)+t*n)}function a(e,t){let n={first:{width:e.width,height:e.height,dataLength:e.data.length},second:{width:t.width,height:t.height,dataLength:t.data.length}};if(e.width!==t.width||e.height!==t.height)return{...n,status:`dimension_mismatch`};let r=e.width*e.height;if(e.data.length!==t.data.length||e.data.length!==r*4)return{...n,status:`data_length_mismatch`};let i=0;for(let n=0;n<e.data.length;n+=4)i+=Math.abs(e.data[n]-t.data[n]),i+=Math.abs(e.data[n+1]-t.data[n+1]),i+=Math.abs(e.data[n+2]-t.data[n+2]);return{...n,status:`compared`,differencePercent:100*i/(765*r)}}function o(e){return Buffer.from(e.buffer,e.byteOffset,e.byteLength)}export{a as n,n as r,o as t};