@burdenoff/ui-engine 2026.1127.1 → 2026.1127.3

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.
Files changed (63) hide show
  1. package/README.md +68 -3
  2. package/dist/capture.js +3 -2
  3. package/dist/dom-runtime/actions.d.ts +65 -0
  4. package/dist/dom-runtime/iife.d.ts +1 -0
  5. package/dist/dom-runtime/index.d.ts +7 -0
  6. package/dist/dom-runtime/runtime.d.ts +79 -0
  7. package/dist/dom-runtime.d.ts +2 -0
  8. package/dist/dom-runtime.iife.js +1 -0
  9. package/dist/dom-runtime.js +535 -0
  10. package/dist/{index-05zgh18g.js → index-2kgsgn1c.js} +1 -1
  11. package/dist/{index-phd8yhyg.js → index-bnvmt4wf.js} +7 -5
  12. package/dist/{index-c6pmt2rg.js → index-cs6acyjn.js} +6 -59
  13. package/dist/index-mgztm37r.js +57 -0
  14. package/dist/index-q1b0j9yr.js +1349 -0
  15. package/dist/index-zwrxw3zp.js +1988 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +180 -6
  18. package/dist/recording.js +1 -1
  19. package/dist/replay.js +2 -2
  20. package/dist/script/adapters/browser-action-contract.d.ts +22 -0
  21. package/dist/script/adapters/from-browser-action.d.ts +7 -0
  22. package/dist/script/adapters/from-remote-browser.d.ts +7 -0
  23. package/dist/script/adapters/recording.d.ts +25 -0
  24. package/dist/script/adapters/to-browser-action.d.ts +8 -0
  25. package/dist/script/canonical.d.ts +6 -0
  26. package/dist/script/capabilities.d.ts +29 -0
  27. package/dist/script/describe.d.ts +83 -0
  28. package/dist/script/fingerprint.d.ts +9 -0
  29. package/dist/script/hash.d.ts +3 -0
  30. package/dist/script/index.d.ts +22 -0
  31. package/dist/script/json-schema.d.ts +4 -0
  32. package/dist/script/limits.d.ts +61 -0
  33. package/dist/script/parse.d.ts +31 -0
  34. package/dist/script/schema.d.ts +87 -0
  35. package/dist/script/types.d.ts +489 -0
  36. package/dist/script/walk.d.ts +29 -0
  37. package/dist/script.d.ts +2 -0
  38. package/dist/script.js +175 -0
  39. package/dist/target/aria.d.ts +31 -0
  40. package/dist/target/dom.d.ts +35 -0
  41. package/dist/target/index.d.ts +13 -0
  42. package/dist/target/markers.d.ts +18 -0
  43. package/dist/target/methods.d.ts +52 -0
  44. package/dist/target/resolve.d.ts +46 -0
  45. package/dist/target/snapshot.d.ts +57 -0
  46. package/dist/target/text.d.ts +23 -0
  47. package/dist/target/types.d.ts +88 -0
  48. package/dist/target.d.ts +2 -0
  49. package/dist/target.js +92 -0
  50. package/dist/testing/fixtures/ambiguous.d.ts +7 -0
  51. package/dist/testing/fixtures/iframe.d.ts +6 -0
  52. package/dist/testing/fixtures/index.d.ts +26 -0
  53. package/dist/testing/fixtures/invoices-v2.d.ts +8 -0
  54. package/dist/testing/fixtures/invoices-v3.d.ts +7 -0
  55. package/dist/testing/fixtures/invoices.d.ts +6 -0
  56. package/dist/testing/fixtures/login.d.ts +6 -0
  57. package/dist/testing/fixtures/shadow.d.ts +7 -0
  58. package/dist/testing/index.d.ts +6 -0
  59. package/dist/testing/mount.d.ts +18 -0
  60. package/dist/testing.d.ts +2 -0
  61. package/dist/testing.js +324 -0
  62. package/package.json +28 -5
  63. package/schema/ui-script-v1.schema.json +8199 -0
