@qontinui/ui-bridge 0.1.1 → 0.2.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/ai/index.d.mts +893 -0
- package/dist/ai/index.d.ts +893 -0
- package/dist/ai/index.js +3897 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/index.mjs +3839 -0
- package/dist/ai/index.mjs.map +1 -0
- package/dist/control/index.d.mts +5 -4
- package/dist/control/index.d.ts +5 -4
- package/dist/core/index.d.mts +6 -4
- package/dist/core/index.d.ts +6 -4
- package/dist/core/index.js +581 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +581 -4
- package/dist/core/index.mjs.map +1 -1
- package/dist/debug/index.d.mts +3 -3
- package/dist/debug/index.d.ts +3 -3
- package/dist/index.d.mts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +4112 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4056 -13
- package/dist/index.mjs.map +1 -1
- package/dist/{metrics-QCnK0EFw.d.ts → metrics-C9XRi_mL.d.ts} +2 -2
- package/dist/{metrics-BCG7z7Aq.d.mts → metrics-NC3csD0R.d.mts} +2 -2
- package/dist/react/index.d.mts +6 -5
- package/dist/react/index.d.ts +6 -5
- package/dist/react/index.js +587 -10
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +587 -10
- package/dist/react/index.mjs.map +1 -1
- package/dist/{registry-CT6BVVKr.d.mts → registry-CIEDjbQ9.d.ts} +22 -1
- package/dist/{registry-D4mQ01B3.d.ts → registry-SsSDq46X.d.mts} +22 -1
- package/dist/render-log/index.d.mts +1 -1
- package/dist/render-log/index.d.ts +1 -1
- package/dist/types-BvCfFuEV.d.ts +534 -0
- package/dist/types-CFT3Dnx4.d.mts +534 -0
- package/dist/{types-BpvpStn3.d.mts → types-CPMbN_Iw.d.mts} +8 -0
- package/dist/{types-BpvpStn3.d.ts → types-CPMbN_Iw.d.ts} +8 -0
- package/dist/{types-DdJD9yw5.d.mts → types-Dr6tH-bm.d.mts} +1 -1
- package/dist/{types-BDkXy5si.d.ts → types-oCTrRxSw.d.ts} +1 -1
- package/dist/{websocket-client-DupH0X7B.d.ts → websocket-client-CX4QJesI.d.ts} +1 -1
- package/dist/{websocket-client-B2LC9CYc.d.mts → websocket-client-C_Na0OSp.d.mts} +1 -1
- package/package.json +6 -1
package/dist/core/index.mjs
CHANGED
|
@@ -217,6 +217,376 @@ function elementMatchesIdentifier(element, identifier) {
|
|
|
217
217
|
return identifier.uiId && element.getAttribute("data-ui-id") === identifier.uiId || identifier.testId && element.getAttribute("data-testid") === identifier.testId || identifier.awasId && element.getAttribute("data-awas-element") === identifier.awasId || identifier.htmlId && element.id === identifier.htmlId || false;
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
// src/ai/fuzzy-matcher.ts
|
|
221
|
+
var DEFAULT_FUZZY_CONFIG = {
|
|
222
|
+
threshold: 0.7,
|
|
223
|
+
levenshteinWeight: 0.3,
|
|
224
|
+
jaroWinklerWeight: 0.4,
|
|
225
|
+
ngramWeight: 0.3,
|
|
226
|
+
ngramSize: 2,
|
|
227
|
+
caseSensitive: false,
|
|
228
|
+
ignoreWhitespace: true
|
|
229
|
+
};
|
|
230
|
+
function levenshteinDistance(s1, s2) {
|
|
231
|
+
const len1 = s1.length;
|
|
232
|
+
const len2 = s2.length;
|
|
233
|
+
const matrix = Array(len1 + 1).fill(null).map(() => Array(len2 + 1).fill(0));
|
|
234
|
+
for (let i = 0; i <= len1; i++) matrix[i][0] = i;
|
|
235
|
+
for (let j = 0; j <= len2; j++) matrix[0][j] = j;
|
|
236
|
+
for (let i = 1; i <= len1; i++) {
|
|
237
|
+
for (let j = 1; j <= len2; j++) {
|
|
238
|
+
const cost = s1[i - 1] === s2[j - 1] ? 0 : 1;
|
|
239
|
+
matrix[i][j] = Math.min(
|
|
240
|
+
matrix[i - 1][j] + 1,
|
|
241
|
+
// deletion
|
|
242
|
+
matrix[i][j - 1] + 1,
|
|
243
|
+
// insertion
|
|
244
|
+
matrix[i - 1][j - 1] + cost
|
|
245
|
+
// substitution
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return matrix[len1][len2];
|
|
250
|
+
}
|
|
251
|
+
function levenshteinSimilarity(s1, s2) {
|
|
252
|
+
if (s1.length === 0 && s2.length === 0) return 1;
|
|
253
|
+
if (s1.length === 0 || s2.length === 0) return 0;
|
|
254
|
+
const distance = levenshteinDistance(s1, s2);
|
|
255
|
+
const maxLength = Math.max(s1.length, s2.length);
|
|
256
|
+
return 1 - distance / maxLength;
|
|
257
|
+
}
|
|
258
|
+
function jaroSimilarity(s1, s2) {
|
|
259
|
+
if (s1.length === 0 && s2.length === 0) return 1;
|
|
260
|
+
if (s1.length === 0 || s2.length === 0) return 0;
|
|
261
|
+
const matchDistance = Math.floor(Math.max(s1.length, s2.length) / 2) - 1;
|
|
262
|
+
const s1Matches = new Array(s1.length).fill(false);
|
|
263
|
+
const s2Matches = new Array(s2.length).fill(false);
|
|
264
|
+
let matches = 0;
|
|
265
|
+
let transpositions = 0;
|
|
266
|
+
for (let i = 0; i < s1.length; i++) {
|
|
267
|
+
const start = Math.max(0, i - matchDistance);
|
|
268
|
+
const end = Math.min(i + matchDistance + 1, s2.length);
|
|
269
|
+
for (let j = start; j < end; j++) {
|
|
270
|
+
if (s2Matches[j] || s1[i] !== s2[j]) continue;
|
|
271
|
+
s1Matches[i] = true;
|
|
272
|
+
s2Matches[j] = true;
|
|
273
|
+
matches++;
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (matches === 0) return 0;
|
|
278
|
+
let k = 0;
|
|
279
|
+
for (let i = 0; i < s1.length; i++) {
|
|
280
|
+
if (!s1Matches[i]) continue;
|
|
281
|
+
while (!s2Matches[k]) k++;
|
|
282
|
+
if (s1[i] !== s2[k]) transpositions++;
|
|
283
|
+
k++;
|
|
284
|
+
}
|
|
285
|
+
return (matches / s1.length + matches / s2.length + (matches - transpositions / 2) / matches) / 3;
|
|
286
|
+
}
|
|
287
|
+
function jaroWinklerSimilarity(s1, s2, prefixScale = 0.1) {
|
|
288
|
+
const jaroSim = jaroSimilarity(s1, s2);
|
|
289
|
+
let prefixLength = 0;
|
|
290
|
+
const maxPrefix = Math.min(4, Math.min(s1.length, s2.length));
|
|
291
|
+
for (let i = 0; i < maxPrefix; i++) {
|
|
292
|
+
if (s1[i] === s2[i]) {
|
|
293
|
+
prefixLength++;
|
|
294
|
+
} else {
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return jaroSim + prefixLength * prefixScale * (1 - jaroSim);
|
|
299
|
+
}
|
|
300
|
+
function generateNgrams(s, n) {
|
|
301
|
+
const ngrams = /* @__PURE__ */ new Set();
|
|
302
|
+
if (s.length < n) {
|
|
303
|
+
ngrams.add(s);
|
|
304
|
+
return ngrams;
|
|
305
|
+
}
|
|
306
|
+
for (let i = 0; i <= s.length - n; i++) {
|
|
307
|
+
ngrams.add(s.substring(i, i + n));
|
|
308
|
+
}
|
|
309
|
+
return ngrams;
|
|
310
|
+
}
|
|
311
|
+
function ngramSimilarity(s1, s2, n = 2) {
|
|
312
|
+
if (s1.length === 0 && s2.length === 0) return 1;
|
|
313
|
+
if (s1.length === 0 || s2.length === 0) return 0;
|
|
314
|
+
const ngrams1 = generateNgrams(s1, n);
|
|
315
|
+
const ngrams2 = generateNgrams(s2, n);
|
|
316
|
+
let intersection = 0;
|
|
317
|
+
for (const ngram of ngrams1) {
|
|
318
|
+
if (ngrams2.has(ngram)) {
|
|
319
|
+
intersection++;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const union = ngrams1.size + ngrams2.size - intersection;
|
|
323
|
+
return union === 0 ? 0 : intersection / union;
|
|
324
|
+
}
|
|
325
|
+
function normalizeString(s, config = {}) {
|
|
326
|
+
let normalized = s;
|
|
327
|
+
if (!config.caseSensitive) {
|
|
328
|
+
normalized = normalized.toLowerCase();
|
|
329
|
+
}
|
|
330
|
+
if (config.ignoreWhitespace !== false) {
|
|
331
|
+
normalized = normalized.replace(/\s+/g, " ").trim();
|
|
332
|
+
}
|
|
333
|
+
return normalized;
|
|
334
|
+
}
|
|
335
|
+
function fuzzyMatch(source, target, config = {}) {
|
|
336
|
+
const finalConfig = { ...DEFAULT_FUZZY_CONFIG, ...config };
|
|
337
|
+
const normalizedSource = normalizeString(source, finalConfig);
|
|
338
|
+
const normalizedTarget = normalizeString(target, finalConfig);
|
|
339
|
+
const levenshteinScore = levenshteinSimilarity(normalizedSource, normalizedTarget);
|
|
340
|
+
const jaroWinklerScore = jaroWinklerSimilarity(normalizedSource, normalizedTarget);
|
|
341
|
+
const ngramScore = ngramSimilarity(normalizedSource, normalizedTarget, finalConfig.ngramSize);
|
|
342
|
+
const similarity = levenshteinScore * finalConfig.levenshteinWeight + jaroWinklerScore * finalConfig.jaroWinklerWeight + ngramScore * finalConfig.ngramWeight;
|
|
343
|
+
return {
|
|
344
|
+
similarity,
|
|
345
|
+
isMatch: similarity >= finalConfig.threshold,
|
|
346
|
+
scores: {
|
|
347
|
+
levenshtein: levenshteinScore,
|
|
348
|
+
jaroWinkler: jaroWinklerScore,
|
|
349
|
+
ngram: ngramScore
|
|
350
|
+
},
|
|
351
|
+
normalizedSource,
|
|
352
|
+
normalizedTarget
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function tokenize(s) {
|
|
356
|
+
return s.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_-]/g, " ").replace(/\s+/g, " ").trim().toLowerCase().split(" ").filter((token) => token.length > 0);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/ai/alias-generator.ts
|
|
360
|
+
var DEFAULT_ALIAS_CONFIG = {
|
|
361
|
+
includeText: true,
|
|
362
|
+
includeAriaLabel: true,
|
|
363
|
+
includePlaceholder: true,
|
|
364
|
+
includeTitle: true,
|
|
365
|
+
includeSynonyms: true,
|
|
366
|
+
maxAliases: 20,
|
|
367
|
+
minLength: 2,
|
|
368
|
+
maxLength: 50
|
|
369
|
+
};
|
|
370
|
+
var SYNONYMS = {
|
|
371
|
+
// Submit-related
|
|
372
|
+
submit: ["send", "go", "confirm", "ok", "apply", "save", "done", "finish"],
|
|
373
|
+
send: ["submit", "deliver", "post"],
|
|
374
|
+
save: ["submit", "store", "keep", "apply"],
|
|
375
|
+
cancel: ["close", "dismiss", "abort", "back", "exit", "quit", "nevermind"],
|
|
376
|
+
close: ["cancel", "dismiss", "exit", "x"],
|
|
377
|
+
delete: ["remove", "trash", "erase", "clear", "destroy"],
|
|
378
|
+
remove: ["delete", "clear", "discard"],
|
|
379
|
+
edit: ["modify", "change", "update", "alter"],
|
|
380
|
+
update: ["edit", "modify", "save", "refresh"],
|
|
381
|
+
add: ["create", "new", "plus", "insert"],
|
|
382
|
+
create: ["add", "new", "make"],
|
|
383
|
+
search: ["find", "lookup", "query", "filter"],
|
|
384
|
+
find: ["search", "locate", "lookup"],
|
|
385
|
+
login: ["signin", "sign in", "log in", "authenticate", "enter"],
|
|
386
|
+
logout: ["signout", "sign out", "log out", "exit"],
|
|
387
|
+
register: ["signup", "sign up", "join", "create account"],
|
|
388
|
+
next: ["continue", "forward", "proceed", "advance"],
|
|
389
|
+
previous: ["back", "backward", "return", "prior"],
|
|
390
|
+
back: ["previous", "return", "backward"],
|
|
391
|
+
start: ["begin", "launch", "initiate", "run", "execute"],
|
|
392
|
+
stop: ["end", "halt", "pause", "terminate"],
|
|
393
|
+
enable: ["activate", "turn on", "switch on"],
|
|
394
|
+
disable: ["deactivate", "turn off", "switch off"],
|
|
395
|
+
show: ["display", "reveal", "view", "open"],
|
|
396
|
+
hide: ["conceal", "collapse", "close"],
|
|
397
|
+
expand: ["open", "show", "unfold", "reveal"],
|
|
398
|
+
collapse: ["close", "hide", "fold", "minimize"],
|
|
399
|
+
yes: ["ok", "confirm", "agree", "accept"],
|
|
400
|
+
no: ["cancel", "decline", "reject", "deny"],
|
|
401
|
+
help: ["support", "assistance", "info", "information", "faq"],
|
|
402
|
+
settings: ["preferences", "options", "config", "configuration"],
|
|
403
|
+
profile: ["account", "user", "me"],
|
|
404
|
+
download: ["export", "save", "get"],
|
|
405
|
+
upload: ["import", "load", "attach"],
|
|
406
|
+
refresh: ["reload", "update", "sync"],
|
|
407
|
+
copy: ["duplicate", "clone"],
|
|
408
|
+
paste: ["insert"],
|
|
409
|
+
select: ["choose", "pick"],
|
|
410
|
+
toggle: ["switch", "flip"],
|
|
411
|
+
// Form fields
|
|
412
|
+
email: ["e-mail", "mail"],
|
|
413
|
+
password: ["pass", "pwd", "secret"],
|
|
414
|
+
username: ["user", "login", "account", "name"],
|
|
415
|
+
firstname: ["first name", "given name", "forename"],
|
|
416
|
+
lastname: ["last name", "surname", "family name"],
|
|
417
|
+
fullname: ["full name", "name", "complete name"],
|
|
418
|
+
phone: ["telephone", "tel", "mobile", "cell"],
|
|
419
|
+
address: ["location", "street"],
|
|
420
|
+
city: ["town"],
|
|
421
|
+
country: ["nation"],
|
|
422
|
+
zip: ["zipcode", "postal", "postal code", "postcode"],
|
|
423
|
+
// Navigation
|
|
424
|
+
home: ["main", "start", "dashboard"],
|
|
425
|
+
menu: ["navigation", "nav"],
|
|
426
|
+
sidebar: ["side bar", "side panel", "side menu"]
|
|
427
|
+
};
|
|
428
|
+
var ELEMENT_ACTION_WORDS = {
|
|
429
|
+
button: ["button", "btn", "click"],
|
|
430
|
+
input: ["input", "field", "textbox", "box"],
|
|
431
|
+
textarea: ["textarea", "text area", "text field", "multiline"],
|
|
432
|
+
select: ["select", "dropdown", "combo", "picker", "chooser"],
|
|
433
|
+
checkbox: ["checkbox", "check", "tick"],
|
|
434
|
+
radio: ["radio", "option", "choice"],
|
|
435
|
+
link: ["link", "anchor", "href"],
|
|
436
|
+
form: ["form"],
|
|
437
|
+
menu: ["menu"],
|
|
438
|
+
menuitem: ["menu item", "option"],
|
|
439
|
+
tab: ["tab"],
|
|
440
|
+
dialog: ["dialog", "modal", "popup"],
|
|
441
|
+
switch: ["switch", "toggle"],
|
|
442
|
+
slider: ["slider", "range"]
|
|
443
|
+
};
|
|
444
|
+
function normalizeAlias(text) {
|
|
445
|
+
return text.toLowerCase().replace(/[^\w\s]/g, " ").replace(/\s+/g, " ").trim();
|
|
446
|
+
}
|
|
447
|
+
function extractWords(text) {
|
|
448
|
+
const tokens = tokenize(text);
|
|
449
|
+
return tokens.filter((t) => t.length >= 2);
|
|
450
|
+
}
|
|
451
|
+
function generateTextAliases(text, config) {
|
|
452
|
+
if (!text || !config.includeText) return [];
|
|
453
|
+
const aliases = [];
|
|
454
|
+
const normalized = normalizeAlias(text);
|
|
455
|
+
if (normalized.length >= config.minLength && normalized.length <= config.maxLength) {
|
|
456
|
+
aliases.push(normalized);
|
|
457
|
+
}
|
|
458
|
+
const words = extractWords(text);
|
|
459
|
+
for (const word of words) {
|
|
460
|
+
if (word.length >= config.minLength) {
|
|
461
|
+
aliases.push(word);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (words.length >= 2 && words.length <= 4) {
|
|
465
|
+
const twoWords = words.slice(0, 2).join(" ");
|
|
466
|
+
if (twoWords.length <= config.maxLength) {
|
|
467
|
+
aliases.push(twoWords);
|
|
468
|
+
}
|
|
469
|
+
if (words.length > 2) {
|
|
470
|
+
const lastTwo = words.slice(-2).join(" ");
|
|
471
|
+
if (lastTwo.length <= config.maxLength) {
|
|
472
|
+
aliases.push(lastTwo);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return aliases;
|
|
477
|
+
}
|
|
478
|
+
function generateSynonyms(aliases, config) {
|
|
479
|
+
if (!config.includeSynonyms) return [];
|
|
480
|
+
const synonyms = [];
|
|
481
|
+
for (const alias of aliases) {
|
|
482
|
+
const words = alias.toLowerCase().split(/\s+/);
|
|
483
|
+
for (const word of words) {
|
|
484
|
+
if (SYNONYMS[word]) {
|
|
485
|
+
for (const synonym of SYNONYMS[word]) {
|
|
486
|
+
const newAlias = alias.toLowerCase().replace(word, synonym);
|
|
487
|
+
if (newAlias !== alias.toLowerCase()) {
|
|
488
|
+
synonyms.push(newAlias);
|
|
489
|
+
}
|
|
490
|
+
if (synonym.length >= config.minLength) {
|
|
491
|
+
synonyms.push(synonym);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return synonyms;
|
|
498
|
+
}
|
|
499
|
+
function generateTypeAliases(elementType) {
|
|
500
|
+
const type = elementType.toLowerCase();
|
|
501
|
+
return ELEMENT_ACTION_WORDS[type] || [type];
|
|
502
|
+
}
|
|
503
|
+
function generateAliases(input, config = {}) {
|
|
504
|
+
const finalConfig = { ...DEFAULT_ALIAS_CONFIG, ...config };
|
|
505
|
+
const aliasSet = /* @__PURE__ */ new Set();
|
|
506
|
+
const addAlias = (alias) => {
|
|
507
|
+
const normalized = normalizeAlias(alias);
|
|
508
|
+
if (normalized.length >= finalConfig.minLength && normalized.length <= finalConfig.maxLength) {
|
|
509
|
+
aliasSet.add(normalized);
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
const addAliases = (aliases2) => {
|
|
513
|
+
for (const alias of aliases2) {
|
|
514
|
+
addAlias(alias);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
if (finalConfig.includeText && input.textContent) {
|
|
518
|
+
addAliases(generateTextAliases(input.textContent, finalConfig));
|
|
519
|
+
}
|
|
520
|
+
if (finalConfig.includeAriaLabel && input.ariaLabel) {
|
|
521
|
+
addAliases(generateTextAliases(input.ariaLabel, finalConfig));
|
|
522
|
+
}
|
|
523
|
+
if (finalConfig.includeAriaLabel && input.ariaLabelledBy) {
|
|
524
|
+
addAliases(generateTextAliases(input.ariaLabelledBy, finalConfig));
|
|
525
|
+
}
|
|
526
|
+
if (finalConfig.includePlaceholder && input.placeholder) {
|
|
527
|
+
addAliases(generateTextAliases(input.placeholder, finalConfig));
|
|
528
|
+
}
|
|
529
|
+
if (finalConfig.includeTitle && input.title) {
|
|
530
|
+
addAliases(generateTextAliases(input.title, finalConfig));
|
|
531
|
+
}
|
|
532
|
+
if (input.labelText) {
|
|
533
|
+
addAliases(generateTextAliases(input.labelText, finalConfig));
|
|
534
|
+
}
|
|
535
|
+
if (input.id) {
|
|
536
|
+
addAliases(extractWords(input.id));
|
|
537
|
+
}
|
|
538
|
+
if (input.name) {
|
|
539
|
+
addAliases(extractWords(input.name));
|
|
540
|
+
}
|
|
541
|
+
if (input.value && (input.elementType === "button" || input.inputType === "submit" || input.inputType === "button")) {
|
|
542
|
+
addAliases(generateTextAliases(input.value, finalConfig));
|
|
543
|
+
}
|
|
544
|
+
if (input.elementType) {
|
|
545
|
+
addAliases(generateTypeAliases(input.elementType));
|
|
546
|
+
}
|
|
547
|
+
if (input.inputType) {
|
|
548
|
+
addAlias(input.inputType);
|
|
549
|
+
if (input.inputType === "email") {
|
|
550
|
+
addAliases(["email", "e-mail", "email address"]);
|
|
551
|
+
} else if (input.inputType === "password") {
|
|
552
|
+
addAliases(["password", "pass", "pwd"]);
|
|
553
|
+
} else if (input.inputType === "tel") {
|
|
554
|
+
addAliases(["phone", "telephone", "mobile"]);
|
|
555
|
+
} else if (input.inputType === "url") {
|
|
556
|
+
addAliases(["url", "website", "link", "address"]);
|
|
557
|
+
} else if (input.inputType === "search") {
|
|
558
|
+
addAliases(["search", "find", "query"]);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (finalConfig.includeSynonyms) {
|
|
562
|
+
const currentAliases = Array.from(aliasSet);
|
|
563
|
+
addAliases(generateSynonyms(currentAliases, finalConfig));
|
|
564
|
+
}
|
|
565
|
+
let aliases = Array.from(aliasSet);
|
|
566
|
+
aliases.sort((a, b) => a.length - b.length);
|
|
567
|
+
if (aliases.length > finalConfig.maxAliases) {
|
|
568
|
+
aliases = aliases.slice(0, finalConfig.maxAliases);
|
|
569
|
+
}
|
|
570
|
+
return aliases;
|
|
571
|
+
}
|
|
572
|
+
function generateDescription(input) {
|
|
573
|
+
const parts = [];
|
|
574
|
+
let name = input.ariaLabel || input.labelText || input.textContent || input.placeholder || input.title || input.id || input.name;
|
|
575
|
+
if (name) {
|
|
576
|
+
name = name.trim();
|
|
577
|
+
if (name.length > 30) {
|
|
578
|
+
name = name.substring(0, 27) + "...";
|
|
579
|
+
}
|
|
580
|
+
parts.push(`"${name}"`);
|
|
581
|
+
}
|
|
582
|
+
const typeWords = ELEMENT_ACTION_WORDS[input.elementType || ""] || [input.elementType || "element"];
|
|
583
|
+
parts.push(typeWords[0]);
|
|
584
|
+
if (input.inputType && input.inputType !== "text") {
|
|
585
|
+
parts.push(`(${input.inputType})`);
|
|
586
|
+
}
|
|
587
|
+
return parts.join(" ");
|
|
588
|
+
}
|
|
589
|
+
|
|
220
590
|
// src/core/registry.ts
|
|
221
591
|
function getElementState(element) {
|
|
222
592
|
const rect = element.getBoundingClientRect();
|
|
@@ -415,9 +785,13 @@ var UIBridgeRegistry = class {
|
|
|
415
785
|
registerElement(id, element, options = {}) {
|
|
416
786
|
const type = options.type ?? inferElementType(element);
|
|
417
787
|
const actions = options.actions ?? inferActions(type);
|
|
418
|
-
element.
|
|
788
|
+
const existingUiId = element.getAttribute("data-ui-id");
|
|
789
|
+
const actualId = existingUiId || id;
|
|
790
|
+
if (!existingUiId) {
|
|
791
|
+
element.setAttribute("data-ui-id", actualId);
|
|
792
|
+
}
|
|
419
793
|
const registered = {
|
|
420
|
-
id,
|
|
794
|
+
id: actualId,
|
|
421
795
|
element,
|
|
422
796
|
type,
|
|
423
797
|
label: options.label,
|
|
@@ -428,8 +802,8 @@ var UIBridgeRegistry = class {
|
|
|
428
802
|
registeredAt: Date.now(),
|
|
429
803
|
mounted: true
|
|
430
804
|
};
|
|
431
|
-
this.elements.set(
|
|
432
|
-
this.emit("element:registered", { id, type, label: options.label });
|
|
805
|
+
this.elements.set(actualId, registered);
|
|
806
|
+
this.emit("element:registered", { id: actualId, type, label: options.label });
|
|
433
807
|
return registered;
|
|
434
808
|
}
|
|
435
809
|
/**
|
|
@@ -469,6 +843,209 @@ var UIBridgeRegistry = class {
|
|
|
469
843
|
}
|
|
470
844
|
return void 0;
|
|
471
845
|
}
|
|
846
|
+
/**
|
|
847
|
+
* Search for elements using AI search criteria
|
|
848
|
+
*/
|
|
849
|
+
searchElements(criteria) {
|
|
850
|
+
const results = [];
|
|
851
|
+
const threshold = criteria.fuzzyThreshold ?? 0.7;
|
|
852
|
+
for (const element of this.elements.values()) {
|
|
853
|
+
if (!element.mounted) continue;
|
|
854
|
+
const state = element.getState();
|
|
855
|
+
if (!criteria.fuzzy && !state.visible) continue;
|
|
856
|
+
const aliases = element.aliases ?? this.generateElementAliases(element);
|
|
857
|
+
const textContent = state.textContent?.trim() || "";
|
|
858
|
+
const label = element.label || "";
|
|
859
|
+
let maxScore = 0;
|
|
860
|
+
const matchReasons = [];
|
|
861
|
+
const scores = {};
|
|
862
|
+
if (criteria.text) {
|
|
863
|
+
if (textContent.toLowerCase() === criteria.text.toLowerCase() || label.toLowerCase() === criteria.text.toLowerCase()) {
|
|
864
|
+
maxScore = 1;
|
|
865
|
+
matchReasons.push("exact text match");
|
|
866
|
+
scores.text = 1;
|
|
867
|
+
} else if (criteria.fuzzy !== false) {
|
|
868
|
+
const textResult = fuzzyMatch(criteria.text, textContent, { threshold });
|
|
869
|
+
const labelResult = fuzzyMatch(criteria.text, label, { threshold });
|
|
870
|
+
const bestResult = textResult.similarity > labelResult.similarity ? textResult : labelResult;
|
|
871
|
+
if (bestResult.isMatch) {
|
|
872
|
+
scores.text = bestResult.similarity;
|
|
873
|
+
if (bestResult.similarity > maxScore) {
|
|
874
|
+
maxScore = bestResult.similarity;
|
|
875
|
+
matchReasons.push(`text similarity: ${(bestResult.similarity * 100).toFixed(0)}%`);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
if (criteria.textContains) {
|
|
881
|
+
if (textContent.toLowerCase().includes(criteria.textContains.toLowerCase()) || label.toLowerCase().includes(criteria.textContains.toLowerCase())) {
|
|
882
|
+
const containsScore = 0.85;
|
|
883
|
+
scores.text = Math.max(scores.text ?? 0, containsScore);
|
|
884
|
+
if (containsScore > maxScore) {
|
|
885
|
+
maxScore = containsScore;
|
|
886
|
+
matchReasons.push("text contains");
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
if (criteria.accessibleName) {
|
|
891
|
+
const ariaLabel = element.element.getAttribute("aria-label") || "";
|
|
892
|
+
const accessibleName = ariaLabel || label || textContent;
|
|
893
|
+
if (accessibleName.toLowerCase() === criteria.accessibleName.toLowerCase()) {
|
|
894
|
+
scores.accessibility = 1;
|
|
895
|
+
if (1 > maxScore) {
|
|
896
|
+
maxScore = 1;
|
|
897
|
+
matchReasons.push("accessible name match");
|
|
898
|
+
}
|
|
899
|
+
} else if (criteria.fuzzy !== false) {
|
|
900
|
+
const result = fuzzyMatch(criteria.accessibleName, accessibleName, { threshold });
|
|
901
|
+
if (result.isMatch) {
|
|
902
|
+
scores.accessibility = result.similarity;
|
|
903
|
+
if (result.similarity > maxScore) {
|
|
904
|
+
maxScore = result.similarity;
|
|
905
|
+
matchReasons.push(`accessible name similarity: ${(result.similarity * 100).toFixed(0)}%`);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
if (criteria.role) {
|
|
911
|
+
const role = element.element.getAttribute("role") || this.inferRole(element.type);
|
|
912
|
+
if (role?.toLowerCase() === criteria.role.toLowerCase()) {
|
|
913
|
+
scores.role = 1;
|
|
914
|
+
if (1 > maxScore) {
|
|
915
|
+
maxScore = 1;
|
|
916
|
+
matchReasons.push(`role: ${criteria.role}`);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
if (criteria.type) {
|
|
921
|
+
if (element.type === criteria.type) {
|
|
922
|
+
const typeScore = 0.9;
|
|
923
|
+
scores.role = Math.max(scores.role ?? 0, typeScore);
|
|
924
|
+
if (typeScore > maxScore) {
|
|
925
|
+
maxScore = typeScore;
|
|
926
|
+
matchReasons.push(`type: ${criteria.type}`);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
for (const alias of aliases) {
|
|
931
|
+
const searchText = criteria.text || criteria.textContains || criteria.accessibleName;
|
|
932
|
+
if (searchText) {
|
|
933
|
+
if (alias.toLowerCase() === searchText.toLowerCase()) {
|
|
934
|
+
scores.fuzzy = 1;
|
|
935
|
+
if (1 > maxScore) {
|
|
936
|
+
maxScore = 1;
|
|
937
|
+
matchReasons.push(`alias: "${alias}"`);
|
|
938
|
+
}
|
|
939
|
+
} else if (criteria.fuzzy !== false) {
|
|
940
|
+
const result = fuzzyMatch(searchText, alias, { threshold });
|
|
941
|
+
if (result.isMatch && result.similarity > (scores.fuzzy ?? 0)) {
|
|
942
|
+
scores.fuzzy = result.similarity;
|
|
943
|
+
if (result.similarity > maxScore) {
|
|
944
|
+
maxScore = result.similarity;
|
|
945
|
+
matchReasons.push(`fuzzy alias: "${alias}"`);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
if (maxScore >= threshold) {
|
|
952
|
+
const aiElement = {
|
|
953
|
+
id: element.id,
|
|
954
|
+
type: element.type,
|
|
955
|
+
label: element.label,
|
|
956
|
+
tagName: element.element.tagName.toLowerCase(),
|
|
957
|
+
role: element.element.getAttribute("role") || void 0,
|
|
958
|
+
accessibleName: element.element.getAttribute("aria-label") || element.label,
|
|
959
|
+
actions: element.actions,
|
|
960
|
+
state,
|
|
961
|
+
registered: true,
|
|
962
|
+
description: element.description || generateDescription({
|
|
963
|
+
textContent,
|
|
964
|
+
ariaLabel: element.element.getAttribute("aria-label"),
|
|
965
|
+
elementType: element.type,
|
|
966
|
+
id: element.id,
|
|
967
|
+
labelText: element.label
|
|
968
|
+
}),
|
|
969
|
+
aliases,
|
|
970
|
+
purpose: element.purpose,
|
|
971
|
+
suggestedActions: [],
|
|
972
|
+
semanticType: element.semanticType
|
|
973
|
+
};
|
|
974
|
+
results.push({
|
|
975
|
+
element: aiElement,
|
|
976
|
+
confidence: maxScore,
|
|
977
|
+
matchReasons,
|
|
978
|
+
scores
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
results.sort((a, b) => b.confidence - a.confidence);
|
|
983
|
+
return results;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Find element by visible text
|
|
987
|
+
*/
|
|
988
|
+
findByText(text, fuzzy = true) {
|
|
989
|
+
const results = this.searchElements({ text, fuzzy, fuzzyThreshold: fuzzy ? 0.7 : 1 });
|
|
990
|
+
if (results.length > 0) {
|
|
991
|
+
return this.elements.get(results[0].element.id);
|
|
992
|
+
}
|
|
993
|
+
return void 0;
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Find element by accessible name
|
|
997
|
+
*/
|
|
998
|
+
findByAccessibleName(name) {
|
|
999
|
+
const results = this.searchElements({ accessibleName: name, fuzzy: true });
|
|
1000
|
+
if (results.length > 0) {
|
|
1001
|
+
return this.elements.get(results[0].element.id);
|
|
1002
|
+
}
|
|
1003
|
+
return void 0;
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Generate aliases for an element
|
|
1007
|
+
*/
|
|
1008
|
+
generateElementAliases(element) {
|
|
1009
|
+
const state = element.getState();
|
|
1010
|
+
return generateAliases({
|
|
1011
|
+
textContent: state.textContent,
|
|
1012
|
+
ariaLabel: element.element.getAttribute("aria-label"),
|
|
1013
|
+
placeholder: element.element.getAttribute("placeholder"),
|
|
1014
|
+
title: element.element.getAttribute("title"),
|
|
1015
|
+
elementType: element.type,
|
|
1016
|
+
tagName: element.element.tagName.toLowerCase(),
|
|
1017
|
+
id: element.id,
|
|
1018
|
+
labelText: element.label
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* Infer ARIA role from element type
|
|
1023
|
+
*/
|
|
1024
|
+
inferRole(type) {
|
|
1025
|
+
const roleMap = {
|
|
1026
|
+
button: "button",
|
|
1027
|
+
input: "textbox",
|
|
1028
|
+
select: "combobox",
|
|
1029
|
+
checkbox: "checkbox",
|
|
1030
|
+
radio: "radio",
|
|
1031
|
+
link: "link",
|
|
1032
|
+
form: void 0,
|
|
1033
|
+
textarea: "textbox",
|
|
1034
|
+
menu: "menu",
|
|
1035
|
+
menuitem: "menuitem",
|
|
1036
|
+
tab: "tab",
|
|
1037
|
+
dialog: "dialog",
|
|
1038
|
+
custom: void 0,
|
|
1039
|
+
switch: "switch",
|
|
1040
|
+
slider: "slider",
|
|
1041
|
+
combobox: "combobox",
|
|
1042
|
+
listbox: "listbox",
|
|
1043
|
+
option: "option",
|
|
1044
|
+
textbox: "textbox",
|
|
1045
|
+
generic: void 0
|
|
1046
|
+
};
|
|
1047
|
+
return roleMap[type];
|
|
1048
|
+
}
|
|
472
1049
|
/**
|
|
473
1050
|
* Register a component
|
|
474
1051
|
*/
|