@burdenoff/ui-engine 2026.1127.3 → 2026.1127.5

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 (65) hide show
  1. package/README.md +71 -5
  2. package/dist/analyze/analyze.d.ts +19 -0
  3. package/dist/analyze/context.d.ts +40 -0
  4. package/dist/analyze/index.d.ts +10 -0
  5. package/dist/analyze/messages.d.ts +39 -0
  6. package/dist/analyze/rules/fixed-wait.d.ts +6 -0
  7. package/dist/analyze/rules/hardware-input.d.ts +2 -0
  8. package/dist/analyze/rules/index.d.ts +3 -0
  9. package/dist/analyze/rules/inline-target.d.ts +2 -0
  10. package/dist/analyze/rules/masked-value.d.ts +8 -0
  11. package/dist/analyze/rules/no-cleanup.d.ts +2 -0
  12. package/dist/analyze/rules/plain-text-secret.d.ts +2 -0
  13. package/dist/analyze/rules/rule.d.ts +15 -0
  14. package/dist/analyze/rules/secret-origin.d.ts +7 -0
  15. package/dist/analyze/rules/sensitive-screenshot.d.ts +2 -0
  16. package/dist/analyze/rules/single-method-target.d.ts +2 -0
  17. package/dist/analyze/rules/unknown-variable.d.ts +2 -0
  18. package/dist/analyze/rules/unused-value.d.ts +2 -0
  19. package/dist/analyze/sensitive.d.ts +14 -0
  20. package/dist/analyze/types.d.ts +66 -0
  21. package/dist/analyze.d.ts +2 -0
  22. package/dist/analyze.js +26 -0
  23. package/dist/dom-runtime.iife.js +1 -1
  24. package/dist/dom-runtime.js +27 -532
  25. package/dist/drivers/dom-driver.d.ts +44 -0
  26. package/dist/drivers/index.d.ts +7 -0
  27. package/dist/drivers/snapshot-driver.d.ts +59 -0
  28. package/dist/drivers.d.ts +2 -0
  29. package/dist/drivers.js +172 -0
  30. package/dist/index-21hvbvx1.js +340 -0
  31. package/dist/{index-q1b0j9yr.js → index-5k26keah.js} +58 -592
  32. package/dist/index-77pcz6n3.js +303 -0
  33. package/dist/index-8w0f6rsz.js +402 -0
  34. package/dist/index-9s5nphx0.js +99 -0
  35. package/dist/index-c88tvyj1.js +743 -0
  36. package/dist/index-ct2xctrq.js +229 -0
  37. package/dist/index-g7724awk.js +224 -0
  38. package/dist/index-gvavb597.js +195 -0
  39. package/dist/index-r2a9rftv.js +1740 -0
  40. package/dist/index-s7qdecev.js +489 -0
  41. package/dist/index-vg8r40y7.js +220 -0
  42. package/dist/index-xner4tgb.js +810 -0
  43. package/dist/index-ycs2bz1a.js +589 -0
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.js +163 -49
  46. package/dist/interpret/compile.d.ts +58 -0
  47. package/dist/interpret/driver.d.ts +171 -0
  48. package/dist/interpret/errors.d.ts +194 -0
  49. package/dist/interpret/events.d.ts +73 -0
  50. package/dist/interpret/expr.d.ts +35 -0
  51. package/dist/interpret/index.d.ts +13 -0
  52. package/dist/interpret/run.d.ts +77 -0
  53. package/dist/interpret.d.ts +2 -0
  54. package/dist/interpret.js +84 -0
  55. package/dist/script/adapters/browser-action-contract.d.ts +5 -2
  56. package/dist/script/limits.d.ts +2 -0
  57. package/dist/script.js +60 -50
  58. package/dist/target/index.d.ts +1 -1
  59. package/dist/target/resolve.d.ts +18 -1
  60. package/dist/target.js +23 -19
  61. package/dist/testing/fake-web-driver.d.ts +28 -0
  62. package/dist/testing/index.d.ts +3 -2
  63. package/dist/testing.js +55 -0
  64. package/package.json +15 -3
  65. package/dist/index-zwrxw3zp.js +0 -1988