package/dist/script.js ADDED
@@ -0,0 +1,175 @@
1
+ import {
2
+ UI_EXPRESSION_OPS2,
3
+ UI_ANCHOR_RELATIONS2,
4
+ UI_TARGET_METHOD_KINDS2,
5
+ UI_WEB_ACTIONS2,
6
+ UI_DESKTOP_ACTIONS2,
7
+ UI_FLOW_ACTIONS2,
8
+ UI_STEP_ACTIONS2,
9
+ UI_VALUE_TYPES2,
10
+ UI_SCRIPT_VERSION2,
11
+ MAX_SCRIPT_STEPS2,
12
+ MAX_SCRIPT_BYTES2,
13
+ MAX_FLOW_DEPTH2,
14
+ MAX_EXPRESSION_DEPTH2,
15
+ MAX_EXPRESSION_ITEMS2,
16
+ MAX_OPERATOR_ARGS2,
17
+ MAX_SCRIPT_INPUTS2,
18
+ MAX_SCRIPT_OUTPUTS2,
19
+ MAX_SCRIPT_VARIABLES2,
20
+ MAX_SCRIPT_ELEMENTS2,
21
+ MAX_TARGET_METHODS2,
22
+ MAX_FRAME_DEPTH2,
23
+ MAX_EXTRACT_FIELDS2,
24
+ MAX_LIST_ITEMS2,
25
+ MAX_LIST_PAGES2,
26
+ MAX_LOOP_ITERATIONS2,
27
+ MAX_RETRY_ATTEMPTS2,
28
+ MAX_STEP_TIMEOUT_MS2,
29
+ MAX_DELAY_MS2,
30
+ MAX_KEYS2,
31
+ MAX_SELECT_VALUES2,
32
+ MAX_SELECTOR_LENGTH2,
33
+ MAX_URL_LENGTH2,
34
+ MAX_LABEL_LENGTH2,
35
+ MAX_TEXT_LENGTH2,
36
+ MAX_INTENT_LENGTH2,
37
+ MAX_NAME_LENGTH2,
38
+ LEGACY_MAX_BROWSER_STEPS2,
39
+ LEGACY_MAX_STEPS_BYTES2,
40
+ jsonByteLength2,
41
+ uiScriptRegistry2,
42
+ NAME_PATTERN2,
43
+ STEP_ID_PATTERN2,
44
+ ELEMENT_KEY_PATTERN2,
45
+ uiExpressionSchema2,
46
+ uiTargetMethodSchema2,
47
+ uiTargetSchema2,
48
+ uiTargetRefSchema2,
49
+ uiStepSchema2,
50
+ uiScriptSchema2,
51
+ canonicalJson2,
52
+ childBlocks2,
53
+ walkSteps2,
54
+ countSteps2,
55
+ stepAtPath2,
56
+ stepTargets2,
57
+ stepExpressions2,
58
+ visitExpression2,
59
+ RECORDING_ACTION_OF2,
60
+ uiStepFingerprint2,
61
+ withFingerprint2,
62
+ UiScriptError2,
63
+ UI_EXPRESSION_ARITY2,
64
+ parseUiScript2,
65
+ safeParseUiScript2,
66
+ UI_SCRIPT_SCHEMA_HASH2,
67
+ schemaHashOf2,
68
+ UI_SCRIPT_SCHEMA_TITLE2,
69
+ uiScriptJsonSchema2,
70
+ CAPABILITY_IDS2,
71
+ SCRIPT_CAPABILITY2,
72
+ requiredCapabilities2,
73
+ missingCapabilities2,
74
+ UI_SCRIPT_STEP_KEY_PREFIX2,
75
+ UI_SCRIPT_STEP_MESSAGES2,
76
+ stepMessageKey2,
77
+ describeTarget2,
78
+ describeExpression2,
79
+ describeStep2,
80
+ BROWSER_STEP_ACTIONS2,
81
+ fromBrowserActionSteps2,
82
+ toBrowserActionSteps2,
83
+ targetFromPlaywrightSelector2,
84
+ fromRemoteBrowserSteps2,
85
+ fromRecording2,
86
+ toRecording2
87
+ } from "./index-zwrxw3zp.js";
88
+ import"./index-cs6acyjn.js";
89
+ export {
90
+ BROWSER_STEP_ACTIONS2 as BROWSER_STEP_ACTIONS,
91
+ CAPABILITY_IDS2 as CAPABILITY_IDS,
92
+ ELEMENT_KEY_PATTERN2 as ELEMENT_KEY_PATTERN,
93
+ LEGACY_MAX_BROWSER_STEPS2 as LEGACY_MAX_BROWSER_STEPS,
94
+ LEGACY_MAX_STEPS_BYTES2 as LEGACY_MAX_STEPS_BYTES,
95
+ MAX_DELAY_MS2 as MAX_DELAY_MS,
96
+ MAX_EXPRESSION_DEPTH2 as MAX_EXPRESSION_DEPTH,
97
+ MAX_EXPRESSION_ITEMS2 as MAX_EXPRESSION_ITEMS,
98
+ MAX_EXTRACT_FIELDS2 as MAX_EXTRACT_FIELDS,
99
+ MAX_FLOW_DEPTH2 as MAX_FLOW_DEPTH,
100
+ MAX_FRAME_DEPTH2 as MAX_FRAME_DEPTH,
101
+ MAX_INTENT_LENGTH2 as MAX_INTENT_LENGTH,
102
+ MAX_KEYS2 as MAX_KEYS,
103
+ MAX_LABEL_LENGTH2 as MAX_LABEL_LENGTH,
104
+ MAX_LIST_ITEMS2 as MAX_LIST_ITEMS,
105
+ MAX_LIST_PAGES2 as MAX_LIST_PAGES,
106
+ MAX_LOOP_ITERATIONS2 as MAX_LOOP_ITERATIONS,
107
+ MAX_NAME_LENGTH2 as MAX_NAME_LENGTH,
108
+ MAX_OPERATOR_ARGS2 as MAX_OPERATOR_ARGS,
109
+ MAX_RETRY_ATTEMPTS2 as MAX_RETRY_ATTEMPTS,
110
+ MAX_SCRIPT_BYTES2 as MAX_SCRIPT_BYTES,
111
+ MAX_SCRIPT_ELEMENTS2 as MAX_SCRIPT_ELEMENTS,
112
+ MAX_SCRIPT_INPUTS2 as MAX_SCRIPT_INPUTS,
113
+ MAX_SCRIPT_OUTPUTS2 as MAX_SCRIPT_OUTPUTS,
114
+ MAX_SCRIPT_STEPS2 as MAX_SCRIPT_STEPS,
115
+ MAX_SCRIPT_VARIABLES2 as MAX_SCRIPT_VARIABLES,
116
+ MAX_SELECTOR_LENGTH2 as MAX_SELECTOR_LENGTH,
117
+ MAX_SELECT_VALUES2 as MAX_SELECT_VALUES,
118
+ MAX_STEP_TIMEOUT_MS2 as MAX_STEP_TIMEOUT_MS,
119
+ MAX_TARGET_METHODS2 as MAX_TARGET_METHODS,
120
+ MAX_TEXT_LENGTH2 as MAX_TEXT_LENGTH,
121
+ MAX_URL_LENGTH2 as MAX_URL_LENGTH,
122
+ NAME_PATTERN2 as NAME_PATTERN,
123
+ RECORDING_ACTION_OF2 as RECORDING_ACTION_OF,
124
+ SCRIPT_CAPABILITY2 as SCRIPT_CAPABILITY,
125
+ STEP_ID_PATTERN2 as STEP_ID_PATTERN,
126
+ UI_ANCHOR_RELATIONS2 as UI_ANCHOR_RELATIONS,
127
+ UI_DESKTOP_ACTIONS2 as UI_DESKTOP_ACTIONS,
128
+ UI_EXPRESSION_ARITY2 as UI_EXPRESSION_ARITY,
129
+ UI_EXPRESSION_OPS2 as UI_EXPRESSION_OPS,
130
+ UI_FLOW_ACTIONS2 as UI_FLOW_ACTIONS,
131
+ UI_SCRIPT_SCHEMA_HASH2 as UI_SCRIPT_SCHEMA_HASH,
132
+ UI_SCRIPT_SCHEMA_TITLE2 as UI_SCRIPT_SCHEMA_TITLE,
133
+ UI_SCRIPT_STEP_KEY_PREFIX2 as UI_SCRIPT_STEP_KEY_PREFIX,
134
+ UI_SCRIPT_STEP_MESSAGES2 as UI_SCRIPT_STEP_MESSAGES,
135
+ UI_SCRIPT_VERSION2 as UI_SCRIPT_VERSION,
136
+ UI_STEP_ACTIONS2 as UI_STEP_ACTIONS,
137
+ UI_TARGET_METHOD_KINDS2 as UI_TARGET_METHOD_KINDS,
138
+ UI_VALUE_TYPES2 as UI_VALUE_TYPES,
139
+ UI_WEB_ACTIONS2 as UI_WEB_ACTIONS,
140
+ UiScriptError2 as UiScriptError,
141
+ canonicalJson2 as canonicalJson,
142
+ childBlocks2 as childBlocks,
143
+ countSteps2 as countSteps,
144
+ describeExpression2 as describeExpression,
145
+ describeStep2 as describeStep,
146
+ describeTarget2 as describeTarget,
147
+ fromBrowserActionSteps2 as fromBrowserActionSteps,
148
+ fromRecording2 as fromRecording,
149
+ fromRemoteBrowserSteps2 as fromRemoteBrowserSteps,
150
+ jsonByteLength2 as jsonByteLength,
151
+ missingCapabilities2 as missingCapabilities,
152
+ parseUiScript2 as parseUiScript,
153
+ requiredCapabilities2 as requiredCapabilities,
154
+ safeParseUiScript2 as safeParseUiScript,
155
+ schemaHashOf2 as schemaHashOf,
156
+ stepAtPath2 as stepAtPath,
157
+ stepExpressions2 as stepExpressions,
158
+ stepMessageKey2 as stepMessageKey,
159
+ stepTargets2 as stepTargets,
160
+ targetFromPlaywrightSelector2 as targetFromPlaywrightSelector,
161
+ toBrowserActionSteps2 as toBrowserActionSteps,
162
+ toRecording2 as toRecording,
163
+ uiExpressionSchema2 as uiExpressionSchema,
164
+ uiScriptJsonSchema2 as uiScriptJsonSchema,
165
+ uiScriptRegistry2 as uiScriptRegistry,
166
+ uiScriptSchema2 as uiScriptSchema,
167
+ uiStepFingerprint2 as uiStepFingerprint,
168
+ uiStepSchema2 as uiStepSchema,
169
+ uiTargetMethodSchema2 as uiTargetMethodSchema,
170
+ uiTargetRefSchema2 as uiTargetRefSchema,
171
+ uiTargetSchema2 as uiTargetSchema,
172
+ visitExpression2 as visitExpression,
173
+ walkSteps2 as walkSteps,
174
+ withFingerprint2 as withFingerprint
175
+ };
@@ -0,0 +1,31 @@
1
+ /** Longest accessible name kept; longer names are cut. */
2
+ export declare const MAX_NAME_LENGTH = 512;
3
+ /** Longest visible text read from one element (the `getText` read limit). */
4
+ export declare const MAX_VISIBLE_TEXT = 65536;
5
+ /**
6
+ * Visibility known from elsewhere: a document rebuilt from a tree snapshot has
7
+ * no styles, so the snapshot's hidden flags decide what text a person saw.
8
+ * Undefined means "compute it from the element's styles".
9
+ */
10
+ export interface TextProbe {
11
+ isVisible?: (element: Element) => boolean | undefined;
12
+ }
13
+ /** The element's role: the first token of its `role` attribute, else its implicit role, else ''. */
14
+ export declare function roleOf(element: Element): string;
15
+ /** True when the element is typed content: an editing host or a text area, or inside one (rendered tree). */
16
+ export declare function isTypedContent(element: Element): boolean;
17
+ /**
18
+ * The element's accessible name, whitespace collapsed and cut to
19
+ * `MAX_NAME_LENGTH`. Form fields never take their name from their value.
20
+ */
21
+ export declare function accessibleName(element: Element, probe?: TextProbe): string;
22
+ /**
23
+ * The name an element has from its labels alone (aria-labelledby, aria-label,
24
+ * associated labels, alt, legend, caption, title, placeholder), never from its
25
+ * content. Reports use it for typed content, whose text is a form-field value.
26
+ */
27
+ export declare function labelName(element: Element, probe?: TextProbe): string;
28
+ /** The text a person reads in the element (its content, never a form-field value), whitespace collapsed. */
29
+ export declare function visibleText(element: Element, probe?: TextProbe): string;
30
+ /** True when the role and name are the ones asked for (names compared after normalisation). */
31
+ export declare function matchesRoleAndName(element: Element, role: string, name: string, probe?: TextProbe): boolean;
@@ -0,0 +1,35 @@
1
+ import { SENSITIVE_MARKERS } from './markers.js';
2
+ import type { WebRect } from './types.js';
3
+ /** Where a search starts: a document, a shadow root or an element. */
4
+ export type WebSearchRoot = Document | ShadowRoot | Element;
5
+ /** Overrides for documents without layout (a test DOM, a document rebuilt from a snapshot). */
6
+ export interface ElementStateProbe {
7
+ /** The element's bounds in the top viewport, or null to measure it. */
8
+ rectOf?: (element: Element) => WebRect | null;
9
+ /** Whether the element is visible, or undefined to compute it. */
10
+ isVisible?: (element: Element) => boolean | undefined;
11
+ }
12
+ /** The parent in the rendered tree: the assigned slot of slotted content, else the parent element, else a shadow root's host. */
13
+ export declare function parentAcrossShadow(element: Element): Element | null;
14
+ /**
15
+ * Whether a person can see the element: it is connected, neither it nor an
16
+ * ancestor (across shadow roots) is `hidden`, `display: none` or a hidden
17
+ * input, and its own computed visibility is not hidden. Where the browser
18
+ * offers `checkVisibility`, that must agree too.
19
+ */
20
+ export declare function isElementVisible(element: Element, probe?: ElementStateProbe): boolean;
21
+ /** Whether the element accepts input: not disabled (natively, through a disabled fieldset or control), not `aria-disabled`, not `inert`. */
22
+ export declare function isElementEnabled(element: Element): boolean;
23
+ /** The element's bounds, rounded to whole pixels, with the offset of the frames it sits in added. */
24
+ export declare function elementRect(element: Element, probe?: ElementStateProbe, offset?: WebRect): WebRect;
25
+ /** Every element under a root, in document order (the root element itself included). */
26
+ export declare function elementsUnder(root: WebSearchRoot): Element[];
27
+ export { SENSITIVE_MARKERS };
28
+ /** True when a field name reads like a secret (the capture rule for element names). */
29
+ export declare function isSecretFieldName(name: string): boolean;
30
+ /**
31
+ * True when the element holds or shows data that must never leave the page in
32
+ * a snapshot or a report: password, one-time-code and card fields, fields named
33
+ * like secrets, and any element (or descendant of one) marked sensitive.
34
+ */
35
+ export declare function isSensitiveElement(element: Element): boolean;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `@burdenoff/ui-engine/target`: the multi-method web target resolver (plan
3
+ * P1-01). It works on any DOM (a content script, a CDP isolated world, a test
4
+ * DOM or a document rebuilt from a tree snapshot) and reads no globals.
5
+ */
6
+ export * from './types.js';
7
+ export { hasSensitiveMarker } from './markers.js';
8
+ export { MAX_COMPARED_TEXT, clip, containsText, editDistance, normaliseText, sameText, textSimilarity, } from './text.js';
9
+ export { MAX_NAME_LENGTH, MAX_VISIBLE_TEXT, type TextProbe, accessibleName, isTypedContent, labelName, matchesRoleAndName, roleOf, visibleText, } from './aria.js';
10
+ export { type ElementStateProbe, SENSITIVE_MARKERS, type WebSearchRoot, elementRect, elementsUnder, isElementEnabled, isElementVisible, isSecretFieldName, isSensitiveElement, parentAcrossShadow, } from './dom.js';
11
+ export { ANCHOR_MARGIN_PX, DEFAULT_FUZZY_THRESHOLD, FUZZY_MARGIN, INTERACTIVE_ROLES, MAX_XPATH_RESULTS, type MethodMatch, type ScoredElement, matchMethod, relationDistance, } from './methods.js';
12
+ export { type ResolveWebTargetOptions, type WebFrameEntry, describeCandidate, enterFrames, resolveWebTarget, } from './resolve.js';
13
+ export { DEFAULT_SNAPSHOT_MAX_NODES, type HydratedSnapshot, MAX_SNAPSHOT_DEPTH, MAX_SNAPSHOT_TEXT, type SerializeTreeSnapshotOptions, UI_TREE_SNAPSHOT_VERSION, type UiTreeSnapshot, type UiTreeSnapshotChild, type UiTreeSnapshotNode, hydrateTreeSnapshot, serializeTreeSnapshot, snapshotUrl, } from './snapshot.js';
@@ -0,0 +1,18 @@
1
+ /** Attributes a page or an author sets to mark an element, and everything inside it, as sensitive. */
2
+ export declare const SENSITIVE_MARKERS: readonly ["data-fg-sensitive", "data-sensitive", "data-private"];
3
+ /** True when the element itself carries a sensitive marker. */
4
+ export declare function hasSensitiveMarker(element: Element): boolean;
5
+ /**
6
+ * The slot an element or a text node renders in: `assignedSlot` where the DOM has it, else
7
+ * the slot of the parent's open shadow root that lists the element among its
8
+ * assigned nodes.
9
+ */
10
+ export declare function assignedSlotOf(element: Element | Text): Element | null;
11
+ /**
12
+ * The element a node hangs from in the rendered (flat) tree: its assigned slot,
13
+ * its parent, a shadow root's host, or the frame element of a same-origin frame
14
+ * document.
15
+ */
16
+ export declare function containerOf(element: Element): Element | null;
17
+ /** True when the element or any ancestor, across shadow roots and same-origin frames, carries a sensitive marker. */
18
+ export declare function isMarkedSensitive(element: Element): boolean;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * One matcher per target method (spec 05 section 3.1). A matcher finds the
3
+ * elements a method describes under a search root; the resolver then filters
4
+ * them by state and decides whether exactly one is left.
5
+ *
6
+ * Matchers that only filter (`role`, `css`, `testId`, `xpath`, `text`) return a
7
+ * list in document order. Matchers that rank (`fuzzy` by similarity, the
8
+ * geometric `anchor` relations by distance) return scores; the resolver takes
9
+ * the best one only when it is clearly better than the next.
10
+ */
11
+ import type { UiAnchorMethod, UiTargetMethod } from '../script/types.js';
12
+ import { type ElementStateProbe, type WebSearchRoot } from './dom.js';
13
+ import type { WebRect } from './types.js';
14
+ /** Default lowest similarity of the fuzzy method (the schema documents 0.8). */
15
+ export declare const DEFAULT_FUZZY_THRESHOLD = 0.8;
16
+ /** How much better than the runner-up the best fuzzy score must be; closer scores are ambiguous. */
17
+ export declare const FUZZY_MARGIN = 0.05;
18
+ /** How much nearer than the runner-up (in CSS pixels) the best anchored element must be; closer is ambiguous. */
19
+ export declare const ANCHOR_MARGIN_PX = 4;
20
+ /** Most elements an XPath result is read for. */
21
+ export declare const MAX_XPATH_RESULTS = 1000;
22
+ /** Roles an anchor method considers when it names no role: the controls a step acts on. */
23
+ export declare const INTERACTIVE_ROLES: Set<string>;
24
+ /** A scored element: higher scores are better (similarity, or minus a distance). */
25
+ export interface ScoredElement {
26
+ element: Element;
27
+ score: number;
28
+ }
29
+ export type MethodMatch = {
30
+ kind: 'list';
31
+ elements: Element[];
32
+ nth?: number;
33
+ overflow?: boolean;
34
+ } | {
35
+ kind: 'ranked';
36
+ scored: ScoredElement[];
37
+ margin: number;
38
+ } | {
39
+ kind: 'invalid';
40
+ } | {
41
+ kind: 'unsupported';
42
+ };
43
+ export interface MatchContext {
44
+ root: WebSearchRoot;
45
+ probe?: ElementStateProbe;
46
+ /** The resolver's state filter. A text hit that fails it does not hide a matching ancestor. */
47
+ keep?: (element: Element) => boolean;
48
+ }
49
+ /** Distance from the anchor to the element along the relation, or null when the element is not in that relation. */
50
+ export declare function relationDistance(relation: UiAnchorMethod['relation'], anchor: WebRect, element: WebRect): number | null;
51
+ /** Run one method under the root. */
52
+ export declare function matchMethod(method: UiTargetMethod, context: MatchContext): MethodMatch;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The multi-method web target resolver (spec 05 section 3, plan P1-01).
3
+ *
4
+ * A target is an ordered list of methods. The resolver follows the frame and
5
+ * shadow-root chain, then tries the methods in order and uses the first that
6
+ * finds exactly one element in the required state. It records what every
7
+ * method found, and reports a fallback when a later method succeeded.
8
+ *
9
+ * It never picks the first of several elements silently. Several matches are
10
+ * resolved only by a rule the target states: an explicit `nth` on the `role`
11
+ * and `text` methods, or a clearly best score for `fuzzy` (similarity) and the
12
+ * spatial `anchor` relations (distance). Otherwise the method is ambiguous and
13
+ * the next method is tried; when no method finds exactly one element, the
14
+ * result is `ELEMENT_AMBIGUOUS` with up to five candidates. A failed resolution
15
+ * carries no element, so a caller has nothing to act on.
16
+ *
17
+ * Page content is untrusted. It is only compared here; candidate names are cut
18
+ * to 200 characters and sensitive elements report no name.
19
+ */
20
+ import type { UiTarget, UiTargetMethod } from '../script/types.js';
21
+ import { type ElementStateProbe, type WebSearchRoot } from './dom.js';
22
+ import { type WebCandidate, type WebElementState, type WebFrameProblem, type WebRect, type WebTargetResolution } from './types.js';
23
+ export interface ResolveWebTargetOptions extends ElementStateProbe {
24
+ /** What a matched element must be. Absent means `interactable`. */
25
+ state?: WebElementState;
26
+ }
27
+ /** Where the frame chain led: the search root inside it, the frames' offset, and whether a frame is hidden. */
28
+ export interface WebFrameEntry {
29
+ root: WebSearchRoot;
30
+ offset: WebRect;
31
+ /** A frame element of the chain is not visible, so nothing inside it is. */
32
+ hidden: boolean;
33
+ /** A frame element of the chain does not accept input (inert, aria-disabled), so nothing inside it does. */
34
+ disabled: boolean;
35
+ }
36
+ /** Follow `target.frame`: each selector names one iframe (entered through its document) or one open shadow host. */
37
+ export declare function enterFrames(root: WebSearchRoot, chain: readonly string[] | undefined, probe?: ElementStateProbe): WebFrameEntry | WebFrameProblem;
38
+ /** The report form of an element: role, name (cut, empty for sensitive elements), bounds and the matching method. */
39
+ export declare function describeCandidate(element: Element, method: UiTargetMethod, methodIndex: number, offset: WebRect, probe?: ElementStateProbe): WebCandidate;
40
+ /**
41
+ * Resolve a target under a root (a document, a shadow root or an element).
42
+ * Returns the element with the method that found it, or a failure with the
43
+ * error code, the attempts and, for an ambiguous or non-interactable target,
44
+ * up to five candidates.
45
+ */
46
+ export declare function resolveWebTarget(root: WebSearchRoot, target: UiTarget, options?: ResolveWebTargetOptions): WebTargetResolution<Element>;
@@ -0,0 +1,57 @@
1
+ import { type ElementStateProbe } from './dom.js';
2
+ export declare const UI_TREE_SNAPSHOT_VERSION = 1;
3
+ /** Default most nodes (elements and texts) a snapshot keeps; the rest is cut and `truncated` is set. */
4
+ export declare const DEFAULT_SNAPSHOT_MAX_NODES = 5000;
5
+ /** Deepest element nesting kept. */
6
+ export declare const MAX_SNAPSHOT_DEPTH = 64;
7
+ /** Longest text or attribute value kept. */
8
+ export declare const MAX_SNAPSHOT_TEXT = 500;
9
+ /** A snapshot element: `t` tag, `a` attributes, `c` children, `s` open shadow-root children, `f` frame document, `r` bounds, `h` hidden. */
10
+ export interface UiTreeSnapshotNode {
11
+ t: string;
12
+ a?: Record<string, string>;
13
+ c?: UiTreeSnapshotChild[];
14
+ s?: UiTreeSnapshotChild[];
15
+ f?: UiTreeSnapshotNode;
16
+ r?: [number, number, number, number];
17
+ h?: 1;
18
+ }
19
+ /** A child is an element or a text. */
20
+ export type UiTreeSnapshotChild = UiTreeSnapshotNode | string;
21
+ export interface UiTreeSnapshot {
22
+ snapshotVersion: typeof UI_TREE_SNAPSHOT_VERSION;
23
+ /** The page URL without query or fragment. */
24
+ url: string;
25
+ title: string;
26
+ viewport: {
27
+ width: number;
28
+ height: number;
29
+ };
30
+ /** The `html` element (its `head` is left out). */
31
+ root: UiTreeSnapshotNode;
32
+ nodeCount: number;
33
+ truncated: boolean;
34
+ }
35
+ export interface SerializeTreeSnapshotOptions extends ElementStateProbe {
36
+ /** Most nodes kept. Absent means `DEFAULT_SNAPSHOT_MAX_NODES`. */
37
+ maxNodes?: number;
38
+ }
39
+ /**
40
+ * A URL as a snapshot keeps it: http(s) and relative URLs only, without user
41
+ * information, query or fragment, cut after a reset-style path segment, and
42
+ * with recognisable credentials replaced. Anything else is dropped (null).
43
+ */
44
+ export declare function snapshotUrl(raw: string): string | null;
45
+ /** Serialise a live document into a value-free tree snapshot. */
46
+ export declare function serializeTreeSnapshot(document: Document, options?: SerializeTreeSnapshotOptions): UiTreeSnapshot;
47
+ /** The result of hydration: the probe that reports recorded bounds and visibility to `resolveWebTarget`. */
48
+ export interface HydratedSnapshot {
49
+ probe: Required<ElementStateProbe>;
50
+ }
51
+ /**
52
+ * Rebuild a snapshot into an empty document (its current content is replaced)
53
+ * and return the probe to resolve targets against it. The document must be
54
+ * inert (a `DOMParser` document or a server-side DOM with scripts off); the
55
+ * snapshot holds no scripts or handlers in any case.
56
+ */
57
+ export declare function hydrateTreeSnapshot(document: Document, snapshot: UiTreeSnapshot): HydratedSnapshot;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Text comparison for target methods: the same normalisation the Stewards
3
+ * resolver uses (NFKC, whitespace collapsed, trimmed, case-insensitive), plus a
4
+ * similarity score for the fuzzy method.
5
+ */
6
+ /** Longest text compared by the fuzzy method; longer names are cut before scoring. */
7
+ export declare const MAX_COMPARED_TEXT = 256;
8
+ /** NFKC, whitespace collapsed, trimmed and lower-cased. */
9
+ export declare function normaliseText(value: string | null | undefined): string;
10
+ /** True when two texts are equal after normalisation. */
11
+ export declare function sameText(a: string | null | undefined, b: string | null | undefined): boolean;
12
+ /** True when `haystack` contains `needle` after normalisation. An empty needle never matches. */
13
+ export declare function containsText(haystack: string | null | undefined, needle: string | null | undefined): boolean;
14
+ /** Levenshtein edit distance (insert, delete, substitute), with one row of memory. */
15
+ export declare function editDistance(a: string, b: string): number;
16
+ /**
17
+ * Similarity of two texts between 0 and 1: one minus the edit distance over the
18
+ * longer length, after normalisation. Two empty texts score 0, so an unnamed
19
+ * element never matches a fuzzy name.
20
+ */
21
+ export declare function textSimilarity(a: string | null | undefined, b: string | null | undefined): number;
22
+ /** Cut a text for reports (candidates, attempts); page text is untrusted and never grows a report unbounded. */
23
+ export declare function clip(value: string, max: number): string;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Types of the multi-method web target resolver (spec 05 section 3, plan P1-01).
3
+ *
4
+ * Everything a resolution reports is plain JSON (no element references), so the
5
+ * DOM runtime can hand it across an isolated-world or CDP boundary unchanged.
6
+ */
7
+ import type { UiTargetMethodKind } from '../script/types.js';
8
+ /** Bounds in CSS pixels, relative to the top viewport (frame offsets added). */
9
+ export interface WebRect {
10
+ x: number;
11
+ y: number;
12
+ width: number;
13
+ height: number;
14
+ }
15
+ /** The error codes a resolution can end with (spec 05 section 10). The interpreter maps them to node error families. */
16
+ export declare const WEB_TARGET_ERROR_CODES: readonly ["ELEMENT_NOT_FOUND", "ELEMENT_AMBIGUOUS", "ELEMENT_NOT_INTERACTABLE"];
17
+ export type WebTargetErrorCode = (typeof WEB_TARGET_ERROR_CODES)[number];
18
+ /** Most candidates an ambiguous resolution lists (spec 19 section 11). */
19
+ export declare const MAX_CANDIDATES = 5;
20
+ /** Longest candidate name reported; page text is untrusted and is cut (threat review U7). */
21
+ export declare const MAX_CANDIDATE_NAME = 200;
22
+ /**
23
+ * What an element must be for a method to count it:
24
+ * - `interactable`: visible and enabled (the default, for steps that act);
25
+ * - `visible`: visible, enabled or not (for steps that read);
26
+ * - `attached`: present in the document, visible or not.
27
+ */
28
+ export type WebElementState = 'interactable' | 'visible' | 'attached';
29
+ /**
30
+ * What one method found:
31
+ * - `found`: exactly one element;
32
+ * - `none`: no element in the required state;
33
+ * - `ambiguous`: several, and the method had no rule to pick one;
34
+ * - `notInteractable`: elements were found but none is visible and enabled;
35
+ * - `invalid`: the method cannot run (a selector the browser rejects, an unusable attribute name);
36
+ * - `unsupported`: the page cannot run this method (no XPath engine, for example);
37
+ * - `disabled`: the method is switched off in the target;
38
+ * - `notTried`: an earlier method already found the element.
39
+ */
40
+ export type WebMethodOutcome = 'found' | 'none' | 'ambiguous' | 'notInteractable' | 'invalid' | 'unsupported' | 'disabled' | 'notTried';
41
+ /** The result of one method, in target order. */
42
+ export interface WebMethodAttempt {
43
+ index: number;
44
+ method: UiTargetMethodKind;
45
+ outcome: WebMethodOutcome;
46
+ /** Elements the method matched in the required state. */
47
+ matches: number;
48
+ }
49
+ /** One element a method matched, as an ambiguity report lists it. */
50
+ export interface WebCandidate {
51
+ role: string;
52
+ /** The accessible name, cut to `MAX_CANDIDATE_NAME`. Sensitive elements report an empty name. */
53
+ name: string;
54
+ bounds: WebRect;
55
+ /** The method that matched this element. */
56
+ method: UiTargetMethodKind;
57
+ /** The position of that method in the target. */
58
+ methodIndex: number;
59
+ }
60
+ /** Why the frame and shadow-root chain could not be followed. */
61
+ export interface WebFrameProblem {
62
+ /** Position in `target.frame` of the selector that failed. */
63
+ index: number;
64
+ reason: 'notFound' | 'ambiguous' | 'invalid' | 'notAFrame' | 'inaccessible';
65
+ }
66
+ /** A resolution that found exactly one element. */
67
+ export interface WebTargetFound<E> {
68
+ status: 'found';
69
+ element: E;
70
+ method: UiTargetMethodKind;
71
+ methodIndex: number;
72
+ /** True when a method other than the first enabled one found the element (spec 05: method drift is reported). */
73
+ fallback: boolean;
74
+ candidate: WebCandidate;
75
+ attempts: WebMethodAttempt[];
76
+ }
77
+ /** A resolution that did not find exactly one element. Nothing may be acted on. */
78
+ export interface WebTargetFailed {
79
+ status: 'failed';
80
+ code: WebTargetErrorCode;
81
+ /** Up to `MAX_CANDIDATES` elements, for `ELEMENT_AMBIGUOUS` and `ELEMENT_NOT_INTERACTABLE`; empty for `ELEMENT_NOT_FOUND`. */
82
+ candidates: WebCandidate[];
83
+ /** How many elements the reported method matched (may exceed the candidates listed). */
84
+ candidateCount: number;
85
+ attempts: WebMethodAttempt[];
86
+ frame?: WebFrameProblem;
87
+ }
88
+ export type WebTargetResolution<E = Element> = WebTargetFound<E> | WebTargetFailed;
@@ -0,0 +1,2 @@
1
+ /** `@burdenoff/ui-engine/target`: the multi-method web target resolver and tree snapshots. */
2
+ export * from './target/index.js';
package/dist/target.js ADDED
@@ -0,0 +1,92 @@
1
+ import {
2
+ WEB_TARGET_ERROR_CODES2,
3
+ MAX_CANDIDATES2,
4
+ MAX_CANDIDATE_NAME2,
5
+ SENSITIVE_MARKERS2,
6
+ hasSensitiveMarker2,
7
+ MAX_COMPARED_TEXT2,
8
+ normaliseText2,
9
+ sameText2,
10
+ containsText2,
11
+ editDistance2,
12
+ textSimilarity2,
13
+ clip2,
14
+ MAX_NAME_LENGTH3,
15
+ MAX_VISIBLE_TEXT2,
16
+ roleOf2,
17
+ isTypedContent2,
18
+ accessibleName2,
19
+ labelName2,
20
+ visibleText2,
21
+ matchesRoleAndName2,
22
+ parentAcrossShadow2,
23
+ isElementVisible2,
24
+ isElementEnabled2,
25
+ elementRect2,
26
+ elementsUnder2,
27
+ isSecretFieldName2,
28
+ isSensitiveElement2,
29
+ DEFAULT_FUZZY_THRESHOLD2,
30
+ FUZZY_MARGIN2,
31
+ ANCHOR_MARGIN_PX2,
32
+ MAX_XPATH_RESULTS2,
33
+ INTERACTIVE_ROLES2,
34
+ relationDistance2,
35
+ matchMethod2,
36
+ enterFrames2,
37
+ describeCandidate2,
38
+ resolveWebTarget2,
39
+ UI_TREE_SNAPSHOT_VERSION2,
40
+ DEFAULT_SNAPSHOT_MAX_NODES2,
41
+ MAX_SNAPSHOT_DEPTH2,
42
+ MAX_SNAPSHOT_TEXT2,
43
+ snapshotUrl2,
44
+ serializeTreeSnapshot2,
45
+ hydrateTreeSnapshot2
46
+ } from "./index-q1b0j9yr.js";
47
+ export {
48
+ ANCHOR_MARGIN_PX2 as ANCHOR_MARGIN_PX,
49
+ DEFAULT_FUZZY_THRESHOLD2 as DEFAULT_FUZZY_THRESHOLD,
50
+ DEFAULT_SNAPSHOT_MAX_NODES2 as DEFAULT_SNAPSHOT_MAX_NODES,
51
+ FUZZY_MARGIN2 as FUZZY_MARGIN,
52
+ INTERACTIVE_ROLES2 as INTERACTIVE_ROLES,
53
+ MAX_CANDIDATES2 as MAX_CANDIDATES,
54
+ MAX_CANDIDATE_NAME2 as MAX_CANDIDATE_NAME,
55
+ MAX_COMPARED_TEXT2 as MAX_COMPARED_TEXT,
56
+ MAX_NAME_LENGTH3 as MAX_NAME_LENGTH,
57
+ MAX_SNAPSHOT_DEPTH2 as MAX_SNAPSHOT_DEPTH,
58
+ MAX_SNAPSHOT_TEXT2 as MAX_SNAPSHOT_TEXT,
59
+ MAX_VISIBLE_TEXT2 as MAX_VISIBLE_TEXT,
60
+ MAX_XPATH_RESULTS2 as MAX_XPATH_RESULTS,
61
+ SENSITIVE_MARKERS2 as SENSITIVE_MARKERS,
62
+ UI_TREE_SNAPSHOT_VERSION2 as UI_TREE_SNAPSHOT_VERSION,
63
+ WEB_TARGET_ERROR_CODES2 as WEB_TARGET_ERROR_CODES,
64
+ accessibleName2 as accessibleName,
65
+ clip2 as clip,
66
+ containsText2 as containsText,
67
+ describeCandidate2 as describeCandidate,
68
+ editDistance2 as editDistance,
69
+ elementRect2 as elementRect,
70
+ elementsUnder2 as elementsUnder,
71
+ enterFrames2 as enterFrames,
72
+ hasSensitiveMarker2 as hasSensitiveMarker,
73
+ hydrateTreeSnapshot2 as hydrateTreeSnapshot,
74
+ isElementEnabled2 as isElementEnabled,
75
+ isElementVisible2 as isElementVisible,
76
+ isSecretFieldName2 as isSecretFieldName,
77
+ isSensitiveElement2 as isSensitiveElement,
78
+ isTypedContent2 as isTypedContent,
79
+ labelName2 as labelName,
80
+ matchMethod2 as matchMethod,
81
+ matchesRoleAndName2 as matchesRoleAndName,
82
+ normaliseText2 as normaliseText,
83
+ parentAcrossShadow2 as parentAcrossShadow,
84
+ relationDistance2 as relationDistance,
85
+ resolveWebTarget2 as resolveWebTarget,
86
+ roleOf2 as roleOf,
87
+ sameText2 as sameText,
88
+ serializeTreeSnapshot2 as serializeTreeSnapshot,
89
+ snapshotUrl2 as snapshotUrl,
90
+ textSimilarity2 as textSimilarity,
91
+ visibleText2 as visibleText
92
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * RPA playground fixture `ambiguous`: two identical "Save" buttons (same tag,
3
+ * class and name) in two sections, and a visible counter of saved changes.
4
+ * A step that targets "the Save button" must fail with both candidates listed
5
+ * and must leave the counter at 0. The inline script only counts clicks.
6
+ */
7
+ export declare const AMBIGUOUS_HTML = "<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"robots\" content=\"noindex, nofollow\">\n<title>Invoice editor - RPA playground</title>\n</head>\n<body>\n<main>\n <h1>Invoice editor</h1>\n <section id=\"header-section\">\n <h2>Invoice header</h2>\n <label for=\"customer\">Customer</label>\n <input id=\"customer\" name=\"customer\" type=\"text\">\n <button class=\"save\" type=\"button\">Save</button>\n </section>\n <section id=\"lines-section\">\n <h2>Line items</h2>\n <label for=\"line-1\">Line 1</label>\n <input id=\"line-1\" name=\"line1\" type=\"text\">\n <button class=\"save\" type=\"button\">Save</button>\n </section>\n <p>Saved changes: <output id=\"saved-count\" aria-label=\"Saved changes\">0</output></p>\n</main>\n<script>\n for (const button of document.querySelectorAll('button.save')) {\n button.addEventListener('click', () => {\n const counter = document.getElementById('saved-count');\n counter.textContent = String(Number(counter.textContent) + 1);\n });\n }\n</script>\n</body>\n</html>\n";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * RPA playground fixture `iframe`: a payment form inside a same-origin frame.
3
+ * Targets reach it through `frame: ['iframe#payment-frame']`.
4
+ */
5
+ export declare const IFRAME_INNER_HTML = "<!doctype html>\n<html lang=\"en\">\n<head><meta charset=\"utf-8\"><title>Payment</title></head>\n<body>\n <form aria-label=\"Payment\">\n <label for=\"amount\">Amount</label>\n <input id=\"amount\" name=\"amount\" type=\"text\">\n <button id=\"pay\" type=\"button\">Pay now</button>\n </form>\n</body>\n</html>\n";
6
+ export declare const IFRAME_HTML: string;