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.73 kB
JavaScript
import{_i as e}from"./sdk-batch.js";import{gt as t}from"./sdk-contracts.js";import{i as n,n as r,o as i,r as a,s as o,t as s}from"./android-input-ownership.js";import{i as c,r as l}from"./android-system-chrome.js";const u=new Set([`textfield`,`securetextfield`,`textview`,`textarea`,`searchfield`,`edittext`]),d={strippedIndexes:new Set,refs:new Set};function f(o){let c=new Map(o.map(e=>[e.index,e])),l=new Set(o.filter(t=>e(t.type??``)===`keyboard`).map(e=>e.index)),u=new Set(o.filter(e=>i(e,n)||i(e,r)).map(e=>e.index)),f=new Set(o.filter(e=>i(e,s)).map(e=>e.index)),m=new Set(o.filter(e=>i(e,a)).map(e=>e.index));if(l.size===0&&u.size===0&&f.size===0&&m.size===0)return d;let h=_(o,c,l),g=new Set(h),v=T(o,c,h);for(let e of _(o,c,v))g.add(e);for(let e of p(o,c,v,l,h))g.delete(e);for(let e of u)g.add(e);for(let e of _(o,c,m))g.add(e);for(let e of f)g.add(e);let y=new Set(t(o.filter(e=>g.has(e.index))));return{strippedIndexes:new Set([...g].filter(e=>!l.has(e))),refs:y}}function p(e,t,n,r,i){let a=new Set;if(n.size===0)return a;let o=h(t,n,r);if(o.size===0)return a;let s=g(t,r);for(let n of e)!i.has(n.index)&&!s.has(n.index)&&n.rect&&m(n,t,o)&&a.add(n.index);return a}function m(e,t,n){if(!e.rect)return!1;let r=E(e,t);if(r===void 0)return!1;let i=n.get(r);return i!==void 0&&e.rect.y+e.rect.height/2<i}function h(e,t,n){let r=new Map;for(let i of n){let n=e.get(i);if(!n?.rect)continue;let a=E(n,e);if(a===void 0||!t.has(a))continue;let o=r.get(a);(o===void 0||n.rect.y<o)&&r.set(a,n.rect.y)}return r}function g(e,t){let n=new Set;for(let r of t){let t=e.get(r),i=t&&typeof t.parentIndex==`number`?e.get(t.parentIndex):void 0;for(;i;)n.add(i.index),i=typeof i.parentIndex==`number`?e.get(i.parentIndex):void 0}return n}function _(e,t,n){let r=new Set(n);if(n.size===0)return r;for(let i of e)D(i,t,n)&&r.add(i.index);return r}function v(e,t){if(e.systemBar!==void 0)return!0;if(e.bundleId!==`com.android.systemui`)return!1;if(l(e))return!0;let n=new Set,r=e;for(;r?.bundleId===`com.android.systemui`&&!n.has(r.index);){if(c(r.identifier))return!0;n.add(r.index),r=r.parentIndex===void 0?void 0:t.get(r.parentIndex)}return!1}function y(e,n){let r=new Map(e.map(e=>[e.index,e])),i=new Set(e.filter(o).map(e=>e.index)),a=new Set([...i].filter(e=>{let t=r.get(e)?.parentIndex,n=t===void 0?void 0:r.get(t);return!n||!i.has(n.index)})),s=n===`com.android.systemui`?new Set:b(e,r,i),c=new Set([...i].filter(e=>!a.has(e)));for(let e of s)c.add(e);let l=new Set(t(e.filter(e=>i.has(e.index)||s.has(e.index))));return c.size===0&&l.size===0?d:{strippedIndexes:c,refs:l}}function b(e,t,n){return new Set(e.filter(e=>!n.has(e.index)&&v(e,t)).map(e=>e.index))}function x(e,t){let n=f(e),r=y(e,t);return n.strippedIndexes.size===0&&n.refs.size===0?r:r.strippedIndexes.size===0&&r.refs.size===0?n:{strippedIndexes:new Set([...n.strippedIndexes,...r.strippedIndexes]),refs:new Set([...n.refs,...r.refs])}}function S(e,t){let{strippedIndexes:n}=x(e,t);return n.size===0?e:e.filter(e=>!n.has(e.index))}function C(e,t){return x(e,t).refs}function w(e){return f(e).refs}function T(t,n,r){let i=new Set;for(let t of r){let r=n.get(t);if(!r||e(r.type??``)!==`keyboard`)continue;let a=E(r,n);a!==void 0&&i.add(a)}for(let a of i){let o=new Set([a]);t.some(t=>u.has(e(t.type??``))&&!r.has(t.index)&&D(t,n,o))&&i.delete(a)}return i}function E(t,n){let r=typeof t.parentIndex==`number`?n.get(t.parentIndex):void 0;for(;r;){if(e(r.type??``)===`window`)return r.index;r=typeof r.parentIndex==`number`?n.get(r.parentIndex):void 0}}function D(e,t,n){let r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0;for(;r;){if(n.has(r.index))return!0;r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}export{C as n,S as r,w as t};