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 • 6.51 kB
JavaScript
import{Oi as e,Yi as t,bi as n,li as r,vi as i,yi as a}from"./sdk-batch.js";import{ct as o,ot as s}from"./sdk-contracts.js";import{a as c,n as l}from"./rect-center.js";const u=[`tabbar`,`toolbar`,`navigationbar`,`bottomnavigation`,`bottomnavigationview`,`sheet`,`dialog`,`alert`,`popover`,`menu`],d=[`toolbar`],f=[`tabbar`],p=[`navigationbar`],m=[`scrollbar`,`scrollindicator`],h=[`button`,`link`,`menuitem`,`tabitem`,`textfield`,`searchfield`,`edittext`,`checkbox`,`radio`,`switch`,`cell`];function g(e){let t=new Map,n=new Map;for(let r of e){if(t.set(r.index,r),typeof r.parentIndex!=`number`)continue;let e=n.get(r.parentIndex);e?e.push(r):n.set(r.parentIndex,[r])}return{byIndex:t,childrenByParent:n,toolbarHostReach:new Map}}function _(e,t={}){if(e.length<2)return e;let n=g(e),r={nodes:e,byIndex:n.byIndex,neighbourhood:n,overlayPositions:e.flatMap((e,r)=>j(e,n,t)?[r]:[]),coverCache:new Map},a=[];for(let[n,o]of e.entries()){if(!A(o))continue;let e=T(r,n,o,t);if(!e)continue;let s=x(e,i(e,t.producer));a.push(s?{position:n,coveredBy:s}:{position:n})}return C(e,a)}const v=new Set([`element`,`group`,`other`]),y=[...f,...d,...p];function b(e){return!a(e,[`bottomnavigation`])&&a(e,y)}function x(e,t){let n=e.label?.trim(),r=o(e.type??`Element`),i=v.has(r);if(!n&&!t&&i)return null;let a=Z(e.rect);return{kind:t??r,...n?{label:n.slice(0,80)}:{},...a?{rect:a}:{},...t?{persistentBar:!0}:{}}}function S(e,t){let n=[];for(let[r,i]of e.entries()){if(!A(i))continue;let e=t(i);if(!e)continue;let a=e===!0?null:x(e);n.push(a?{position:r,coveredBy:a}:{position:r})}return C(e,n)}function C(e,t){if(t.length===0)return e;let n=[...e];for(let{position:r,coveredBy:i}of t){let t=e[r];n[r]={...t,hittable:!1,interactionBlocked:`covered`,...i?{coveredBy:i}:{},presentationHints:Q(t.presentationHints)}}return n}function w(e){return e.interactionBlocked!==void 0}function T(e,t,n,r){let i=e.coverCache.get(t);if(i!==void 0)return i;e.coverCache.set(t,null);let a=Z(n.rect);if(!a)return D(e,t,null);let o=s(a),c=r.isAdditionalOverlayNode?.(n)===!0;for(let i of e.overlayPositions){if(!E(e,i,t,c,r))continue;let s=e.nodes[i];if(O(e,i,n,a,o,r))return D(e,t,s)}return D(e,t,null)}function E(e,t,n,r,i){let a=e.nodes[t];return a?t>n?!0:t===n||r?!1:i.isAdditionalOverlayNode?.(a)===!0:!1}function D(e,t,n){return e.coverCache.set(t,n),n}function O(e,t,r,i,a,o){if(!e.nodes[t])return!1;let s=k(e,t,r,i,o);return!!(s&&n(s,a.x,a.y))}function k(e,t,n,r,i){let a=e.nodes[t];if(!a||!j(a,e.neighbourhood,i)||Y(n,a,e.byIndex))return null;let o=Z(a.rect);return!o||l(r,o)||I(a,n,e)||L(a,o,n,e.byIndex)||T(e,t,a,i)?null:o}function A(e){return Z(e.rect)?e.hittable===!0||J(e)?!0:!!(e.label?.trim()||e.value?.trim()||e.identifier?.trim()):!1}function j(e,t,n){return!Z(e.rect)||r(e)||U(e,t)||M(e,t)||F(e,t)?!1:a(e,u)||G(e,t.byIndex,n)}function M(e,t){if(!b(e)||typeof e.parentIndex!=`number`)return!1;let n=Z(e.rect);return n?(t.childrenByParent.get(e.parentIndex)??[]).some(t=>t.index!==e.index&&l(n,t.rect)):!1}function N(e,t){let n=t.toolbarHostReach.get(e.index);if(n!==void 0)return n;let r=P(e,t);return t.toolbarHostReach.set(e.index,r),r}function P(e,t){if(!a(e,d)||typeof e.parentIndex!=`number`)return null;let n=Z(e.rect);if(!n)return null;let r=t.childrenByParent.get(e.parentIndex),i=r.findIndex(t=>t.index===e.index),o=r.flatMap((e,t)=>t!==i&&H(n,e)?[t]:[]);if(o.length===0||o.some(e=>e>i))return null;let s=z(r,i),c=o.filter(e=>e>=s);if(c.length===o.length)return{kind:`own-presentation`};let l=new Set;for(let e of c){if(!a(r[e],f))break;l.add(e)}return{kind:`over-beneath`,parentIndex:e.parentIndex,ownBranchIndexes:new Set(r.slice(s,i).filter((e,t)=>!l.has(s+t)).map(e=>e.index))}}function F(e,t){return N(e,t)?.kind===`own-presentation`}function I(e,t,n){let r=N(e,n.neighbourhood);if(r?.kind!==`over-beneath`)return!1;let i=R(t,r.parentIndex,n.byIndex);return i!==void 0&&r.ownBranchIndexes.has(i.index)}function L(e,t,n,r){if(!a(e,d))return!1;let i=n,o=new Set;for(;i&&!o.has(i.index);){if(a(i,p))return V(i,t);o.add(i.index),i=typeof i.parentIndex==`number`?r.get(i.parentIndex):void 0}return!1}function R(e,t,n){let r=e,i=new Set;for(;r&&!i.has(r.index);){if(r.parentIndex===t)return r;i.add(r.index),r=typeof r.parentIndex==`number`?n.get(r.parentIndex):void 0}}function z(e,t){for(let n=t-1;n>=0;n--)if(B(e,n))return n+1;return 0}function B(e,t){let n=e[t];if(!a(n,d))return!1;let r=Z(n.rect);return!r||!e.some(e=>V(e,r))}function V(t,n){let r=Z(t.rect);return!!(r&&a(t,p)&&e(r,n))}function H(n,r){let i=b(r)||t(r)&&!a(r,m),o=Z(r.rect);return!!(i&&o&&e(n,o))}function U(e,t){if(!b(e))return!1;let n=Z(e.rect);if(!n)return!1;let i=t.byIndex,a=typeof e.parentIndex==`number`?i.get(e.parentIndex):void 0,o=new Set;for(;a&&!o.has(a.index);){if(r(a)){let r=Z(a.rect);return!!(r&&($(n,r)||W(e,n,r,t)))}o.add(a.index),a=typeof a.parentIndex==`number`?i.get(a.parentIndex):void 0}return!1}function W(e,t,n,r){if(e.role!==`_UIFloatingBarContainerView`||typeof e.parentIndex!=`number`)return!1;let i=t.y+t.height;if(i>=n.y+n.height||!$(t,{...n,height:i-n.y}))return!1;let o=(r.childrenByParent.get(e.parentIndex)??[]).flatMap(e=>{if(!a(e,[`button`,`tabitem`]))return[];let t=Z(e.rect);return t&&Math.abs(t.y-i)<=.5&&t.x>=n.x&&t.x+t.width<=n.x+n.width&&t.height<=n.height/4&&t.y+t.height>=n.y+n.height*.9&&t.y+t.height<=n.y+n.height+.5?[t]:[]});if(o.sort((e,t)=>e.x-t.x),o.length<2||Math.abs(o[0].x-n.x)>.5)return!1;let s=n.x,c=o[0];for(let e of o){if(Math.abs(e.x-s)>.5||Math.abs(e.y-c.y)>.5||Math.abs(e.height-c.height)>.5)return!1;s=e.x+e.width}return Math.abs(s-(n.x+n.width))<=.5}function G(e,t,n){return n.isAdditionalOverlayNode?.(e)===!0&&!K(e,t,n)}function K(e,t,n){let r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(q(r,n))return!0;i.add(r.index),r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return!1}function q(e,t){return t.isAdditionalOverlayNode?.(e)===!0&&Z(e.rect)!==null&&!r(e)}function J(e){return a(e,h)}function Y(e,t,n){return X(e,t,n)||X(t,e,n)}function X(e,t,n){let r=typeof t.parentIndex==`number`?n.get(t.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(r.index===e.index)return!0;i.add(r.index),r=typeof r.parentIndex==`number`?n.get(r.parentIndex):void 0}return!1}function Z(e){let t=c(e);return t&&t.width>0&&t.height>0?t:null}function Q(e){return Array.from(new Set([...e??[],`covered`]))}function $(e,t){let n=Math.min(Math.max(e.y-t.y,0),4);return l(e,{...t,y:t.y+n,height:t.height-n})}export{S as n,w as r,_ as t};