@browserbasehq/orca 3.4.0-preview-5 → 3.5.0-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/lib/inference.d.ts +2 -1
- package/dist/cjs/lib/inference.js +10 -3
- package/dist/cjs/lib/inference.js.map +1 -1
- package/dist/cjs/lib/prompt.d.ts +2 -2
- package/dist/cjs/lib/prompt.js +19 -4
- package/dist/cjs/lib/prompt.js.map +1 -1
- package/dist/cjs/lib/v3/handlers/extractHandler.js +19 -2
- package/dist/cjs/lib/v3/handlers/extractHandler.js.map +1 -1
- package/dist/cjs/lib/v3/index.d.ts +1 -0
- package/dist/cjs/lib/v3/index.js.map +1 -1
- package/dist/cjs/lib/v3/types/private/handlers.d.ts +1 -0
- package/dist/cjs/lib/v3/types/private/handlers.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/api.d.ts +2 -0
- package/dist/cjs/lib/v3/types/public/api.js +4 -0
- package/dist/cjs/lib/v3/types/public/api.js.map +1 -1
- package/dist/cjs/lib/v3/types/public/methods.d.ts +1 -0
- package/dist/cjs/lib/v3/types/public/methods.js.map +1 -1
- package/dist/cjs/lib/v3/v3.js +2 -0
- package/dist/cjs/lib/v3/v3.js.map +1 -1
- package/dist/cjs/lib/v3Evaluator.d.ts +20 -12
- package/dist/cjs/lib/v3Evaluator.js +41 -199
- package/dist/cjs/lib/v3Evaluator.js.map +1 -1
- package/dist/cjs/lib/v3LegacyEvaluator.d.ts +20 -0
- package/dist/cjs/lib/v3LegacyEvaluator.js +215 -0
- package/dist/cjs/lib/v3LegacyEvaluator.js.map +1 -0
- package/dist/esm/lib/inference.d.ts +2 -1
- package/dist/esm/lib/inference.js +10 -3
- package/dist/esm/lib/inference.js.map +1 -1
- package/dist/esm/lib/prompt.d.ts +2 -2
- package/dist/esm/lib/prompt.js +19 -4
- package/dist/esm/lib/prompt.js.map +1 -1
- package/dist/esm/lib/v3/handlers/extractHandler.js +19 -2
- package/dist/esm/lib/v3/handlers/extractHandler.js.map +1 -1
- package/dist/esm/lib/v3/index.d.ts +1 -0
- package/dist/esm/lib/v3/index.js.map +1 -1
- package/dist/esm/lib/v3/types/private/handlers.d.ts +1 -0
- package/dist/esm/lib/v3/types/private/handlers.js.map +1 -1
- package/dist/esm/lib/v3/types/public/api.d.ts +2 -0
- package/dist/esm/lib/v3/types/public/api.js +4 -0
- package/dist/esm/lib/v3/types/public/api.js.map +1 -1
- package/dist/esm/lib/v3/types/public/methods.d.ts +1 -0
- package/dist/esm/lib/v3/types/public/methods.js.map +1 -1
- package/dist/esm/lib/v3/v3.js +2 -0
- package/dist/esm/lib/v3/v3.js.map +1 -1
- package/dist/esm/lib/v3Evaluator.d.ts +20 -12
- package/dist/esm/lib/v3Evaluator.js +41 -199
- package/dist/esm/lib/v3Evaluator.js.map +1 -1
- package/dist/esm/lib/v3LegacyEvaluator.d.ts +20 -0
- package/dist/esm/lib/v3LegacyEvaluator.js +211 -0
- package/dist/esm/lib/v3LegacyEvaluator.js.map +1 -0
- package/package.json +3 -3
- package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.d.ts +0 -24
- package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.js +0 -31
- package/dist/cjs/lib/v3/dom/build/selectorRuntime.generated.js.map +0 -1
- package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.d.ts +0 -24
- package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.js +0 -28
- package/dist/esm/lib/v3/dom/build/selectorRuntime.generated.js.map +0 -1
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare const selectorRuntimeBootstrap = "if (!globalThis.__stagehandSelectorRuntime) { var __stagehandSelectorRuntimeFactory=(()=>{var P=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},C=(t,e,n,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of N(e))!D.call(t,s)&&s!==n&&P(t,s,{get:()=>e[s],enumerable:!(r=A(e,s))||r.enumerable});return t};var k=t=>C(P({},\"__esModule\",{value:!0}),t);var j={};$(j,{countCssWithRoots:()=>B,countTextWithRoots:()=>Y,countXPathNative:()=>U,countXPathWithRoots:()=>K,hasOpenShadowRoots:()=>V,queryCssWithRoots:()=>X,queryTextWithRoots:()=>M,queryXPathNative:()=>Z,queryXPathWithRoots:()=>z});function R(t){let e=String(t||\"\").trim().replace(/^xpath=/i,\"\");if(!e)return[];let n=[],r=0;for(;r<e.length;){let s=\"child\";e.startsWith(\"//\",r)?(s=\"desc\",r+=2):e[r]===\"/\"&&(s=\"child\",r+=1);let o=r,a=0,i=null;for(;r<e.length;){let l=e[r];if(i)l===i&&(i=null);else if(l===\"'\"||l==='\"')i=l;else if(l===\"[\")a++;else if(l===\"]\")a--;else if(l===\"/\"&&a===0)break;r+=1}let u=e.slice(o,r).trim();if(!u)continue;let{tag:c,predicates:f}=W(u);n.push({axis:s,tag:c,predicates:f})}return n}function q(t){let e=[],n=0;for(;n<t.length;){if(t[n]!==\"[\"){n++;continue}n++;let r=n,s=null;for(;n<t.length;){let o=t[n];if(s)o===s&&(s=null);else if(o===\"'\"||o==='\"')s=o;else if(o===\"]\")break;n++}e.push(t.slice(r,n).trim()),n++}return e}function W(t){let e=t.indexOf(\"[\");if(e===-1)return{tag:t===\"\"?\"*\":t.toLowerCase(),predicates:[]};let n=t.slice(0,e).trim(),r=n===\"\"?\"*\":n.toLowerCase(),s=t.slice(e),o=[];for(let a of q(s)){let i=d(a);i&&o.push(i)}return{tag:r,predicates:o}}function d(t){let e=t.trim();if(!e)return null;let n=y(e,\"or\");if(n.length>1){let o=n.map(a=>d(a)).filter(Boolean);return o.length!==n.length?null:{type:\"or\",predicates:o}}let r=y(e,\"and\");if(r.length>1){let o=r.map(a=>d(a)).filter(Boolean);return o.length!==r.length?null:{type:\"and\",predicates:o}}let s=O(e,\"not\");if(s!=null){let o=d(s);return o?{type:\"not\",predicate:o}:null}return _(e)}function _(t){let e=/^(?:'([^']*)'|\"([^\"]*)\")$/,n=\"[a-zA-Z_][\\\\w.-]*\",r=`(?:'([^']*)'|\"([^\"]*)\")`;if(/^\\d+$/.test(t))return{type:\"index\",index:Math.max(1,Number(t))};let s=t.match(new RegExp(`^normalize-space\\\\(\\\\s*@(${n})\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(s)return{type:\"attrEquals\",name:s[1],value:s[2]??s[3]??\"\",normalize:!0};let o=t.match(new RegExp(`^normalize-space\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(o)return{type:\"textEquals\",value:o[1]??o[2]??\"\",normalize:!0};let a=t.match(new RegExp(`^@(${n})\\\\s*=\\\\s*${r}$`));if(a)return{type:\"attrEquals\",name:a[1],value:a[2]??a[3]??\"\"};let i=t.match(new RegExp(`^@(${n})$`));if(i)return{type:\"attrExists\",name:i[1]};let u=t.match(new RegExp(`^contains\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(u)return{type:\"attrContains\",name:u[1],value:u[2]??u[3]??\"\"};let c=t.match(new RegExp(`^starts-with\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(c)return{type:\"attrStartsWith\",name:c[1],value:c[2]??c[3]??\"\"};let f=t.match(new RegExp(`^(?:text\\\\(\\\\)|\\\\.)\\\\s*=\\\\s*${r}$`));if(f)return{type:\"textEquals\",value:f[1]??f[2]??\"\"};let l=t.match(new RegExp(`^contains\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));return l?{type:\"textContains\",value:l[1]??l[2]??\"\"}:(e.test(t),null)}function y(t,e){let n=[],r=0,s=0,o=null,a=0;for(;a<t.length;){let i=t[a];if(o){i===o&&(o=null),a+=1;continue}if(i===\"'\"||i==='\"'){o=i,a+=1;continue}if(i===\"(\"){s+=1,a+=1;continue}if(i===\")\"){s=Math.max(0,s-1),a+=1;continue}if(s===0&&L(t,a,e)){n.push(t.slice(r,a).trim()),a+=e.length,r=a;continue}a+=1}return n.push(t.slice(r).trim()),n.filter(i=>i.length>0)}function L(t,e,n){if(!t.startsWith(n,e))return!1;let r=e>0?t[e-1]:\" \";if(r===\"@\")return!1;let s=e+n.length<t.length?t[e+n.length]:\" \";return S(r)&&S(s)}function S(t){return!/[a-zA-Z0-9_.-]/.test(t)}function O(t,e){let n=`${e}(`;if(!t.startsWith(n)||!t.endsWith(\")\"))return null;let r=t.slice(n.length,-1);return I(r)?r:null}function I(t){let e=0,n=null;for(let r=0;r<t.length;r+=1){let s=t[r];if(n){s===n&&(n=null);continue}if(s===\"'\"||s==='\"'){n=s;continue}if(s===\"(\"?e+=1:s===\")\"&&(e-=1),e<0)return!1}return e===0}var F=t=>t.replace(/\\s+/g,\" \").trim();function b(t){return String(t.textContent??\"\")}function m(t,e){return e?F(t):t}function x(t,e){switch(e.type){case\"and\":return e.predicates.every(n=>x(t,n));case\"or\":return e.predicates.some(n=>x(t,n));case\"not\":return!x(t,e.predicate);case\"attrExists\":return t.getAttribute(e.name)!==null;case\"attrEquals\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize)===m(e.value,e.normalize)}case\"attrContains\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).includes(m(e.value,e.normalize))}case\"attrStartsWith\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).startsWith(m(e.value,e.normalize))}case\"textEquals\":return m(b(t),e.normalize)===m(e.value,e.normalize);case\"textContains\":return m(b(t),e.normalize).includes(m(e.value,e.normalize));case\"index\":return!0;default:return!0}}function v(t,e){let n=t;for(let r of e){if(!n.length)return[];if(r.type===\"index\"){let s=r.index-1;n=s>=0&&s<n.length?[n[s]]:[];continue}n=n.filter(s=>x(s,r))}return n}function w(t){let e=new Map;for(let n=0;n<t.length;n+=2){let r=t[n],s=t[n+1];r instanceof Element&&s instanceof ShadowRoot&&e.set(r,s)}return e}function E(t,e){if(!t)return[];if(t instanceof Document)return t.documentElement?[t.documentElement]:[];if(t instanceof ShadowRoot||t instanceof DocumentFragment)return Array.from(t.children||[]);if(!(t instanceof Element))return[];let n=Array.from(t.children||[]);t.shadowRoot&&n.push(...Array.from(t.shadowRoot.children||[]));let r=e.get(t);return r&&n.push(...Array.from(r.children||[])),n}function H(t,e){let n=[],r=new Set,s=[...E(t,e)].reverse();for(;s.length;){let o=s.pop();if(!(o instanceof Element)||r.has(o))continue;r.add(o),n.push(o);let a=E(o,e);for(let i=a.length-1;i>=0;i-=1)s.push(a[i])}return n}function X(t,e,...n){let r=w(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}function B(t,...e){return X.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function M(t,e,...n){let r=w(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}function Y(t,...e){return M.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function T(t){let e=String(t||\"\").trim();return e?e.replace(/^xpath=/i,\"\").trim():\"\"}function G(t,e){return e.tag===\"*\"?!0:t.localName===e.tag}function z(t,e,...n){let r=w(n),s=R(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):H(c,r)).filter(h=>G(h,a)),g=v(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}function K(t,...e){return z.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function Z(t,e){let n=T(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}function U(t){let e=T(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}function V(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}return k(j);})();\n globalThis.__stagehandSelectorRuntime = __stagehandSelectorRuntimeFactory;\n}";
|
|
2
|
-
export declare const selectorRuntimeSources: {
|
|
3
|
-
readonly countCssWithRoots: "function O(t,...e){return C.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}";
|
|
4
|
-
readonly countTextWithRoots: "function I(t,...e){return k.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}";
|
|
5
|
-
readonly countXPathNative: "function B(t){let e=v(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}";
|
|
6
|
-
readonly countXPathWithRoots: "function F(t,...e){return W.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}";
|
|
7
|
-
readonly hasOpenShadowRoots: "function Y(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}";
|
|
8
|
-
readonly queryCssWithRoots: "function C(t,e,...n){let r=P(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}";
|
|
9
|
-
readonly queryTextWithRoots: "function k(t,e,...n){let r=P(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}";
|
|
10
|
-
readonly queryXPathNative: "function H(t,e){let n=v(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}";
|
|
11
|
-
readonly queryXPathWithRoots: "function W(t,e,...n){let r=P(n),s=b(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):$(c,r)).filter(h=>q(h,a)),g=R(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}";
|
|
12
|
-
};
|
|
13
|
-
export declare const selectorRuntimeGlobalRefs: {
|
|
14
|
-
readonly countCssWithRoots: "globalThis.__stagehandSelectorRuntime.countCssWithRoots";
|
|
15
|
-
readonly countTextWithRoots: "globalThis.__stagehandSelectorRuntime.countTextWithRoots";
|
|
16
|
-
readonly countXPathNative: "globalThis.__stagehandSelectorRuntime.countXPathNative";
|
|
17
|
-
readonly countXPathWithRoots: "globalThis.__stagehandSelectorRuntime.countXPathWithRoots";
|
|
18
|
-
readonly hasOpenShadowRoots: "globalThis.__stagehandSelectorRuntime.hasOpenShadowRoots";
|
|
19
|
-
readonly queryCssWithRoots: "globalThis.__stagehandSelectorRuntime.queryCssWithRoots";
|
|
20
|
-
readonly queryTextWithRoots: "globalThis.__stagehandSelectorRuntime.queryTextWithRoots";
|
|
21
|
-
readonly queryXPathNative: "globalThis.__stagehandSelectorRuntime.queryXPathNative";
|
|
22
|
-
readonly queryXPathWithRoots: "globalThis.__stagehandSelectorRuntime.queryXPathWithRoots";
|
|
23
|
-
};
|
|
24
|
-
export type SelectorRuntimeName = keyof typeof selectorRuntimeSources;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.selectorRuntimeGlobalRefs = exports.selectorRuntimeSources = exports.selectorRuntimeBootstrap = void 0;
|
|
4
|
-
/*
|
|
5
|
-
* AUTO-GENERATED FILE. DO NOT EDIT.
|
|
6
|
-
* Run `pnpm run build-dom-scripts` to regenerate.
|
|
7
|
-
*/
|
|
8
|
-
exports.selectorRuntimeBootstrap = "if (!globalThis.__stagehandSelectorRuntime) { var __stagehandSelectorRuntimeFactory=(()=>{var P=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},C=(t,e,n,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of N(e))!D.call(t,s)&&s!==n&&P(t,s,{get:()=>e[s],enumerable:!(r=A(e,s))||r.enumerable});return t};var k=t=>C(P({},\"__esModule\",{value:!0}),t);var j={};$(j,{countCssWithRoots:()=>B,countTextWithRoots:()=>Y,countXPathNative:()=>U,countXPathWithRoots:()=>K,hasOpenShadowRoots:()=>V,queryCssWithRoots:()=>X,queryTextWithRoots:()=>M,queryXPathNative:()=>Z,queryXPathWithRoots:()=>z});function R(t){let e=String(t||\"\").trim().replace(/^xpath=/i,\"\");if(!e)return[];let n=[],r=0;for(;r<e.length;){let s=\"child\";e.startsWith(\"//\",r)?(s=\"desc\",r+=2):e[r]===\"/\"&&(s=\"child\",r+=1);let o=r,a=0,i=null;for(;r<e.length;){let l=e[r];if(i)l===i&&(i=null);else if(l===\"'\"||l==='\"')i=l;else if(l===\"[\")a++;else if(l===\"]\")a--;else if(l===\"/\"&&a===0)break;r+=1}let u=e.slice(o,r).trim();if(!u)continue;let{tag:c,predicates:f}=W(u);n.push({axis:s,tag:c,predicates:f})}return n}function q(t){let e=[],n=0;for(;n<t.length;){if(t[n]!==\"[\"){n++;continue}n++;let r=n,s=null;for(;n<t.length;){let o=t[n];if(s)o===s&&(s=null);else if(o===\"'\"||o==='\"')s=o;else if(o===\"]\")break;n++}e.push(t.slice(r,n).trim()),n++}return e}function W(t){let e=t.indexOf(\"[\");if(e===-1)return{tag:t===\"\"?\"*\":t.toLowerCase(),predicates:[]};let n=t.slice(0,e).trim(),r=n===\"\"?\"*\":n.toLowerCase(),s=t.slice(e),o=[];for(let a of q(s)){let i=d(a);i&&o.push(i)}return{tag:r,predicates:o}}function d(t){let e=t.trim();if(!e)return null;let n=y(e,\"or\");if(n.length>1){let o=n.map(a=>d(a)).filter(Boolean);return o.length!==n.length?null:{type:\"or\",predicates:o}}let r=y(e,\"and\");if(r.length>1){let o=r.map(a=>d(a)).filter(Boolean);return o.length!==r.length?null:{type:\"and\",predicates:o}}let s=O(e,\"not\");if(s!=null){let o=d(s);return o?{type:\"not\",predicate:o}:null}return _(e)}function _(t){let e=/^(?:'([^']*)'|\"([^\"]*)\")$/,n=\"[a-zA-Z_][\\\\w.-]*\",r=`(?:'([^']*)'|\"([^\"]*)\")`;if(/^\\d+$/.test(t))return{type:\"index\",index:Math.max(1,Number(t))};let s=t.match(new RegExp(`^normalize-space\\\\(\\\\s*@(${n})\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(s)return{type:\"attrEquals\",name:s[1],value:s[2]??s[3]??\"\",normalize:!0};let o=t.match(new RegExp(`^normalize-space\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(o)return{type:\"textEquals\",value:o[1]??o[2]??\"\",normalize:!0};let a=t.match(new RegExp(`^@(${n})\\\\s*=\\\\s*${r}$`));if(a)return{type:\"attrEquals\",name:a[1],value:a[2]??a[3]??\"\"};let i=t.match(new RegExp(`^@(${n})$`));if(i)return{type:\"attrExists\",name:i[1]};let u=t.match(new RegExp(`^contains\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(u)return{type:\"attrContains\",name:u[1],value:u[2]??u[3]??\"\"};let c=t.match(new RegExp(`^starts-with\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(c)return{type:\"attrStartsWith\",name:c[1],value:c[2]??c[3]??\"\"};let f=t.match(new RegExp(`^(?:text\\\\(\\\\)|\\\\.)\\\\s*=\\\\s*${r}$`));if(f)return{type:\"textEquals\",value:f[1]??f[2]??\"\"};let l=t.match(new RegExp(`^contains\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));return l?{type:\"textContains\",value:l[1]??l[2]??\"\"}:(e.test(t),null)}function y(t,e){let n=[],r=0,s=0,o=null,a=0;for(;a<t.length;){let i=t[a];if(o){i===o&&(o=null),a+=1;continue}if(i===\"'\"||i==='\"'){o=i,a+=1;continue}if(i===\"(\"){s+=1,a+=1;continue}if(i===\")\"){s=Math.max(0,s-1),a+=1;continue}if(s===0&&L(t,a,e)){n.push(t.slice(r,a).trim()),a+=e.length,r=a;continue}a+=1}return n.push(t.slice(r).trim()),n.filter(i=>i.length>0)}function L(t,e,n){if(!t.startsWith(n,e))return!1;let r=e>0?t[e-1]:\" \";if(r===\"@\")return!1;let s=e+n.length<t.length?t[e+n.length]:\" \";return S(r)&&S(s)}function S(t){return!/[a-zA-Z0-9_.-]/.test(t)}function O(t,e){let n=`${e}(`;if(!t.startsWith(n)||!t.endsWith(\")\"))return null;let r=t.slice(n.length,-1);return I(r)?r:null}function I(t){let e=0,n=null;for(let r=0;r<t.length;r+=1){let s=t[r];if(n){s===n&&(n=null);continue}if(s===\"'\"||s==='\"'){n=s;continue}if(s===\"(\"?e+=1:s===\")\"&&(e-=1),e<0)return!1}return e===0}var F=t=>t.replace(/\\s+/g,\" \").trim();function b(t){return String(t.textContent??\"\")}function m(t,e){return e?F(t):t}function x(t,e){switch(e.type){case\"and\":return e.predicates.every(n=>x(t,n));case\"or\":return e.predicates.some(n=>x(t,n));case\"not\":return!x(t,e.predicate);case\"attrExists\":return t.getAttribute(e.name)!==null;case\"attrEquals\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize)===m(e.value,e.normalize)}case\"attrContains\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).includes(m(e.value,e.normalize))}case\"attrStartsWith\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).startsWith(m(e.value,e.normalize))}case\"textEquals\":return m(b(t),e.normalize)===m(e.value,e.normalize);case\"textContains\":return m(b(t),e.normalize).includes(m(e.value,e.normalize));case\"index\":return!0;default:return!0}}function v(t,e){let n=t;for(let r of e){if(!n.length)return[];if(r.type===\"index\"){let s=r.index-1;n=s>=0&&s<n.length?[n[s]]:[];continue}n=n.filter(s=>x(s,r))}return n}function w(t){let e=new Map;for(let n=0;n<t.length;n+=2){let r=t[n],s=t[n+1];r instanceof Element&&s instanceof ShadowRoot&&e.set(r,s)}return e}function E(t,e){if(!t)return[];if(t instanceof Document)return t.documentElement?[t.documentElement]:[];if(t instanceof ShadowRoot||t instanceof DocumentFragment)return Array.from(t.children||[]);if(!(t instanceof Element))return[];let n=Array.from(t.children||[]);t.shadowRoot&&n.push(...Array.from(t.shadowRoot.children||[]));let r=e.get(t);return r&&n.push(...Array.from(r.children||[])),n}function H(t,e){let n=[],r=new Set,s=[...E(t,e)].reverse();for(;s.length;){let o=s.pop();if(!(o instanceof Element)||r.has(o))continue;r.add(o),n.push(o);let a=E(o,e);for(let i=a.length-1;i>=0;i-=1)s.push(a[i])}return n}function X(t,e,...n){let r=w(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}function B(t,...e){return X.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function M(t,e,...n){let r=w(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}function Y(t,...e){return M.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function T(t){let e=String(t||\"\").trim();return e?e.replace(/^xpath=/i,\"\").trim():\"\"}function G(t,e){return e.tag===\"*\"?!0:t.localName===e.tag}function z(t,e,...n){let r=w(n),s=R(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):H(c,r)).filter(h=>G(h,a)),g=v(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}function K(t,...e){return z.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function Z(t,e){let n=T(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}function U(t){let e=T(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}function V(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}return k(j);})();\n globalThis.__stagehandSelectorRuntime = __stagehandSelectorRuntimeFactory;\n}";
|
|
9
|
-
exports.selectorRuntimeSources = {
|
|
10
|
-
"countCssWithRoots": "function O(t,...e){return C.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
|
|
11
|
-
"countTextWithRoots": "function I(t,...e){return k.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
|
|
12
|
-
"countXPathNative": "function B(t){let e=v(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}",
|
|
13
|
-
"countXPathWithRoots": "function F(t,...e){return W.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
|
|
14
|
-
"hasOpenShadowRoots": "function Y(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}",
|
|
15
|
-
"queryCssWithRoots": "function C(t,e,...n){let r=P(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}",
|
|
16
|
-
"queryTextWithRoots": "function k(t,e,...n){let r=P(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}",
|
|
17
|
-
"queryXPathNative": "function H(t,e){let n=v(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}",
|
|
18
|
-
"queryXPathWithRoots": "function W(t,e,...n){let r=P(n),s=b(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):$(c,r)).filter(h=>q(h,a)),g=R(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}"
|
|
19
|
-
};
|
|
20
|
-
exports.selectorRuntimeGlobalRefs = {
|
|
21
|
-
"countCssWithRoots": "globalThis.__stagehandSelectorRuntime.countCssWithRoots",
|
|
22
|
-
"countTextWithRoots": "globalThis.__stagehandSelectorRuntime.countTextWithRoots",
|
|
23
|
-
"countXPathNative": "globalThis.__stagehandSelectorRuntime.countXPathNative",
|
|
24
|
-
"countXPathWithRoots": "globalThis.__stagehandSelectorRuntime.countXPathWithRoots",
|
|
25
|
-
"hasOpenShadowRoots": "globalThis.__stagehandSelectorRuntime.hasOpenShadowRoots",
|
|
26
|
-
"queryCssWithRoots": "globalThis.__stagehandSelectorRuntime.queryCssWithRoots",
|
|
27
|
-
"queryTextWithRoots": "globalThis.__stagehandSelectorRuntime.queryTextWithRoots",
|
|
28
|
-
"queryXPathNative": "globalThis.__stagehandSelectorRuntime.queryXPathNative",
|
|
29
|
-
"queryXPathWithRoots": "globalThis.__stagehandSelectorRuntime.queryXPathWithRoots"
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=selectorRuntime.generated.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectorRuntime.generated.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/selectorRuntime.generated.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,wBAAwB,GAAG,0oRAA0oR,CAAC;AACtqR,QAAA,sBAAsB,GAAG;IACpC,mBAAmB,EAAE,+EAA+E;IACpG,oBAAoB,EAAE,+EAA+E;IACrG,kBAAkB,EAAE,wOAAwO;IAC5P,qBAAqB,EAAE,+EAA+E;IACtG,oBAAoB,EAAE,6LAA6L;IACnN,mBAAmB,EAAE,iTAAiT;IACtU,oBAAoB,EAAE,8xBAA8xB;IACpzB,kBAAkB,EAAE,+SAA+S;IACnU,qBAAqB,EAAE,mVAAmV;CAClW,CAAC;AACE,QAAA,yBAAyB,GAAG;IACvC,mBAAmB,EAAE,yDAAyD;IAC9E,oBAAoB,EAAE,0DAA0D;IAChF,kBAAkB,EAAE,wDAAwD;IAC5E,qBAAqB,EAAE,2DAA2D;IAClF,oBAAoB,EAAE,0DAA0D;IAChF,mBAAmB,EAAE,yDAAyD;IAC9E,oBAAoB,EAAE,0DAA0D;IAChF,kBAAkB,EAAE,wDAAwD;IAC5E,qBAAqB,EAAE,2DAA2D;CAC1E,CAAC","sourcesContent":["/*\n * AUTO-GENERATED FILE. DO NOT EDIT.\n * Run `pnpm run build-dom-scripts` to regenerate.\n */\nexport const selectorRuntimeBootstrap = \"if (!globalThis.__stagehandSelectorRuntime) { var __stagehandSelectorRuntimeFactory=(()=>{var P=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},C=(t,e,n,r)=>{if(e&&typeof e==\\\"object\\\"||typeof e==\\\"function\\\")for(let s of N(e))!D.call(t,s)&&s!==n&&P(t,s,{get:()=>e[s],enumerable:!(r=A(e,s))||r.enumerable});return t};var k=t=>C(P({},\\\"__esModule\\\",{value:!0}),t);var j={};$(j,{countCssWithRoots:()=>B,countTextWithRoots:()=>Y,countXPathNative:()=>U,countXPathWithRoots:()=>K,hasOpenShadowRoots:()=>V,queryCssWithRoots:()=>X,queryTextWithRoots:()=>M,queryXPathNative:()=>Z,queryXPathWithRoots:()=>z});function R(t){let e=String(t||\\\"\\\").trim().replace(/^xpath=/i,\\\"\\\");if(!e)return[];let n=[],r=0;for(;r<e.length;){let s=\\\"child\\\";e.startsWith(\\\"//\\\",r)?(s=\\\"desc\\\",r+=2):e[r]===\\\"/\\\"&&(s=\\\"child\\\",r+=1);let o=r,a=0,i=null;for(;r<e.length;){let l=e[r];if(i)l===i&&(i=null);else if(l===\\\"'\\\"||l==='\\\"')i=l;else if(l===\\\"[\\\")a++;else if(l===\\\"]\\\")a--;else if(l===\\\"/\\\"&&a===0)break;r+=1}let u=e.slice(o,r).trim();if(!u)continue;let{tag:c,predicates:f}=W(u);n.push({axis:s,tag:c,predicates:f})}return n}function q(t){let e=[],n=0;for(;n<t.length;){if(t[n]!==\\\"[\\\"){n++;continue}n++;let r=n,s=null;for(;n<t.length;){let o=t[n];if(s)o===s&&(s=null);else if(o===\\\"'\\\"||o==='\\\"')s=o;else if(o===\\\"]\\\")break;n++}e.push(t.slice(r,n).trim()),n++}return e}function W(t){let e=t.indexOf(\\\"[\\\");if(e===-1)return{tag:t===\\\"\\\"?\\\"*\\\":t.toLowerCase(),predicates:[]};let n=t.slice(0,e).trim(),r=n===\\\"\\\"?\\\"*\\\":n.toLowerCase(),s=t.slice(e),o=[];for(let a of q(s)){let i=d(a);i&&o.push(i)}return{tag:r,predicates:o}}function d(t){let e=t.trim();if(!e)return null;let n=y(e,\\\"or\\\");if(n.length>1){let o=n.map(a=>d(a)).filter(Boolean);return o.length!==n.length?null:{type:\\\"or\\\",predicates:o}}let r=y(e,\\\"and\\\");if(r.length>1){let o=r.map(a=>d(a)).filter(Boolean);return o.length!==r.length?null:{type:\\\"and\\\",predicates:o}}let s=O(e,\\\"not\\\");if(s!=null){let o=d(s);return o?{type:\\\"not\\\",predicate:o}:null}return _(e)}function _(t){let e=/^(?:'([^']*)'|\\\"([^\\\"]*)\\\")$/,n=\\\"[a-zA-Z_][\\\\\\\\w.-]*\\\",r=`(?:'([^']*)'|\\\"([^\\\"]*)\\\")`;if(/^\\\\d+$/.test(t))return{type:\\\"index\\\",index:Math.max(1,Number(t))};let s=t.match(new RegExp(`^normalize-space\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*\\\\\\\\)\\\\\\\\s*=\\\\\\\\s*${r}$`));if(s)return{type:\\\"attrEquals\\\",name:s[1],value:s[2]??s[3]??\\\"\\\",normalize:!0};let o=t.match(new RegExp(`^normalize-space\\\\\\\\(\\\\\\\\s*(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*\\\\\\\\)\\\\\\\\s*=\\\\\\\\s*${r}$`));if(o)return{type:\\\"textEquals\\\",value:o[1]??o[2]??\\\"\\\",normalize:!0};let a=t.match(new RegExp(`^@(${n})\\\\\\\\s*=\\\\\\\\s*${r}$`));if(a)return{type:\\\"attrEquals\\\",name:a[1],value:a[2]??a[3]??\\\"\\\"};let i=t.match(new RegExp(`^@(${n})$`));if(i)return{type:\\\"attrExists\\\",name:i[1]};let u=t.match(new RegExp(`^contains\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*,\\\\\\\\s*${r}\\\\\\\\s*\\\\\\\\)$`));if(u)return{type:\\\"attrContains\\\",name:u[1],value:u[2]??u[3]??\\\"\\\"};let c=t.match(new RegExp(`^starts-with\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*,\\\\\\\\s*${r}\\\\\\\\s*\\\\\\\\)$`));if(c)return{type:\\\"attrStartsWith\\\",name:c[1],value:c[2]??c[3]??\\\"\\\"};let f=t.match(new RegExp(`^(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*=\\\\\\\\s*${r}$`));if(f)return{type:\\\"textEquals\\\",value:f[1]??f[2]??\\\"\\\"};let l=t.match(new RegExp(`^contains\\\\\\\\(\\\\\\\\s*(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*,\\\\\\\\s*${r}\\\\\\\\s*\\\\\\\\)$`));return l?{type:\\\"textContains\\\",value:l[1]??l[2]??\\\"\\\"}:(e.test(t),null)}function y(t,e){let n=[],r=0,s=0,o=null,a=0;for(;a<t.length;){let i=t[a];if(o){i===o&&(o=null),a+=1;continue}if(i===\\\"'\\\"||i==='\\\"'){o=i,a+=1;continue}if(i===\\\"(\\\"){s+=1,a+=1;continue}if(i===\\\")\\\"){s=Math.max(0,s-1),a+=1;continue}if(s===0&&L(t,a,e)){n.push(t.slice(r,a).trim()),a+=e.length,r=a;continue}a+=1}return n.push(t.slice(r).trim()),n.filter(i=>i.length>0)}function L(t,e,n){if(!t.startsWith(n,e))return!1;let r=e>0?t[e-1]:\\\" \\\";if(r===\\\"@\\\")return!1;let s=e+n.length<t.length?t[e+n.length]:\\\" \\\";return S(r)&&S(s)}function S(t){return!/[a-zA-Z0-9_.-]/.test(t)}function O(t,e){let n=`${e}(`;if(!t.startsWith(n)||!t.endsWith(\\\")\\\"))return null;let r=t.slice(n.length,-1);return I(r)?r:null}function I(t){let e=0,n=null;for(let r=0;r<t.length;r+=1){let s=t[r];if(n){s===n&&(n=null);continue}if(s===\\\"'\\\"||s==='\\\"'){n=s;continue}if(s===\\\"(\\\"?e+=1:s===\\\")\\\"&&(e-=1),e<0)return!1}return e===0}var F=t=>t.replace(/\\\\s+/g,\\\" \\\").trim();function b(t){return String(t.textContent??\\\"\\\")}function m(t,e){return e?F(t):t}function x(t,e){switch(e.type){case\\\"and\\\":return e.predicates.every(n=>x(t,n));case\\\"or\\\":return e.predicates.some(n=>x(t,n));case\\\"not\\\":return!x(t,e.predicate);case\\\"attrExists\\\":return t.getAttribute(e.name)!==null;case\\\"attrEquals\\\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize)===m(e.value,e.normalize)}case\\\"attrContains\\\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).includes(m(e.value,e.normalize))}case\\\"attrStartsWith\\\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).startsWith(m(e.value,e.normalize))}case\\\"textEquals\\\":return m(b(t),e.normalize)===m(e.value,e.normalize);case\\\"textContains\\\":return m(b(t),e.normalize).includes(m(e.value,e.normalize));case\\\"index\\\":return!0;default:return!0}}function v(t,e){let n=t;for(let r of e){if(!n.length)return[];if(r.type===\\\"index\\\"){let s=r.index-1;n=s>=0&&s<n.length?[n[s]]:[];continue}n=n.filter(s=>x(s,r))}return n}function w(t){let e=new Map;for(let n=0;n<t.length;n+=2){let r=t[n],s=t[n+1];r instanceof Element&&s instanceof ShadowRoot&&e.set(r,s)}return e}function E(t,e){if(!t)return[];if(t instanceof Document)return t.documentElement?[t.documentElement]:[];if(t instanceof ShadowRoot||t instanceof DocumentFragment)return Array.from(t.children||[]);if(!(t instanceof Element))return[];let n=Array.from(t.children||[]);t.shadowRoot&&n.push(...Array.from(t.shadowRoot.children||[]));let r=e.get(t);return r&&n.push(...Array.from(r.children||[])),n}function H(t,e){let n=[],r=new Set,s=[...E(t,e)].reverse();for(;s.length;){let o=s.pop();if(!(o instanceof Element)||r.has(o))continue;r.add(o),n.push(o);let a=E(o,e);for(let i=a.length-1;i>=0;i-=1)s.push(a[i])}return n}function X(t,e,...n){let r=w(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}function B(t,...e){return X.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function M(t,e,...n){let r=w(n),s=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),o=String(t||\\\"\\\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\\\"\\\";if(s.has(g))return\\\"\\\";try{let p=l.innerText;if(typeof p==\\\"string\\\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\\\"string\\\"?h.trim():\\\"\\\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}function Y(t,...e){return M.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function T(t){let e=String(t||\\\"\\\").trim();return e?e.replace(/^xpath=/i,\\\"\\\").trim():\\\"\\\"}function G(t,e){return e.tag===\\\"*\\\"?!0:t.localName===e.tag}function z(t,e,...n){let r=w(n),s=R(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\\\"child\\\"?E(c,r):H(c,r)).filter(h=>G(h,a)),g=v(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}function K(t,...e){return z.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function Z(t,e){let n=T(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}function U(t){let e=T(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}function V(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}return k(j);})();\\n globalThis.__stagehandSelectorRuntime = __stagehandSelectorRuntimeFactory;\\n}\";\nexport const selectorRuntimeSources = {\n \"countCssWithRoots\": \"function O(t,...e){return C.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}\",\n \"countTextWithRoots\": \"function I(t,...e){return k.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}\",\n \"countXPathNative\": \"function B(t){let e=v(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}\",\n \"countXPathWithRoots\": \"function F(t,...e){return W.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}\",\n \"hasOpenShadowRoots\": \"function Y(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}\",\n \"queryCssWithRoots\": \"function C(t,e,...n){let r=P(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}\",\n \"queryTextWithRoots\": \"function k(t,e,...n){let r=P(n),s=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),o=String(t||\\\"\\\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\\\"\\\";if(s.has(g))return\\\"\\\";try{let p=l.innerText;if(typeof p==\\\"string\\\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\\\"string\\\"?h.trim():\\\"\\\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}\",\n \"queryXPathNative\": \"function H(t,e){let n=v(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}\",\n \"queryXPathWithRoots\": \"function W(t,e,...n){let r=P(n),s=b(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\\\"child\\\"?E(c,r):$(c,r)).filter(h=>q(h,a)),g=R(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}\"\n} as const;\nexport const selectorRuntimeGlobalRefs = {\n \"countCssWithRoots\": \"globalThis.__stagehandSelectorRuntime.countCssWithRoots\",\n \"countTextWithRoots\": \"globalThis.__stagehandSelectorRuntime.countTextWithRoots\",\n \"countXPathNative\": \"globalThis.__stagehandSelectorRuntime.countXPathNative\",\n \"countXPathWithRoots\": \"globalThis.__stagehandSelectorRuntime.countXPathWithRoots\",\n \"hasOpenShadowRoots\": \"globalThis.__stagehandSelectorRuntime.hasOpenShadowRoots\",\n \"queryCssWithRoots\": \"globalThis.__stagehandSelectorRuntime.queryCssWithRoots\",\n \"queryTextWithRoots\": \"globalThis.__stagehandSelectorRuntime.queryTextWithRoots\",\n \"queryXPathNative\": \"globalThis.__stagehandSelectorRuntime.queryXPathNative\",\n \"queryXPathWithRoots\": \"globalThis.__stagehandSelectorRuntime.queryXPathWithRoots\"\n} as const;\nexport type SelectorRuntimeName = keyof typeof selectorRuntimeSources;\n"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare const selectorRuntimeBootstrap = "if (!globalThis.__stagehandSelectorRuntime) { var __stagehandSelectorRuntimeFactory=(()=>{var P=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},C=(t,e,n,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of N(e))!D.call(t,s)&&s!==n&&P(t,s,{get:()=>e[s],enumerable:!(r=A(e,s))||r.enumerable});return t};var k=t=>C(P({},\"__esModule\",{value:!0}),t);var j={};$(j,{countCssWithRoots:()=>B,countTextWithRoots:()=>Y,countXPathNative:()=>U,countXPathWithRoots:()=>K,hasOpenShadowRoots:()=>V,queryCssWithRoots:()=>X,queryTextWithRoots:()=>M,queryXPathNative:()=>Z,queryXPathWithRoots:()=>z});function R(t){let e=String(t||\"\").trim().replace(/^xpath=/i,\"\");if(!e)return[];let n=[],r=0;for(;r<e.length;){let s=\"child\";e.startsWith(\"//\",r)?(s=\"desc\",r+=2):e[r]===\"/\"&&(s=\"child\",r+=1);let o=r,a=0,i=null;for(;r<e.length;){let l=e[r];if(i)l===i&&(i=null);else if(l===\"'\"||l==='\"')i=l;else if(l===\"[\")a++;else if(l===\"]\")a--;else if(l===\"/\"&&a===0)break;r+=1}let u=e.slice(o,r).trim();if(!u)continue;let{tag:c,predicates:f}=W(u);n.push({axis:s,tag:c,predicates:f})}return n}function q(t){let e=[],n=0;for(;n<t.length;){if(t[n]!==\"[\"){n++;continue}n++;let r=n,s=null;for(;n<t.length;){let o=t[n];if(s)o===s&&(s=null);else if(o===\"'\"||o==='\"')s=o;else if(o===\"]\")break;n++}e.push(t.slice(r,n).trim()),n++}return e}function W(t){let e=t.indexOf(\"[\");if(e===-1)return{tag:t===\"\"?\"*\":t.toLowerCase(),predicates:[]};let n=t.slice(0,e).trim(),r=n===\"\"?\"*\":n.toLowerCase(),s=t.slice(e),o=[];for(let a of q(s)){let i=d(a);i&&o.push(i)}return{tag:r,predicates:o}}function d(t){let e=t.trim();if(!e)return null;let n=y(e,\"or\");if(n.length>1){let o=n.map(a=>d(a)).filter(Boolean);return o.length!==n.length?null:{type:\"or\",predicates:o}}let r=y(e,\"and\");if(r.length>1){let o=r.map(a=>d(a)).filter(Boolean);return o.length!==r.length?null:{type:\"and\",predicates:o}}let s=O(e,\"not\");if(s!=null){let o=d(s);return o?{type:\"not\",predicate:o}:null}return _(e)}function _(t){let e=/^(?:'([^']*)'|\"([^\"]*)\")$/,n=\"[a-zA-Z_][\\\\w.-]*\",r=`(?:'([^']*)'|\"([^\"]*)\")`;if(/^\\d+$/.test(t))return{type:\"index\",index:Math.max(1,Number(t))};let s=t.match(new RegExp(`^normalize-space\\\\(\\\\s*@(${n})\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(s)return{type:\"attrEquals\",name:s[1],value:s[2]??s[3]??\"\",normalize:!0};let o=t.match(new RegExp(`^normalize-space\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(o)return{type:\"textEquals\",value:o[1]??o[2]??\"\",normalize:!0};let a=t.match(new RegExp(`^@(${n})\\\\s*=\\\\s*${r}$`));if(a)return{type:\"attrEquals\",name:a[1],value:a[2]??a[3]??\"\"};let i=t.match(new RegExp(`^@(${n})$`));if(i)return{type:\"attrExists\",name:i[1]};let u=t.match(new RegExp(`^contains\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(u)return{type:\"attrContains\",name:u[1],value:u[2]??u[3]??\"\"};let c=t.match(new RegExp(`^starts-with\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(c)return{type:\"attrStartsWith\",name:c[1],value:c[2]??c[3]??\"\"};let f=t.match(new RegExp(`^(?:text\\\\(\\\\)|\\\\.)\\\\s*=\\\\s*${r}$`));if(f)return{type:\"textEquals\",value:f[1]??f[2]??\"\"};let l=t.match(new RegExp(`^contains\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));return l?{type:\"textContains\",value:l[1]??l[2]??\"\"}:(e.test(t),null)}function y(t,e){let n=[],r=0,s=0,o=null,a=0;for(;a<t.length;){let i=t[a];if(o){i===o&&(o=null),a+=1;continue}if(i===\"'\"||i==='\"'){o=i,a+=1;continue}if(i===\"(\"){s+=1,a+=1;continue}if(i===\")\"){s=Math.max(0,s-1),a+=1;continue}if(s===0&&L(t,a,e)){n.push(t.slice(r,a).trim()),a+=e.length,r=a;continue}a+=1}return n.push(t.slice(r).trim()),n.filter(i=>i.length>0)}function L(t,e,n){if(!t.startsWith(n,e))return!1;let r=e>0?t[e-1]:\" \";if(r===\"@\")return!1;let s=e+n.length<t.length?t[e+n.length]:\" \";return S(r)&&S(s)}function S(t){return!/[a-zA-Z0-9_.-]/.test(t)}function O(t,e){let n=`${e}(`;if(!t.startsWith(n)||!t.endsWith(\")\"))return null;let r=t.slice(n.length,-1);return I(r)?r:null}function I(t){let e=0,n=null;for(let r=0;r<t.length;r+=1){let s=t[r];if(n){s===n&&(n=null);continue}if(s===\"'\"||s==='\"'){n=s;continue}if(s===\"(\"?e+=1:s===\")\"&&(e-=1),e<0)return!1}return e===0}var F=t=>t.replace(/\\s+/g,\" \").trim();function b(t){return String(t.textContent??\"\")}function m(t,e){return e?F(t):t}function x(t,e){switch(e.type){case\"and\":return e.predicates.every(n=>x(t,n));case\"or\":return e.predicates.some(n=>x(t,n));case\"not\":return!x(t,e.predicate);case\"attrExists\":return t.getAttribute(e.name)!==null;case\"attrEquals\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize)===m(e.value,e.normalize)}case\"attrContains\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).includes(m(e.value,e.normalize))}case\"attrStartsWith\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).startsWith(m(e.value,e.normalize))}case\"textEquals\":return m(b(t),e.normalize)===m(e.value,e.normalize);case\"textContains\":return m(b(t),e.normalize).includes(m(e.value,e.normalize));case\"index\":return!0;default:return!0}}function v(t,e){let n=t;for(let r of e){if(!n.length)return[];if(r.type===\"index\"){let s=r.index-1;n=s>=0&&s<n.length?[n[s]]:[];continue}n=n.filter(s=>x(s,r))}return n}function w(t){let e=new Map;for(let n=0;n<t.length;n+=2){let r=t[n],s=t[n+1];r instanceof Element&&s instanceof ShadowRoot&&e.set(r,s)}return e}function E(t,e){if(!t)return[];if(t instanceof Document)return t.documentElement?[t.documentElement]:[];if(t instanceof ShadowRoot||t instanceof DocumentFragment)return Array.from(t.children||[]);if(!(t instanceof Element))return[];let n=Array.from(t.children||[]);t.shadowRoot&&n.push(...Array.from(t.shadowRoot.children||[]));let r=e.get(t);return r&&n.push(...Array.from(r.children||[])),n}function H(t,e){let n=[],r=new Set,s=[...E(t,e)].reverse();for(;s.length;){let o=s.pop();if(!(o instanceof Element)||r.has(o))continue;r.add(o),n.push(o);let a=E(o,e);for(let i=a.length-1;i>=0;i-=1)s.push(a[i])}return n}function X(t,e,...n){let r=w(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}function B(t,...e){return X.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function M(t,e,...n){let r=w(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}function Y(t,...e){return M.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function T(t){let e=String(t||\"\").trim();return e?e.replace(/^xpath=/i,\"\").trim():\"\"}function G(t,e){return e.tag===\"*\"?!0:t.localName===e.tag}function z(t,e,...n){let r=w(n),s=R(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):H(c,r)).filter(h=>G(h,a)),g=v(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}function K(t,...e){return z.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function Z(t,e){let n=T(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}function U(t){let e=T(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}function V(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}return k(j);})();\n globalThis.__stagehandSelectorRuntime = __stagehandSelectorRuntimeFactory;\n}";
|
|
2
|
-
export declare const selectorRuntimeSources: {
|
|
3
|
-
readonly countCssWithRoots: "function O(t,...e){return C.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}";
|
|
4
|
-
readonly countTextWithRoots: "function I(t,...e){return k.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}";
|
|
5
|
-
readonly countXPathNative: "function B(t){let e=v(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}";
|
|
6
|
-
readonly countXPathWithRoots: "function F(t,...e){return W.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}";
|
|
7
|
-
readonly hasOpenShadowRoots: "function Y(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}";
|
|
8
|
-
readonly queryCssWithRoots: "function C(t,e,...n){let r=P(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}";
|
|
9
|
-
readonly queryTextWithRoots: "function k(t,e,...n){let r=P(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}";
|
|
10
|
-
readonly queryXPathNative: "function H(t,e){let n=v(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}";
|
|
11
|
-
readonly queryXPathWithRoots: "function W(t,e,...n){let r=P(n),s=b(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):$(c,r)).filter(h=>q(h,a)),g=R(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}";
|
|
12
|
-
};
|
|
13
|
-
export declare const selectorRuntimeGlobalRefs: {
|
|
14
|
-
readonly countCssWithRoots: "globalThis.__stagehandSelectorRuntime.countCssWithRoots";
|
|
15
|
-
readonly countTextWithRoots: "globalThis.__stagehandSelectorRuntime.countTextWithRoots";
|
|
16
|
-
readonly countXPathNative: "globalThis.__stagehandSelectorRuntime.countXPathNative";
|
|
17
|
-
readonly countXPathWithRoots: "globalThis.__stagehandSelectorRuntime.countXPathWithRoots";
|
|
18
|
-
readonly hasOpenShadowRoots: "globalThis.__stagehandSelectorRuntime.hasOpenShadowRoots";
|
|
19
|
-
readonly queryCssWithRoots: "globalThis.__stagehandSelectorRuntime.queryCssWithRoots";
|
|
20
|
-
readonly queryTextWithRoots: "globalThis.__stagehandSelectorRuntime.queryTextWithRoots";
|
|
21
|
-
readonly queryXPathNative: "globalThis.__stagehandSelectorRuntime.queryXPathNative";
|
|
22
|
-
readonly queryXPathWithRoots: "globalThis.__stagehandSelectorRuntime.queryXPathWithRoots";
|
|
23
|
-
};
|
|
24
|
-
export type SelectorRuntimeName = keyof typeof selectorRuntimeSources;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* AUTO-GENERATED FILE. DO NOT EDIT.
|
|
3
|
-
* Run `pnpm run build-dom-scripts` to regenerate.
|
|
4
|
-
*/
|
|
5
|
-
export const selectorRuntimeBootstrap = "if (!globalThis.__stagehandSelectorRuntime) { var __stagehandSelectorRuntimeFactory=(()=>{var P=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},C=(t,e,n,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of N(e))!D.call(t,s)&&s!==n&&P(t,s,{get:()=>e[s],enumerable:!(r=A(e,s))||r.enumerable});return t};var k=t=>C(P({},\"__esModule\",{value:!0}),t);var j={};$(j,{countCssWithRoots:()=>B,countTextWithRoots:()=>Y,countXPathNative:()=>U,countXPathWithRoots:()=>K,hasOpenShadowRoots:()=>V,queryCssWithRoots:()=>X,queryTextWithRoots:()=>M,queryXPathNative:()=>Z,queryXPathWithRoots:()=>z});function R(t){let e=String(t||\"\").trim().replace(/^xpath=/i,\"\");if(!e)return[];let n=[],r=0;for(;r<e.length;){let s=\"child\";e.startsWith(\"//\",r)?(s=\"desc\",r+=2):e[r]===\"/\"&&(s=\"child\",r+=1);let o=r,a=0,i=null;for(;r<e.length;){let l=e[r];if(i)l===i&&(i=null);else if(l===\"'\"||l==='\"')i=l;else if(l===\"[\")a++;else if(l===\"]\")a--;else if(l===\"/\"&&a===0)break;r+=1}let u=e.slice(o,r).trim();if(!u)continue;let{tag:c,predicates:f}=W(u);n.push({axis:s,tag:c,predicates:f})}return n}function q(t){let e=[],n=0;for(;n<t.length;){if(t[n]!==\"[\"){n++;continue}n++;let r=n,s=null;for(;n<t.length;){let o=t[n];if(s)o===s&&(s=null);else if(o===\"'\"||o==='\"')s=o;else if(o===\"]\")break;n++}e.push(t.slice(r,n).trim()),n++}return e}function W(t){let e=t.indexOf(\"[\");if(e===-1)return{tag:t===\"\"?\"*\":t.toLowerCase(),predicates:[]};let n=t.slice(0,e).trim(),r=n===\"\"?\"*\":n.toLowerCase(),s=t.slice(e),o=[];for(let a of q(s)){let i=d(a);i&&o.push(i)}return{tag:r,predicates:o}}function d(t){let e=t.trim();if(!e)return null;let n=y(e,\"or\");if(n.length>1){let o=n.map(a=>d(a)).filter(Boolean);return o.length!==n.length?null:{type:\"or\",predicates:o}}let r=y(e,\"and\");if(r.length>1){let o=r.map(a=>d(a)).filter(Boolean);return o.length!==r.length?null:{type:\"and\",predicates:o}}let s=O(e,\"not\");if(s!=null){let o=d(s);return o?{type:\"not\",predicate:o}:null}return _(e)}function _(t){let e=/^(?:'([^']*)'|\"([^\"]*)\")$/,n=\"[a-zA-Z_][\\\\w.-]*\",r=`(?:'([^']*)'|\"([^\"]*)\")`;if(/^\\d+$/.test(t))return{type:\"index\",index:Math.max(1,Number(t))};let s=t.match(new RegExp(`^normalize-space\\\\(\\\\s*@(${n})\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(s)return{type:\"attrEquals\",name:s[1],value:s[2]??s[3]??\"\",normalize:!0};let o=t.match(new RegExp(`^normalize-space\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*\\\\)\\\\s*=\\\\s*${r}$`));if(o)return{type:\"textEquals\",value:o[1]??o[2]??\"\",normalize:!0};let a=t.match(new RegExp(`^@(${n})\\\\s*=\\\\s*${r}$`));if(a)return{type:\"attrEquals\",name:a[1],value:a[2]??a[3]??\"\"};let i=t.match(new RegExp(`^@(${n})$`));if(i)return{type:\"attrExists\",name:i[1]};let u=t.match(new RegExp(`^contains\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(u)return{type:\"attrContains\",name:u[1],value:u[2]??u[3]??\"\"};let c=t.match(new RegExp(`^starts-with\\\\(\\\\s*@(${n})\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));if(c)return{type:\"attrStartsWith\",name:c[1],value:c[2]??c[3]??\"\"};let f=t.match(new RegExp(`^(?:text\\\\(\\\\)|\\\\.)\\\\s*=\\\\s*${r}$`));if(f)return{type:\"textEquals\",value:f[1]??f[2]??\"\"};let l=t.match(new RegExp(`^contains\\\\(\\\\s*(?:text\\\\(\\\\)|\\\\.)\\\\s*,\\\\s*${r}\\\\s*\\\\)$`));return l?{type:\"textContains\",value:l[1]??l[2]??\"\"}:(e.test(t),null)}function y(t,e){let n=[],r=0,s=0,o=null,a=0;for(;a<t.length;){let i=t[a];if(o){i===o&&(o=null),a+=1;continue}if(i===\"'\"||i==='\"'){o=i,a+=1;continue}if(i===\"(\"){s+=1,a+=1;continue}if(i===\")\"){s=Math.max(0,s-1),a+=1;continue}if(s===0&&L(t,a,e)){n.push(t.slice(r,a).trim()),a+=e.length,r=a;continue}a+=1}return n.push(t.slice(r).trim()),n.filter(i=>i.length>0)}function L(t,e,n){if(!t.startsWith(n,e))return!1;let r=e>0?t[e-1]:\" \";if(r===\"@\")return!1;let s=e+n.length<t.length?t[e+n.length]:\" \";return S(r)&&S(s)}function S(t){return!/[a-zA-Z0-9_.-]/.test(t)}function O(t,e){let n=`${e}(`;if(!t.startsWith(n)||!t.endsWith(\")\"))return null;let r=t.slice(n.length,-1);return I(r)?r:null}function I(t){let e=0,n=null;for(let r=0;r<t.length;r+=1){let s=t[r];if(n){s===n&&(n=null);continue}if(s===\"'\"||s==='\"'){n=s;continue}if(s===\"(\"?e+=1:s===\")\"&&(e-=1),e<0)return!1}return e===0}var F=t=>t.replace(/\\s+/g,\" \").trim();function b(t){return String(t.textContent??\"\")}function m(t,e){return e?F(t):t}function x(t,e){switch(e.type){case\"and\":return e.predicates.every(n=>x(t,n));case\"or\":return e.predicates.some(n=>x(t,n));case\"not\":return!x(t,e.predicate);case\"attrExists\":return t.getAttribute(e.name)!==null;case\"attrEquals\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize)===m(e.value,e.normalize)}case\"attrContains\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).includes(m(e.value,e.normalize))}case\"attrStartsWith\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).startsWith(m(e.value,e.normalize))}case\"textEquals\":return m(b(t),e.normalize)===m(e.value,e.normalize);case\"textContains\":return m(b(t),e.normalize).includes(m(e.value,e.normalize));case\"index\":return!0;default:return!0}}function v(t,e){let n=t;for(let r of e){if(!n.length)return[];if(r.type===\"index\"){let s=r.index-1;n=s>=0&&s<n.length?[n[s]]:[];continue}n=n.filter(s=>x(s,r))}return n}function w(t){let e=new Map;for(let n=0;n<t.length;n+=2){let r=t[n],s=t[n+1];r instanceof Element&&s instanceof ShadowRoot&&e.set(r,s)}return e}function E(t,e){if(!t)return[];if(t instanceof Document)return t.documentElement?[t.documentElement]:[];if(t instanceof ShadowRoot||t instanceof DocumentFragment)return Array.from(t.children||[]);if(!(t instanceof Element))return[];let n=Array.from(t.children||[]);t.shadowRoot&&n.push(...Array.from(t.shadowRoot.children||[]));let r=e.get(t);return r&&n.push(...Array.from(r.children||[])),n}function H(t,e){let n=[],r=new Set,s=[...E(t,e)].reverse();for(;s.length;){let o=s.pop();if(!(o instanceof Element)||r.has(o))continue;r.add(o),n.push(o);let a=E(o,e);for(let i=a.length-1;i>=0;i-=1)s.push(a[i])}return n}function X(t,e,...n){let r=w(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}function B(t,...e){return X.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function M(t,e,...n){let r=w(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}function Y(t,...e){return M.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function T(t){let e=String(t||\"\").trim();return e?e.replace(/^xpath=/i,\"\").trim():\"\"}function G(t,e){return e.tag===\"*\"?!0:t.localName===e.tag}function z(t,e,...n){let r=w(n),s=R(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):H(c,r)).filter(h=>G(h,a)),g=v(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}function K(t,...e){return z.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function Z(t,e){let n=T(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}function U(t){let e=T(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}function V(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}return k(j);})();\n globalThis.__stagehandSelectorRuntime = __stagehandSelectorRuntimeFactory;\n}";
|
|
6
|
-
export const selectorRuntimeSources = {
|
|
7
|
-
"countCssWithRoots": "function O(t,...e){return C.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
|
|
8
|
-
"countTextWithRoots": "function I(t,...e){return k.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
|
|
9
|
-
"countXPathNative": "function B(t){let e=v(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}",
|
|
10
|
-
"countXPathWithRoots": "function F(t,...e){return W.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}",
|
|
11
|
-
"hasOpenShadowRoots": "function Y(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}",
|
|
12
|
-
"queryCssWithRoots": "function C(t,e,...n){let r=P(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}",
|
|
13
|
-
"queryTextWithRoots": "function k(t,e,...n){let r=P(n),s=new Set([\"SCRIPT\",\"STYLE\",\"TEMPLATE\",\"NOSCRIPT\",\"HEAD\",\"TITLE\",\"LINK\",\"META\",\"HTML\",\"BODY\"]),o=String(t||\"\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\"\";if(s.has(g))return\"\";try{let p=l.innerText;if(typeof p==\"string\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\"string\"?h.trim():\"\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}",
|
|
14
|
-
"queryXPathNative": "function H(t,e){let n=v(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}",
|
|
15
|
-
"queryXPathWithRoots": "function W(t,e,...n){let r=P(n),s=b(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\"child\"?E(c,r):$(c,r)).filter(h=>q(h,a)),g=R(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}"
|
|
16
|
-
};
|
|
17
|
-
export const selectorRuntimeGlobalRefs = {
|
|
18
|
-
"countCssWithRoots": "globalThis.__stagehandSelectorRuntime.countCssWithRoots",
|
|
19
|
-
"countTextWithRoots": "globalThis.__stagehandSelectorRuntime.countTextWithRoots",
|
|
20
|
-
"countXPathNative": "globalThis.__stagehandSelectorRuntime.countXPathNative",
|
|
21
|
-
"countXPathWithRoots": "globalThis.__stagehandSelectorRuntime.countXPathWithRoots",
|
|
22
|
-
"hasOpenShadowRoots": "globalThis.__stagehandSelectorRuntime.hasOpenShadowRoots",
|
|
23
|
-
"queryCssWithRoots": "globalThis.__stagehandSelectorRuntime.queryCssWithRoots",
|
|
24
|
-
"queryTextWithRoots": "globalThis.__stagehandSelectorRuntime.queryTextWithRoots",
|
|
25
|
-
"queryXPathNative": "globalThis.__stagehandSelectorRuntime.queryXPathNative",
|
|
26
|
-
"queryXPathWithRoots": "globalThis.__stagehandSelectorRuntime.queryXPathWithRoots"
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=selectorRuntime.generated.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectorRuntime.generated.js","sourceRoot":"","sources":["../../../../../../lib/v3/dom/build/selectorRuntime.generated.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,0oRAA0oR,CAAC;AACnrR,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,mBAAmB,EAAE,+EAA+E;IACpG,oBAAoB,EAAE,+EAA+E;IACrG,kBAAkB,EAAE,wOAAwO;IAC5P,qBAAqB,EAAE,+EAA+E;IACtG,oBAAoB,EAAE,6LAA6L;IACnN,mBAAmB,EAAE,iTAAiT;IACtU,oBAAoB,EAAE,8xBAA8xB;IACpzB,kBAAkB,EAAE,+SAA+S;IACnU,qBAAqB,EAAE,mVAAmV;CAClW,CAAC;AACX,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,mBAAmB,EAAE,yDAAyD;IAC9E,oBAAoB,EAAE,0DAA0D;IAChF,kBAAkB,EAAE,wDAAwD;IAC5E,qBAAqB,EAAE,2DAA2D;IAClF,oBAAoB,EAAE,0DAA0D;IAChF,mBAAmB,EAAE,yDAAyD;IAC9E,oBAAoB,EAAE,0DAA0D;IAChF,kBAAkB,EAAE,wDAAwD;IAC5E,qBAAqB,EAAE,2DAA2D;CAC1E,CAAC","sourcesContent":["/*\n * AUTO-GENERATED FILE. DO NOT EDIT.\n * Run `pnpm run build-dom-scripts` to regenerate.\n */\nexport const selectorRuntimeBootstrap = \"if (!globalThis.__stagehandSelectorRuntime) { var __stagehandSelectorRuntimeFactory=(()=>{var P=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var n in e)P(t,n,{get:e[n],enumerable:!0})},C=(t,e,n,r)=>{if(e&&typeof e==\\\"object\\\"||typeof e==\\\"function\\\")for(let s of N(e))!D.call(t,s)&&s!==n&&P(t,s,{get:()=>e[s],enumerable:!(r=A(e,s))||r.enumerable});return t};var k=t=>C(P({},\\\"__esModule\\\",{value:!0}),t);var j={};$(j,{countCssWithRoots:()=>B,countTextWithRoots:()=>Y,countXPathNative:()=>U,countXPathWithRoots:()=>K,hasOpenShadowRoots:()=>V,queryCssWithRoots:()=>X,queryTextWithRoots:()=>M,queryXPathNative:()=>Z,queryXPathWithRoots:()=>z});function R(t){let e=String(t||\\\"\\\").trim().replace(/^xpath=/i,\\\"\\\");if(!e)return[];let n=[],r=0;for(;r<e.length;){let s=\\\"child\\\";e.startsWith(\\\"//\\\",r)?(s=\\\"desc\\\",r+=2):e[r]===\\\"/\\\"&&(s=\\\"child\\\",r+=1);let o=r,a=0,i=null;for(;r<e.length;){let l=e[r];if(i)l===i&&(i=null);else if(l===\\\"'\\\"||l==='\\\"')i=l;else if(l===\\\"[\\\")a++;else if(l===\\\"]\\\")a--;else if(l===\\\"/\\\"&&a===0)break;r+=1}let u=e.slice(o,r).trim();if(!u)continue;let{tag:c,predicates:f}=W(u);n.push({axis:s,tag:c,predicates:f})}return n}function q(t){let e=[],n=0;for(;n<t.length;){if(t[n]!==\\\"[\\\"){n++;continue}n++;let r=n,s=null;for(;n<t.length;){let o=t[n];if(s)o===s&&(s=null);else if(o===\\\"'\\\"||o==='\\\"')s=o;else if(o===\\\"]\\\")break;n++}e.push(t.slice(r,n).trim()),n++}return e}function W(t){let e=t.indexOf(\\\"[\\\");if(e===-1)return{tag:t===\\\"\\\"?\\\"*\\\":t.toLowerCase(),predicates:[]};let n=t.slice(0,e).trim(),r=n===\\\"\\\"?\\\"*\\\":n.toLowerCase(),s=t.slice(e),o=[];for(let a of q(s)){let i=d(a);i&&o.push(i)}return{tag:r,predicates:o}}function d(t){let e=t.trim();if(!e)return null;let n=y(e,\\\"or\\\");if(n.length>1){let o=n.map(a=>d(a)).filter(Boolean);return o.length!==n.length?null:{type:\\\"or\\\",predicates:o}}let r=y(e,\\\"and\\\");if(r.length>1){let o=r.map(a=>d(a)).filter(Boolean);return o.length!==r.length?null:{type:\\\"and\\\",predicates:o}}let s=O(e,\\\"not\\\");if(s!=null){let o=d(s);return o?{type:\\\"not\\\",predicate:o}:null}return _(e)}function _(t){let e=/^(?:'([^']*)'|\\\"([^\\\"]*)\\\")$/,n=\\\"[a-zA-Z_][\\\\\\\\w.-]*\\\",r=`(?:'([^']*)'|\\\"([^\\\"]*)\\\")`;if(/^\\\\d+$/.test(t))return{type:\\\"index\\\",index:Math.max(1,Number(t))};let s=t.match(new RegExp(`^normalize-space\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*\\\\\\\\)\\\\\\\\s*=\\\\\\\\s*${r}$`));if(s)return{type:\\\"attrEquals\\\",name:s[1],value:s[2]??s[3]??\\\"\\\",normalize:!0};let o=t.match(new RegExp(`^normalize-space\\\\\\\\(\\\\\\\\s*(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*\\\\\\\\)\\\\\\\\s*=\\\\\\\\s*${r}$`));if(o)return{type:\\\"textEquals\\\",value:o[1]??o[2]??\\\"\\\",normalize:!0};let a=t.match(new RegExp(`^@(${n})\\\\\\\\s*=\\\\\\\\s*${r}$`));if(a)return{type:\\\"attrEquals\\\",name:a[1],value:a[2]??a[3]??\\\"\\\"};let i=t.match(new RegExp(`^@(${n})$`));if(i)return{type:\\\"attrExists\\\",name:i[1]};let u=t.match(new RegExp(`^contains\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*,\\\\\\\\s*${r}\\\\\\\\s*\\\\\\\\)$`));if(u)return{type:\\\"attrContains\\\",name:u[1],value:u[2]??u[3]??\\\"\\\"};let c=t.match(new RegExp(`^starts-with\\\\\\\\(\\\\\\\\s*@(${n})\\\\\\\\s*,\\\\\\\\s*${r}\\\\\\\\s*\\\\\\\\)$`));if(c)return{type:\\\"attrStartsWith\\\",name:c[1],value:c[2]??c[3]??\\\"\\\"};let f=t.match(new RegExp(`^(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*=\\\\\\\\s*${r}$`));if(f)return{type:\\\"textEquals\\\",value:f[1]??f[2]??\\\"\\\"};let l=t.match(new RegExp(`^contains\\\\\\\\(\\\\\\\\s*(?:text\\\\\\\\(\\\\\\\\)|\\\\\\\\.)\\\\\\\\s*,\\\\\\\\s*${r}\\\\\\\\s*\\\\\\\\)$`));return l?{type:\\\"textContains\\\",value:l[1]??l[2]??\\\"\\\"}:(e.test(t),null)}function y(t,e){let n=[],r=0,s=0,o=null,a=0;for(;a<t.length;){let i=t[a];if(o){i===o&&(o=null),a+=1;continue}if(i===\\\"'\\\"||i==='\\\"'){o=i,a+=1;continue}if(i===\\\"(\\\"){s+=1,a+=1;continue}if(i===\\\")\\\"){s=Math.max(0,s-1),a+=1;continue}if(s===0&&L(t,a,e)){n.push(t.slice(r,a).trim()),a+=e.length,r=a;continue}a+=1}return n.push(t.slice(r).trim()),n.filter(i=>i.length>0)}function L(t,e,n){if(!t.startsWith(n,e))return!1;let r=e>0?t[e-1]:\\\" \\\";if(r===\\\"@\\\")return!1;let s=e+n.length<t.length?t[e+n.length]:\\\" \\\";return S(r)&&S(s)}function S(t){return!/[a-zA-Z0-9_.-]/.test(t)}function O(t,e){let n=`${e}(`;if(!t.startsWith(n)||!t.endsWith(\\\")\\\"))return null;let r=t.slice(n.length,-1);return I(r)?r:null}function I(t){let e=0,n=null;for(let r=0;r<t.length;r+=1){let s=t[r];if(n){s===n&&(n=null);continue}if(s===\\\"'\\\"||s==='\\\"'){n=s;continue}if(s===\\\"(\\\"?e+=1:s===\\\")\\\"&&(e-=1),e<0)return!1}return e===0}var F=t=>t.replace(/\\\\s+/g,\\\" \\\").trim();function b(t){return String(t.textContent??\\\"\\\")}function m(t,e){return e?F(t):t}function x(t,e){switch(e.type){case\\\"and\\\":return e.predicates.every(n=>x(t,n));case\\\"or\\\":return e.predicates.some(n=>x(t,n));case\\\"not\\\":return!x(t,e.predicate);case\\\"attrExists\\\":return t.getAttribute(e.name)!==null;case\\\"attrEquals\\\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize)===m(e.value,e.normalize)}case\\\"attrContains\\\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).includes(m(e.value,e.normalize))}case\\\"attrStartsWith\\\":{let n=t.getAttribute(e.name);return n===null?!1:m(n,e.normalize).startsWith(m(e.value,e.normalize))}case\\\"textEquals\\\":return m(b(t),e.normalize)===m(e.value,e.normalize);case\\\"textContains\\\":return m(b(t),e.normalize).includes(m(e.value,e.normalize));case\\\"index\\\":return!0;default:return!0}}function v(t,e){let n=t;for(let r of e){if(!n.length)return[];if(r.type===\\\"index\\\"){let s=r.index-1;n=s>=0&&s<n.length?[n[s]]:[];continue}n=n.filter(s=>x(s,r))}return n}function w(t){let e=new Map;for(let n=0;n<t.length;n+=2){let r=t[n],s=t[n+1];r instanceof Element&&s instanceof ShadowRoot&&e.set(r,s)}return e}function E(t,e){if(!t)return[];if(t instanceof Document)return t.documentElement?[t.documentElement]:[];if(t instanceof ShadowRoot||t instanceof DocumentFragment)return Array.from(t.children||[]);if(!(t instanceof Element))return[];let n=Array.from(t.children||[]);t.shadowRoot&&n.push(...Array.from(t.shadowRoot.children||[]));let r=e.get(t);return r&&n.push(...Array.from(r.children||[])),n}function H(t,e){let n=[],r=new Set,s=[...E(t,e)].reverse();for(;s.length;){let o=s.pop();if(!(o instanceof Element)||r.has(o))continue;r.add(o),n.push(o);let a=E(o,e);for(let i=a.length-1;i>=0;i-=1)s.push(a[i])}return n}function X(t,e,...n){let r=w(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}function B(t,...e){return X.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function M(t,e,...n){let r=w(n),s=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),o=String(t||\\\"\\\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\\\"\\\";if(s.has(g))return\\\"\\\";try{let p=l.innerText;if(typeof p==\\\"string\\\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\\\"string\\\"?h.trim():\\\"\\\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}function Y(t,...e){return M.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function T(t){let e=String(t||\\\"\\\").trim();return e?e.replace(/^xpath=/i,\\\"\\\").trim():\\\"\\\"}function G(t,e){return e.tag===\\\"*\\\"?!0:t.localName===e.tag}function z(t,e,...n){let r=w(n),s=R(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\\\"child\\\"?E(c,r):H(c,r)).filter(h=>G(h,a)),g=v(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}function K(t,...e){return z.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}function Z(t,e){let n=T(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}function U(t){let e=T(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}function V(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}return k(j);})();\\n globalThis.__stagehandSelectorRuntime = __stagehandSelectorRuntimeFactory;\\n}\";\nexport const selectorRuntimeSources = {\n \"countCssWithRoots\": \"function O(t,...e){return C.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}\",\n \"countTextWithRoots\": \"function I(t,...e){return k.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}\",\n \"countXPathNative\": \"function B(t){let e=v(t);if(!e)return 0;try{let n=this.evaluate(e,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=0;for(let s=0;s<n.snapshotLength;s+=1)n.snapshotItem(s)instanceof Element&&(r+=1);return r}catch{return 0}}\",\n \"countXPathWithRoots\": \"function F(t,...e){return W.call(this,t,Number.MAX_SAFE_INTEGER,...e).length}\",\n \"hasOpenShadowRoots\": \"function Y(){try{let t=this.createTreeWalker(this,NodeFilter.SHOW_ELEMENT);for(;t.nextNode();){let e=t.currentNode;if(e instanceof Element&&e.shadowRoot)return!0}}catch{return!1}return!1}\",\n \"queryCssWithRoots\": \"function C(t,e,...n){let r=P(n),s=[],o=new Set,a=[...E(this,r)].reverse();for(;a.length&&s.length<e;){let i=a.pop();if(!(i instanceof Element)||o.has(i))continue;o.add(i);try{if(i.matches(t)&&(s.push(i),s.length>=e))break}catch{return[]}let u=E(i,r);for(let c=u.length-1;c>=0;c-=1)a.push(u[c])}return s}\",\n \"queryTextWithRoots\": \"function k(t,e,...n){let r=P(n),s=new Set([\\\"SCRIPT\\\",\\\"STYLE\\\",\\\"TEMPLATE\\\",\\\"NOSCRIPT\\\",\\\"HEAD\\\",\\\"TITLE\\\",\\\"LINK\\\",\\\"META\\\",\\\"HTML\\\",\\\"BODY\\\"]),o=String(t||\\\"\\\").toLowerCase();if(!o)return[];let a=l=>{let g=l.tagName?l.tagName.toUpperCase():\\\"\\\";if(s.has(g))return\\\"\\\";try{let p=l.innerText;if(typeof p==\\\"string\\\"&&p.trim())return p.trim()}catch{}let h=l.textContent;return typeof h==\\\"string\\\"?h.trim():\\\"\\\"},i=[],u=new Set,c=[...E(this,r)].reverse();for(;c.length;){let l=c.pop();if(!(l instanceof Element)||u.has(l))continue;u.add(l);let g=a(l);g&&g.toLowerCase().includes(o)&&i.push(l);let h=E(l,r);for(let p=h.length-1;p>=0;p-=1)c.push(h[p])}let f=[];for(let l of i){let g=!1;for(let h of i)if(l!==h)try{if(l.contains(h)){g=!0;break}}catch{}if(!g&&(f.push(l),f.length>=e))break}return f}\",\n \"queryXPathNative\": \"function H(t,e){let n=v(t);if(!n||!Number.isFinite(e)||e<=0)return[];try{let r=this.evaluate(n,this,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[],o=Math.min(r.snapshotLength,Math.floor(e));for(let a=0;a<o;a+=1){let i=r.snapshotItem(a);i instanceof Element&&s.push(i)}return s}catch{return[]}}\",\n \"queryXPathWithRoots\": \"function W(t,e,...n){let r=P(n),s=b(t);if(!s.length)return[];let o=[this];for(let a of s){let i=[],u=new Set;for(let c of o){let l=(a.axis===\\\"child\\\"?E(c,r):$(c,r)).filter(h=>q(h,a)),g=R(l,a.predicates);for(let h of g)if(!u.has(h)&&(u.add(h),i.push(h),i.length>=e&&a===s[s.length-1]))break}if(!i.length)return[];o=i}return o.slice(0,e)}\"\n} as const;\nexport const selectorRuntimeGlobalRefs = {\n \"countCssWithRoots\": \"globalThis.__stagehandSelectorRuntime.countCssWithRoots\",\n \"countTextWithRoots\": \"globalThis.__stagehandSelectorRuntime.countTextWithRoots\",\n \"countXPathNative\": \"globalThis.__stagehandSelectorRuntime.countXPathNative\",\n \"countXPathWithRoots\": \"globalThis.__stagehandSelectorRuntime.countXPathWithRoots\",\n \"hasOpenShadowRoots\": \"globalThis.__stagehandSelectorRuntime.hasOpenShadowRoots\",\n \"queryCssWithRoots\": \"globalThis.__stagehandSelectorRuntime.queryCssWithRoots\",\n \"queryTextWithRoots\": \"globalThis.__stagehandSelectorRuntime.queryTextWithRoots\",\n \"queryXPathNative\": \"globalThis.__stagehandSelectorRuntime.queryXPathNative\",\n \"queryXPathWithRoots\": \"globalThis.__stagehandSelectorRuntime.queryXPathWithRoots\"\n} as const;\nexport type SelectorRuntimeName = keyof typeof selectorRuntimeSources;\n"]}
|