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