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 • 3.01 kB
JavaScript
import{_i as e}from"./sdk-batch.js";import"./rect-center.js";function t(e){let t=new Map;for(let n of e){if(typeof n.parentIndex!=`number`)continue;let e=t.get(n.parentIndex)??[];e.push(n),t.set(n.parentIndex,e)}return t}function n(e,t){let n=[],r=new Set([e.index]),i=[...t.get(e.index)??[]];for(;i.length>0;){let e=i.pop();if(!e||r.has(e.index))continue;r.add(e.index),n.push(e);let a=t.get(e.index);a&&i.push(...a)}return n}const r=new WeakMap;function i(e,t){if(!e[t])return[];let n=s(e)[t]??t+1;return e.slice(t+1,n)}function a(e,t,n){let r=s(e)[t]??t+1;for(let i=t+1;i<r;i+=1){let t=e[i];if(t&&n(t))return t}}function o(e,t,n){let r=s(e)[t]??t+1;for(let i=t+1;i<r;i+=1){let t=e[i];t&&n(t)}}function s(e){let t=r.get(e);if(t)return t;let n=Array(e.length),i=[];for(let[t,r]of e.entries()){let e=r?.depth??0;for(;i.length>0&&e<=i.at(-1).depth;){let e=i.pop();n[e.position]=t}i.push({depth:e,position:t})}for(let t of i)n[t.position]=e.length;return r.set(e,n),n}function c(e,t){let n=[],r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);)i.add(r.index),n.push(r),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0;return n}function l(e,t,n){for(let r of c(e,t))if(n(r))return r;return null}function u(e,t,n={}){return(n.includeSelf===!0&&m(e.type)?e:null)??l(e,t,e=>m(e.type))}function d(t,n){let r=e(t.type??``),i=t.label?.trim();return!!(p(t)||r===`other`&&!i&&!t.value||(r===`other`||r===`statictext`)&&i&&n.includes(i)||r===`image`)}function f(t){let n=e(t.type??``);return n===`button`||n===`link`||n===`switch`||n===`searchfield`||n===`textfield`}function p(t){return e(t.type??``)===`button`&&t.label?.trim()===`chevron`&&t.enabled===!1}function m(t){let n=e(t??``);return n===`collectionview`||n===`table`||n===`scrollview`||n===`scrollarea`}function h(t,n){let r=t.label?.trim();if(!r||r!==n)return!1;let i=e(t.type??``);return i===`other`||i===`statictext`||i===`link`}function g(e,t,n){e.set(t.index,v(y(e,t),n))}function _(e,t,n){let r=y(e,t);e.set(t.index,v(r,n(r)))}function v(e,t){let n={...e,...t};for(let[e,r]of Object.entries(t))r===void 0&&delete n[e];return n}function y(e,t){return e.get(t.index)??t}function b(t){let n;for(let r of t){let t=e(r.type??``);(t===`application`||t===`window`)&&S(r.rect,n)&&(n=r.rect)}return n}function x(e,t,n=.8){let r=C(e),i=C(t);return r>0&&i>0&&r/i>=n}function S(e,t){return!!(e&&(!t||C(e)>C(t)))}function C(e){return e?e.width*e.height:0}function w(e,t,n){let r=new Map(n.map(e=>[e.index,e])),i=new Map;for(let[t,n]of e.entries())i.set(n.index,t);return e.map((e,n)=>{let a=typeof e.parentIndex==`number`?i.get(e.parentIndex):void 0;return a===void 0&&typeof e.parentIndex==`number`&&(a=T(e.parentIndex,t,r,i)),{...e,index:n,parentIndex:a}})}function T(e,t,n,r){let i=e,a=new Set;for(;typeof i==`number`&&!a.has(i);){if(a.add(i),!t.has(i))return r.get(i);i=n.get(i)?.parentIndex}}export{_,b as a,o as c,h as d,m as f,d as g,w as h,a as i,p as l,g as m,i as n,l as o,f as p,n as r,u as s,t,x as u};