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.58 kB
import{r as e}from"./rolldown-runtime.js";import{v as t}from"./sdk-contracts.js";import{o as n}from"./screenshot.js";import"./capture.js";import{i as r,o as i}from"./png-worker-client.js";import{r as a}from"./png.js";import{promises as o}from"node:fs";var s=e({resizePngBox:()=>u,resizePngFile:()=>l,resizePngFileToScale:()=>c});async function c(e,a){let{min:s,max:c}=n;if(!Number.isFinite(a)||a<s||a>c)throw new t(`INVALID_ARGS`,`Screenshot scale must be between ${s} and ${c}`);if(a===1)return;let l=await r(await o.readFile(e),`screenshot`),d=Math.max(1,Math.round(l.width*a)),f=Math.max(1,Math.round(l.height*a));await o.writeFile(e,await i(u(l,d,f)))}async function l(e,n,a){if(!Number.isInteger(n)||n<1||!Number.isInteger(a)||a<1)throw new t(`INVALID_ARGS`,`Screenshot resize dimensions must be positive integers`);let s=await r(await o.readFile(e),`screenshot`);(s.width!==n||s.height!==a)&&await o.writeFile(e,await i(u(s,n,a)))}function u(e,t,n){let r=new a.PNG({width:t,height:n});for(let i=0;i<n;i+=1){let a=i*e.height/n,o=(i+1)*e.height/n;for(let n=0;n<t;n+=1){let s=n*e.width/t,c=(n+1)*e.width/t,l=0,u=0,d=0,f=0,p=0;for(let t=Math.floor(a);t<Math.ceil(o);t+=1){let n=Math.min(t+1,o)-Math.max(t,a);for(let r=Math.floor(s);r<Math.ceil(c);r+=1){let i=n*(Math.min(r+1,c)-Math.max(r,s)),a=(t*e.width+r)*4;l+=(e.data[a]??0)*i,u+=(e.data[a+1]??0)*i,d+=(e.data[a+2]??0)*i,f+=(e.data[a+3]??0)*i,p+=i}}let m=(i*r.width+n)*4;r.data[m]=Math.round(l/p),r.data[m+1]=Math.round(u/p),r.data[m+2]=Math.round(d/p),r.data[m+3]=Math.round(f/p)}}return r}export{c as i,u as n,l as r,s as t};