@@ -0,0 +1,229 @@
1
+ import {
2
+ READ_ACTIONS2,
3
+ POINTER_ACTIONS2,
4
+ performDomAction2
5
+ } from "./index-77pcz6n3.js";
6
+ import {
7
+ resolveWebTarget2,
8
+ serializeTreeSnapshot2
9
+ } from "./index-5k26keah.js";
10
+
11
+ // src/dom-runtime/runtime.ts
12
+ var DOM_RUNTIME_VERSION2 = 1;
13
+ var DOM_RUNTIME_GLOBAL2 = "__burdenoffUiRuntime";
14
+ var MAX_HIGHLIGHT_MS2 = 60000;
15
+ var HIGHLIGHT_HOST_TAG2 = "fg-ui-highlight";
16
+ var METHOD_KINDS = new Set(["role", "css", "testId", "xpath", "fuzzy", "anchor", "text"]);
17
+ function isRuntimeTarget2(value) {
18
+ if (!value || typeof value !== "object")
19
+ return false;
20
+ const target = value;
21
+ if (!Array.isArray(target.methods) || target.methods.length === 0 || target.methods.length > 8)
22
+ return false;
23
+ if (target.frame !== undefined && !(Array.isArray(target.frame) && target.frame.every((item) => typeof item === "string"))) {
24
+ return false;
25
+ }
26
+ return target.methods.every((method) => !!method && typeof method === "object" && METHOD_KINDS.has(String(method.kind)));
27
+ }
28
+ function invalidTarget() {
29
+ return { status: "failed", code: "ELEMENT_NOT_FOUND", candidates: [], candidateCount: 0, attempts: [] };
30
+ }
31
+ function withoutElement(found) {
32
+ return {
33
+ status: found.status,
34
+ method: found.method,
35
+ methodIndex: found.methodIndex,
36
+ fallback: found.fallback,
37
+ candidate: found.candidate,
38
+ attempts: found.attempts
39
+ };
40
+ }
41
+ function frameElementOf(document) {
42
+ try {
43
+ return document.defaultView?.frameElement ?? null;
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+ function coveredAt(current, x, y, labels) {
49
+ const root = current.getRootNode();
50
+ if (typeof root.elementFromPoint !== "function")
51
+ return null;
52
+ const top = root.elementFromPoint(x, y);
53
+ if (!top)
54
+ return "offscreen";
55
+ if (top === current || current.contains(top))
56
+ return null;
57
+ return labels.some((label) => label.contains(top)) ? null : "covered";
58
+ }
59
+ function coverage(element, rect) {
60
+ let x = rect.x + rect.width / 2;
61
+ let y = rect.y + rect.height / 2;
62
+ const labels = Array.from(element.labels ?? []);
63
+ let current = element;
64
+ for (let hop = 0;hop < 32; hop += 1) {
65
+ const blocked = coveredAt(current, x, y, hop === 0 ? labels : []);
66
+ if (blocked)
67
+ return blocked;
68
+ const root = current.getRootNode();
69
+ if (root && "host" in root) {
70
+ current = root.host;
71
+ continue;
72
+ }
73
+ const frame = frameElementOf(current.ownerDocument);
74
+ if (!frame)
75
+ return null;
76
+ const box = frame.getBoundingClientRect();
77
+ x += box.x + frame.clientLeft;
78
+ y += box.y + frame.clientTop;
79
+ current = frame;
80
+ }
81
+ return null;
82
+ }
83
+ function outsideViewport(element, rect) {
84
+ const view = element.ownerDocument.defaultView;
85
+ if (!view)
86
+ return false;
87
+ const x = rect.x + rect.width / 2;
88
+ const y = rect.y + rect.height / 2;
89
+ return x < 0 || y < 0 || x >= view.innerWidth || y >= view.innerHeight;
90
+ }
91
+ function pointerBlock(element) {
92
+ const view = element.ownerDocument.defaultView;
93
+ if (view && view.getComputedStyle(element).pointerEvents === "none")
94
+ return "noPointerEvents";
95
+ let rect = element.getBoundingClientRect();
96
+ if (rect.width <= 0 || rect.height <= 0)
97
+ return null;
98
+ if (outsideViewport(element, rect) && typeof element.scrollIntoView === "function") {
99
+ element.scrollIntoView({ block: "center", inline: "center" });
100
+ rect = element.getBoundingClientRect();
101
+ }
102
+ return coverage(element, rect);
103
+ }
104
+ function createDomRuntime2(document, options = {}) {
105
+ const root = options.root ?? document;
106
+ const probe = {
107
+ ...options.rectOf ? { rectOf: options.rectOf } : {},
108
+ ...options.isVisible ? { isVisible: options.isVisible } : {}
109
+ };
110
+ let overlay = null;
111
+ let clearTimer = null;
112
+ const clearHighlight = () => {
113
+ if (clearTimer !== null) {
114
+ clearTimeout(clearTimer);
115
+ clearTimer = null;
116
+ }
117
+ overlay?.remove();
118
+ overlay = null;
119
+ };
120
+ const resolveRaw = (target, state) => {
121
+ clearHighlight();
122
+ return resolveWebTarget2(root, target, { ...probe, ...state ? { state } : {} });
123
+ };
124
+ const resolve = (target, resolveOptions = {}) => {
125
+ if (!isRuntimeTarget2(target))
126
+ return invalidTarget();
127
+ const result = resolveRaw(target, resolveOptions.state);
128
+ return result.status === "found" ? withoutElement(result) : result;
129
+ };
130
+ const act = (target, action, actOptions = {}) => {
131
+ if (!action || typeof action !== "object" || typeof action.kind !== "string") {
132
+ return { ok: false, code: "INVALID_ACTION" };
133
+ }
134
+ if (!isRuntimeTarget2(target)) {
135
+ return { ok: false, code: "ELEMENT_NOT_FOUND", resolution: invalidTarget() };
136
+ }
137
+ const state = actOptions.state ?? (READ_ACTIONS2.has(action.kind) ? "visible" : "interactable");
138
+ const result = resolveRaw(target, state);
139
+ if (result.status !== "found") {
140
+ if (action.kind === "exists" && result.code === "ELEMENT_NOT_FOUND") {
141
+ return { ok: true, value: false, resolution: result };
142
+ }
143
+ return { ok: false, code: result.code, resolution: result };
144
+ }
145
+ const resolution = withoutElement(result);
146
+ const blocked = POINTER_ACTIONS2.has(action.kind) ? pointerBlock(result.element) : null;
147
+ if (blocked) {
148
+ return {
149
+ ok: false,
150
+ code: "ELEMENT_NOT_INTERACTABLE",
151
+ reason: blocked,
152
+ resolution: {
153
+ status: "failed",
154
+ code: "ELEMENT_NOT_INTERACTABLE",
155
+ candidates: [result.candidate],
156
+ candidateCount: 1,
157
+ attempts: result.attempts
158
+ }
159
+ };
160
+ }
161
+ const outcome = performDomAction2(result.element, action);
162
+ if (!outcome.ok)
163
+ return { ok: false, code: outcome.problem, resolution };
164
+ return outcome.value === undefined ? { ok: true, resolution } : { ok: true, resolution, value: outcome.value };
165
+ };
166
+ const drawBoxes = (boxes, label, numbered) => {
167
+ const host = document.createElement(HIGHLIGHT_HOST_TAG2);
168
+ host.setAttribute("aria-hidden", "true");
169
+ host.setAttribute("style", "all: initial; position: fixed; inset: 0; pointer-events: none; z-index: 2147483647;");
170
+ const shadow = host.attachShadow({ mode: "closed" });
171
+ boxes.forEach((box, index) => {
172
+ const frame = document.createElement("div");
173
+ frame.setAttribute("style", `position: fixed; left: ${box.bounds.x - 3}px; top: ${box.bounds.y - 3}px; width: ${box.bounds.width + 6}px; height: ${box.bounds.height + 6}px; outline: 3px solid Highlight; border-radius: 4px; box-sizing: border-box;`);
174
+ const caption = numbered ? `${index + 1}${label ? ` ${label}` : ""}` : label;
175
+ if (caption) {
176
+ const tag = document.createElement("span");
177
+ tag.textContent = caption.slice(0, 120);
178
+ tag.setAttribute("style", "position: absolute; left: 0; top: 100%; margin-top: 4px; padding: 2px 6px; font: 600 11px system-ui, sans-serif; background: Highlight; color: HighlightText; border-radius: 3px; white-space: nowrap;");
179
+ frame.appendChild(tag);
180
+ }
181
+ shadow.appendChild(frame);
182
+ });
183
+ document.documentElement.appendChild(host);
184
+ overlay = host;
185
+ };
186
+ const highlight = (target, highlightOptions = {}) => {
187
+ if (!isRuntimeTarget2(target))
188
+ return invalidTarget();
189
+ const result = resolveRaw(target, highlightOptions.state ?? "visible");
190
+ if (result.status === "found")
191
+ drawBoxes([result.candidate], highlightOptions.label, false);
192
+ else if (result.candidates.length > 0)
193
+ drawBoxes(result.candidates, highlightOptions.label, true);
194
+ const duration = Math.min(MAX_HIGHLIGHT_MS2, Math.max(0, Number(highlightOptions.durationMs ?? 0) || 0));
195
+ if (overlay && duration > 0)
196
+ clearTimer = setTimeout(clearHighlight, duration);
197
+ return result.status === "found" ? withoutElement(result) : result;
198
+ };
199
+ return {
200
+ version: DOM_RUNTIME_VERSION2,
201
+ resolve,
202
+ act,
203
+ highlight,
204
+ clearHighlight,
205
+ snapshot: (snapshotOptions = {}) => {
206
+ clearHighlight();
207
+ return serializeTreeSnapshot2(document, {
208
+ ...probe,
209
+ ...snapshotOptions.maxNodes ? { maxNodes: snapshotOptions.maxNodes } : {}
210
+ });
211
+ }
212
+ };
213
+ }
214
+ function installDomRuntime2(scope, document) {
215
+ const existing = Reflect.get(scope, DOM_RUNTIME_GLOBAL2);
216
+ if (existing && typeof existing === "object" && typeof existing.version === "number" && existing.version >= DOM_RUNTIME_VERSION2) {
217
+ return existing;
218
+ }
219
+ const runtime = Object.freeze(createDomRuntime2(document));
220
+ Object.defineProperty(scope, DOM_RUNTIME_GLOBAL2, {
221
+ value: runtime,
222
+ configurable: true,
223
+ enumerable: false,
224
+ writable: false
225
+ });
226
+ return runtime;
227
+ }
228
+
229
+ export { DOM_RUNTIME_VERSION2, DOM_RUNTIME_GLOBAL2, MAX_HIGHLIGHT_MS2, HIGHLIGHT_HOST_TAG2, isRuntimeTarget2, createDomRuntime2, installDomRuntime2 };
@@ -0,0 +1,224 @@
1
+ // src/script/types.ts
2
+ var UI_EXPRESSION_OPS2 = [
3
+ "eq",
4
+ "ne",
5
+ "lt",
6
+ "le",
7
+ "gt",
8
+ "ge",
9
+ "and",
10
+ "or",
11
+ "not",
12
+ "add",
13
+ "sub",
14
+ "mul",
15
+ "div",
16
+ "mod",
17
+ "neg",
18
+ "abs",
19
+ "round",
20
+ "min",
21
+ "max",
22
+ "concat",
23
+ "contains",
24
+ "startsWith",
25
+ "endsWith",
26
+ "lower",
27
+ "upper",
28
+ "trim",
29
+ "replace",
30
+ "split",
31
+ "join",
32
+ "length",
33
+ "toNumber",
34
+ "toText",
35
+ "toBoolean",
36
+ "isEmpty",
37
+ "coalesce",
38
+ "if",
39
+ "get",
40
+ "now",
41
+ "formatDate",
42
+ "addDays"
43
+ ];
44
+ var UI_ANCHOR_RELATIONS2 = ["leftOf", "rightOf", "above", "below", "inside", "sameRow"];
45
+ var UI_TARGET_METHOD_KINDS2 = ["role", "css", "testId", "xpath", "fuzzy", "anchor", "text"];
46
+ var UI_WEB_ACTIONS2 = [
47
+ "navigate",
48
+ "goBack",
49
+ "reload",
50
+ "closeTab",
51
+ "click",
52
+ "doubleClick",
53
+ "hover",
54
+ "type",
55
+ "typeSecret",
56
+ "clear",
57
+ "select",
58
+ "check",
59
+ "pressKey",
60
+ "scroll",
61
+ "waitFor",
62
+ "extract",
63
+ "extractList",
64
+ "getText",
65
+ "getValue",
66
+ "getAttribute",
67
+ "elementExists",
68
+ "getPageText",
69
+ "getPageHtml",
70
+ "screenshot",
71
+ "login"
72
+ ];
73
+ var UI_DESKTOP_ACTIONS2 = ["focusWindow"];
74
+ var UI_FLOW_ACTIONS2 = [
75
+ "if",
76
+ "forEach",
77
+ "while",
78
+ "retryScope",
79
+ "set",
80
+ "log",
81
+ "call"
82
+ ];
83
+ var UI_STEP_ACTIONS2 = [...UI_WEB_ACTIONS2, ...UI_DESKTOP_ACTIONS2, ...UI_FLOW_ACTIONS2];
84
+ var UI_VALUE_TYPES2 = ["text", "number", "boolean", "list", "object", "any"];
85
+
86
+ // src/script/walk.ts
87
+ function childBlocks2(step) {
88
+ switch (step.action) {
89
+ case "if":
90
+ return step.else ? [
91
+ ["then", step.then],
92
+ ["else", step.else]
93
+ ] : [["then", step.then]];
94
+ case "forEach":
95
+ case "while":
96
+ case "retryScope":
97
+ return [["steps", step.steps]];
98
+ default:
99
+ return [];
100
+ }
101
+ }
102
+ function* walkList(steps, prefix, depth) {
103
+ for (const [index, step] of steps.entries()) {
104
+ const path = prefix ? `${prefix}.${index}` : String(index);
105
+ yield { step, path, depth };
106
+ for (const [block, children] of childBlocks2(step)) {
107
+ yield* walkList(children, `${path}.${block}`, depth + 1);
108
+ }
109
+ }
110
+ }
111
+ function* walkSteps2(script) {
112
+ yield* walkList(script.steps, "", 0);
113
+ if (script.cleanup)
114
+ yield* walkList(script.cleanup, "cleanup", 0);
115
+ }
116
+ function countSteps2(script) {
117
+ return Array.from(walkSteps2(script)).length;
118
+ }
119
+ function stepAtPath2(script, path) {
120
+ for (const walked of walkSteps2(script))
121
+ if (walked.path === path)
122
+ return walked.step;
123
+ return;
124
+ }
125
+ function stepTargets2(step) {
126
+ const found = [];
127
+ const add = (field, ref) => {
128
+ if (ref)
129
+ found.push([field, ref]);
130
+ };
131
+ if ("target" in step)
132
+ add("target", step.target);
133
+ switch (step.action) {
134
+ case "extract":
135
+ step.fields.forEach((field, index) => add(`fields.${index}.target`, field.target));
136
+ break;
137
+ case "extractList":
138
+ add("item", step.item);
139
+ add("next", step.next);
140
+ step.fields.forEach((field, index) => add(`fields.${index}.target`, field.target));
141
+ break;
142
+ case "login":
143
+ add("username", step.username);
144
+ add("password", step.password);
145
+ add("submit", step.submit);
146
+ add("success", step.success);
147
+ break;
148
+ case "if":
149
+ case "while":
150
+ add("elementExists", step.elementExists);
151
+ break;
152
+ case "forEach":
153
+ add("elements", step.elements);
154
+ break;
155
+ default:
156
+ break;
157
+ }
158
+ if (step.verify && "target" in step.verify)
159
+ add("verify.target", step.verify.target);
160
+ return found;
161
+ }
162
+ function stepExpressions2(step) {
163
+ const found = [];
164
+ const add = (field, value) => {
165
+ if (value !== undefined)
166
+ found.push([field, value]);
167
+ };
168
+ switch (step.action) {
169
+ case "navigate":
170
+ add("url", step.url);
171
+ break;
172
+ case "type":
173
+ add("text", step.text);
174
+ break;
175
+ case "select":
176
+ step.values.forEach((value, index) => add(`values.${index}`, value));
177
+ break;
178
+ case "waitFor":
179
+ add("text", step.text);
180
+ add("urlContains", step.urlContains);
181
+ break;
182
+ case "if":
183
+ case "while":
184
+ add("condition", step.condition);
185
+ break;
186
+ case "forEach":
187
+ add("in", step.in);
188
+ break;
189
+ case "set":
190
+ add("value", step.value);
191
+ break;
192
+ case "log":
193
+ add("message", step.message);
194
+ break;
195
+ case "call":
196
+ for (const [arg, value] of Object.entries(step.args ?? {}))
197
+ add(`args.${arg}`, value);
198
+ break;
199
+ default:
200
+ break;
201
+ }
202
+ const verify = step.verify;
203
+ if (verify?.kind === "urlContains" || verify?.kind === "valueEquals")
204
+ add("verify.value", verify.value);
205
+ if (verify?.kind === "textPresent")
206
+ add("verify.text", verify.text);
207
+ return found;
208
+ }
209
+ function visitExpression2(expression, visit, depth = 1) {
210
+ visit(expression, depth);
211
+ if (expression === null || typeof expression !== "object")
212
+ return;
213
+ if ("list" in expression)
214
+ for (const item of expression.list)
215
+ visitExpression2(item, visit, depth + 1);
216
+ else if ("object" in expression)
217
+ for (const item of Object.values(expression.object))
218
+ visitExpression2(item, visit, depth + 1);
219
+ else if ("op" in expression)
220
+ for (const arg of expression.args)
221
+ visitExpression2(arg, visit, depth + 1);
222
+ }
223
+
224
+ export { UI_EXPRESSION_OPS2, UI_ANCHOR_RELATIONS2, UI_TARGET_METHOD_KINDS2, UI_WEB_ACTIONS2, UI_DESKTOP_ACTIONS2, UI_FLOW_ACTIONS2, UI_STEP_ACTIONS2, UI_VALUE_TYPES2, childBlocks2, walkSteps2, countSteps2, stepAtPath2, stepTargets2, stepExpressions2, visitExpression2 };
@@ -0,0 +1,195 @@
1
+ // src/script/describe.ts
2
+ var UI_SCRIPT_STEP_KEY_PREFIX2 = "fluidgrids.uiScript.step.";
3
+ var UI_SCRIPT_STEP_MESSAGES2 = {
4
+ navigate: "Go to {{url}}",
5
+ goBack: "Go back",
6
+ reload: "Reload the page",
7
+ closeTab: "Close the tab",
8
+ click: "Click {{target}}",
9
+ rightClick: "Right-click {{target}}",
10
+ doubleClick: "Double-click {{target}}",
11
+ rightDoubleClick: "Right double-click {{target}}",
12
+ hover: "Point at {{target}}",
13
+ type: "Type {{value}} into {{target}}",
14
+ typeFocused: "Type {{value}}",
15
+ typeMasked: "Type a hidden value into {{target}}",
16
+ typeMaskedFocused: "Type a hidden value",
17
+ typeSecret: "Type a secret into {{target}}",
18
+ clear: "Clear {{target}}",
19
+ select: "Choose {{value}} in {{target}}",
20
+ check: "Tick {{target}}",
21
+ uncheck: "Untick {{target}}",
22
+ pressKey: "Press {{keys}}",
23
+ scrollTop: "Scroll to the top",
24
+ scrollBottom: "Scroll to the bottom",
25
+ scrollTo: "Scroll to {{target}}",
26
+ scrollBy: "Scroll by {{dx}}, {{dy}}",
27
+ scrollInside: "Scroll {{target}} by {{dx}}, {{dy}}",
28
+ waitFor: "Wait for {{target}}",
29
+ waitForGone: "Wait for {{target}} to go away",
30
+ waitForText: "Wait for the text {{value}}",
31
+ waitForUrl: "Wait for the address to contain {{value}}",
32
+ waitForTime: "Wait {{milliseconds}} ms",
33
+ extract: "Read {{fields}}",
34
+ extractList: "Read each {{target}}",
35
+ getText: "Read the text of {{target}}",
36
+ getValue: "Read the value of {{target}}",
37
+ getAttribute: "Read {{attribute}} of {{target}}",
38
+ elementExists: "Check whether {{target}} is there",
39
+ getPageText: "Read the page text",
40
+ getPageHtml: "Read the page HTML",
41
+ screenshot: "Take a screenshot",
42
+ screenshotOf: "Take a screenshot of {{target}}",
43
+ login: "Sign in",
44
+ focusWindow: "Switch to {{app}}",
45
+ if: "If {{condition}}",
46
+ ifElement: "If {{target}} is there",
47
+ forEach: "For each item in {{value}}",
48
+ forEachElement: "For each {{target}}",
49
+ while: "While {{condition}}, at most {{max}} times",
50
+ whileElement: "While {{target}} is there, at most {{max}} times",
51
+ retryScope: "Try up to {{attempts}} times",
52
+ set: "Set {{name}} to {{value}}",
53
+ log: "Log {{value}}",
54
+ call: "Run the shared sequence {{sequence}}"
55
+ };
56
+ function stepMessageKey2(name) {
57
+ return `${UI_SCRIPT_STEP_KEY_PREFIX2}${name}`;
58
+ }
59
+ var MAX_SHOWN = 60;
60
+ function shorten(text) {
61
+ const flat = text.replace(/\s+/g, " ").trim();
62
+ return flat.length > MAX_SHOWN ? `${flat.slice(0, MAX_SHOWN - 1)}…` : flat;
63
+ }
64
+ function quoted(text) {
65
+ return `"${shorten(text)}"`;
66
+ }
67
+ function describeTarget2(ref, elements = {}) {
68
+ if (!ref)
69
+ return quoted("?");
70
+ if ("element" in ref) {
71
+ const element = elements[ref.element];
72
+ if (element?.name)
73
+ return quoted(element.name);
74
+ if (!element?.target)
75
+ return quoted(ref.element);
76
+ return describeTarget2(element.target);
77
+ }
78
+ const method = ref.methods.find((item) => item.enabled !== false) ?? ref.methods[0];
79
+ switch (method?.kind) {
80
+ case "role":
81
+ case "fuzzy":
82
+ return quoted(method.name);
83
+ case "text":
84
+ return quoted(method.text);
85
+ case "testId":
86
+ return quoted(method.value);
87
+ case "anchor":
88
+ return quoted(method.anchor.kind === "text" ? method.anchor.text : method.anchor.name);
89
+ case "css":
90
+ return quoted(method.selector);
91
+ case "xpath":
92
+ return quoted(method.xpath);
93
+ default:
94
+ return quoted("?");
95
+ }
96
+ }
97
+ function describeExpression2(expression) {
98
+ if (expression === undefined || expression === null)
99
+ return "…";
100
+ if (typeof expression === "string")
101
+ return quoted(expression);
102
+ if (typeof expression === "number" || typeof expression === "boolean")
103
+ return String(expression);
104
+ if ("input" in expression)
105
+ return `[${expression.input}]`;
106
+ if ("var" in expression)
107
+ return `[${expression.var}]`;
108
+ return "…";
109
+ }
110
+ function fill(name, vars) {
111
+ const fallback = UI_SCRIPT_STEP_MESSAGES2[name].replace(/\{\{(\w+)\}\}/g, (_match, variable) => String(vars[variable] ?? ""));
112
+ return { key: stepMessageKey2(name), vars, fallback };
113
+ }
114
+ function describeStep2(step, elements = {}) {
115
+ const target = (ref) => describeTarget2(ref, elements);
116
+ switch (step.action) {
117
+ case "navigate":
118
+ return fill("navigate", { url: describeExpression2(step.url) });
119
+ case "click":
120
+ return fill(step.button === "right" ? "rightClick" : "click", { target: target(step.target) });
121
+ case "doubleClick":
122
+ return fill(step.button === "right" ? "rightDoubleClick" : "doubleClick", { target: target(step.target) });
123
+ case "hover":
124
+ case "clear":
125
+ case "typeSecret":
126
+ case "getText":
127
+ case "getValue":
128
+ case "elementExists":
129
+ return fill(step.action, { target: target(step.target) });
130
+ case "type": {
131
+ if (!step.target)
132
+ return fill(step.masked ? "typeMaskedFocused" : "typeFocused", step.masked ? {} : { value: describeExpression2(step.text) });
133
+ return fill(step.masked ? "typeMasked" : "type", {
134
+ target: target(step.target),
135
+ ...step.masked ? {} : { value: describeExpression2(step.text) }
136
+ });
137
+ }
138
+ case "select":
139
+ return fill("select", {
140
+ value: step.values.map(describeExpression2).join(", "),
141
+ target: target(step.target)
142
+ });
143
+ case "check":
144
+ return fill(step.checked === false ? "uncheck" : "check", { target: target(step.target) });
145
+ case "pressKey":
146
+ return fill("pressKey", { keys: step.keys.join("+") });
147
+ case "scroll":
148
+ if (step.target && (step.dx !== undefined || step.dy !== undefined)) {
149
+ return fill("scrollInside", { target: target(step.target), dx: step.dx ?? 0, dy: step.dy ?? 0 });
150
+ }
151
+ if (step.target)
152
+ return fill("scrollTo", { target: target(step.target) });
153
+ if (step.dx !== undefined || step.dy !== undefined)
154
+ return fill("scrollBy", { dx: step.dx ?? 0, dy: step.dy ?? 0 });
155
+ return fill(step.to === "top" ? "scrollTop" : "scrollBottom", {});
156
+ case "waitFor":
157
+ if (step.target) {
158
+ const gone = step.state === "hidden" || step.state === "detached";
159
+ return fill(gone ? "waitForGone" : "waitFor", { target: target(step.target) });
160
+ }
161
+ if (step.text !== undefined)
162
+ return fill("waitForText", { value: describeExpression2(step.text) });
163
+ if (step.urlContains !== undefined)
164
+ return fill("waitForUrl", { value: describeExpression2(step.urlContains) });
165
+ return fill("waitForTime", { milliseconds: step.milliseconds ?? 0 });
166
+ case "extract":
167
+ return fill("extract", { fields: step.fields.map((field) => field.name).join(", ") });
168
+ case "extractList":
169
+ return fill("extractList", { target: target(step.item) });
170
+ case "getAttribute":
171
+ return fill("getAttribute", { attribute: step.attribute, target: target(step.target) });
172
+ case "screenshot":
173
+ return step.target ? fill("screenshotOf", { target: target(step.target) }) : fill("screenshot", {});
174
+ case "focusWindow":
175
+ return fill("focusWindow", { app: quoted(step.title ?? step.app) });
176
+ case "if":
177
+ return step.elementExists ? fill("ifElement", { target: target(step.elementExists) }) : fill("if", { condition: describeExpression2(step.condition) });
178
+ case "forEach":
179
+ return step.elements ? fill("forEachElement", { target: target(step.elements) }) : fill("forEach", { value: describeExpression2(step.in) });
180
+ case "while":
181
+ return step.elementExists ? fill("whileElement", { target: target(step.elementExists), max: step.maxIterations }) : fill("while", { condition: describeExpression2(step.condition), max: step.maxIterations });
182
+ case "retryScope":
183
+ return fill("retryScope", { attempts: step.attempts });
184
+ case "set":
185
+ return fill("set", { name: `[${step.name}]`, value: describeExpression2(step.value) });
186
+ case "log":
187
+ return fill("log", { value: describeExpression2(step.message) });
188
+ case "call":
189
+ return fill("call", { sequence: quoted(step.sequenceId) });
190
+ default:
191
+ return fill(step.action, {});
192
+ }
193
+ }
194
+
195
+ export { UI_SCRIPT_STEP_KEY_PREFIX2, UI_SCRIPT_STEP_MESSAGES2, stepMessageKey2, describeTarget2, describeExpression2, describeStep2 };