ax-grep 0.0.0 → 0.1.1

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.
@@ -0,0 +1,612 @@
1
+ // src/browser.ts
2
+ var defaultOptions = {
3
+ mode: "compact",
4
+ includeBounds: true,
5
+ includeAttributes: true,
6
+ includeTextNodes: true,
7
+ includeHidden: false,
8
+ includeSelectOptions: true,
9
+ excludeLikelyAds: false,
10
+ excludeLikelyBoilerplate: false,
11
+ pruneCustomElementWrappers: true,
12
+ pruneCollapsedSubtrees: true,
13
+ pruneLikelyClosedOverlays: false,
14
+ summarizeLargeSubtrees: false,
15
+ summarizeLikelyLinkFarms: false,
16
+ summarizeRepeatedSubtrees: false,
17
+ maxChildrenPerNode: 80,
18
+ maxLinkFarmChildren: 24,
19
+ maxRepeatedSubtreeInstances: 3,
20
+ maxTextLength: 240
21
+ };
22
+ var defaultObserverOptions = {
23
+ debounceMs: 50
24
+ };
25
+ var interactiveRoles = /* @__PURE__ */ new Set([
26
+ "button",
27
+ "checkbox",
28
+ "combobox",
29
+ "link",
30
+ "listbox",
31
+ "menuitem",
32
+ "menuitemcheckbox",
33
+ "menuitemradio",
34
+ "option",
35
+ "radio",
36
+ "searchbox",
37
+ "slider",
38
+ "spinbutton",
39
+ "switch",
40
+ "tab",
41
+ "textbox",
42
+ "treeitem"
43
+ ]);
44
+ var landmarkTags = {
45
+ article: "article",
46
+ aside: "complementary",
47
+ footer: "contentinfo",
48
+ form: "form",
49
+ header: "banner",
50
+ main: "main",
51
+ nav: "navigation",
52
+ section: "region"
53
+ };
54
+ var rolesNamedFromContents = /* @__PURE__ */ new Set([
55
+ "button",
56
+ "cell",
57
+ "checkbox",
58
+ "columnheader",
59
+ "heading",
60
+ "link",
61
+ "menuitem",
62
+ "menuitemcheckbox",
63
+ "menuitemradio",
64
+ "option",
65
+ "radio",
66
+ "rowheader",
67
+ "switch",
68
+ "tab",
69
+ "treeitem"
70
+ ]);
71
+ function extractSemanticTree(options = {}) {
72
+ const rootDocument = document;
73
+ const context = {
74
+ options: { ...defaultOptions, ...options },
75
+ nextId: 1,
76
+ rootDocument
77
+ };
78
+ return walkElement(rootDocument.body ?? rootDocument.documentElement, context) ?? unavailableNode(context, "document", "Document has no inspectable body");
79
+ }
80
+ function formatSemanticTreeText(node) {
81
+ const lines = [];
82
+ function visit(current, depth) {
83
+ const prefix = " ".repeat(depth);
84
+ const role = current.role ?? current.tag;
85
+ const marker = current.interactive ? "[i] " : "";
86
+ const name = current.name ? ` '${current.name}'` : "";
87
+ const state = formatState(current.state);
88
+ const unavailable = current.unavailableReason ? ` (${current.unavailableReason})` : "";
89
+ lines.push(`${prefix}${marker}${role}${name}${state}${unavailable}`);
90
+ for (const child of current.children) visit(child, depth + 1);
91
+ }
92
+ visit(node, 0);
93
+ return lines.join("\n");
94
+ }
95
+ function observeSemanticTree(onChange, options = {}) {
96
+ const root = document.documentElement;
97
+ const observerOptions = { ...defaultObserverOptions, ...options };
98
+ let mutationCount = 0;
99
+ let timeoutId;
100
+ function snapshot() {
101
+ return extractSemanticTree(options);
102
+ }
103
+ function emit() {
104
+ timeoutId = void 0;
105
+ onChange({
106
+ tree: snapshot(),
107
+ changedAt: Date.now(),
108
+ mutationCount
109
+ });
110
+ mutationCount = 0;
111
+ }
112
+ const observer = new MutationObserver((mutations) => {
113
+ mutationCount += mutations.length;
114
+ if (timeoutId !== void 0) window.clearTimeout(timeoutId);
115
+ timeoutId = window.setTimeout(emit, observerOptions.debounceMs);
116
+ });
117
+ observer.observe(root, {
118
+ attributes: true,
119
+ characterData: true,
120
+ childList: true,
121
+ subtree: true
122
+ });
123
+ return {
124
+ disconnect() {
125
+ if (timeoutId !== void 0) window.clearTimeout(timeoutId);
126
+ observer.disconnect();
127
+ },
128
+ snapshot
129
+ };
130
+ }
131
+ function walkElement(element, context) {
132
+ if (!context.options.includeHidden && isHidden(element)) return null;
133
+ if (context.options.excludeLikelyAds && isLikelyAd(element)) return null;
134
+ const role = getRole(element);
135
+ const state = getState(element, context);
136
+ const focusable = isFocusable(element);
137
+ const interactive = isInteractive(element, role, focusable);
138
+ const name = role ? computeName(element, role, context) : "";
139
+ const description = computeDescription(element, context);
140
+ const tag = element.tagName.toLowerCase();
141
+ const children = collectChildren(element, context);
142
+ if (context.options.mode === "interactive" && !interactive) {
143
+ return children.length > 0 ? containerNode(context, tag, children) : null;
144
+ }
145
+ if (shouldPrune(element, role, name, interactive, children, context)) {
146
+ return children.length === 1 ? children[0] ?? null : containerNode(context, tag, children);
147
+ }
148
+ const node = {
149
+ id: nextId(context),
150
+ tag,
151
+ role,
152
+ name,
153
+ interactive,
154
+ focusable,
155
+ children
156
+ };
157
+ if (description) node.description = description;
158
+ const text = getDirectText(element, context.options.maxTextLength);
159
+ if (text) node.text = text;
160
+ const value = getValue(element);
161
+ if (value) node.value = value;
162
+ if (Object.keys(state).length > 0) node.state = state;
163
+ node.selector = getCssPath(element);
164
+ node.xpath = getXPath(element);
165
+ if (context.options.includeBounds) node.bounds = getBounds(element);
166
+ if (context.options.includeAttributes) node.attributes = getAttributes(element);
167
+ appendSpecialChildren(element, node, context);
168
+ appendShadowChildren(element, node, context);
169
+ appendFrameChildren(element, node, context);
170
+ return node;
171
+ }
172
+ function collectChildren(element, context) {
173
+ const children = [];
174
+ for (const child of Array.from(element.childNodes)) {
175
+ if (child.nodeType === Node.ELEMENT_NODE) {
176
+ if (!context.options.includeSelectOptions && element instanceof HTMLSelectElement) continue;
177
+ const semanticChild = walkElement(child, context);
178
+ if (semanticChild) children.push(semanticChild);
179
+ continue;
180
+ }
181
+ if (context.options.includeTextNodes && child.nodeType === Node.TEXT_NODE) {
182
+ const text = normalizeText(child.textContent ?? "", context.options.maxTextLength);
183
+ if (text) {
184
+ children.push({
185
+ id: nextId(context),
186
+ tag: "#text",
187
+ role: "text",
188
+ name: text,
189
+ text,
190
+ interactive: false,
191
+ focusable: false,
192
+ children: []
193
+ });
194
+ }
195
+ }
196
+ }
197
+ return children;
198
+ }
199
+ function shouldPrune(element, role, name, interactive, children, context) {
200
+ if (context.options.mode === "full") return false;
201
+ if (role === "none" || role === "presentation") return true;
202
+ if (interactive) return false;
203
+ if (context.options.pruneCustomElementWrappers && isCustomElement(element)) return children.length > 0;
204
+ if (role && role !== "generic") return false;
205
+ if (name) return false;
206
+ if (element.id || element.getAttribute("aria-label") || element.getAttribute("aria-labelledby")) return false;
207
+ return children.length > 0;
208
+ }
209
+ function getRole(element) {
210
+ const explicit = firstToken(element.getAttribute("role"));
211
+ if (explicit) return explicit;
212
+ const tag = element.tagName.toLowerCase();
213
+ if (tag === "section" && !hasExplicitNameSource(element)) return null;
214
+ if (tag === "form" && !hasExplicitNameSource(element)) return null;
215
+ if (tag in landmarkTags) return landmarkTags[tag] ?? null;
216
+ if (/^h[1-6]$/.test(tag)) return "heading";
217
+ if (tag === "a" || tag === "area") return element.hasAttribute("href") ? "link" : null;
218
+ if (tag === "button") return "button";
219
+ if (tag === "details") return "group";
220
+ if (tag === "dialog") return "dialog";
221
+ if (tag === "fieldset") return "group";
222
+ if (tag === "figure") return "figure";
223
+ if (tag === "iframe") return "iframe";
224
+ if (tag === "img") return hasEmptyAlt(element) ? "presentation" : "img";
225
+ if (tag === "li") return "listitem";
226
+ if (tag === "ol" || tag === "ul") return "list";
227
+ if (tag === "optgroup") return "group";
228
+ if (tag === "option") return "option";
229
+ if (tag === "output") return "status";
230
+ if (tag === "progress") return "progressbar";
231
+ if (tag === "select") return element.hasAttribute("multiple") ? "listbox" : "combobox";
232
+ if (tag === "summary") return "button";
233
+ if (tag === "table") return "table";
234
+ if (tag === "caption") return "caption";
235
+ if (tag === "tbody" || tag === "tfoot" || tag === "thead") return "rowgroup";
236
+ if (tag === "td") return "cell";
237
+ if (tag === "textarea") return "textbox";
238
+ if (tag === "th") return element.getAttribute("scope") === "row" ? "rowheader" : "columnheader";
239
+ if (tag === "tr") return "row";
240
+ if (tag === "input") return inputRole(element);
241
+ return null;
242
+ }
243
+ function inputRole(input) {
244
+ const type = (input.getAttribute("type") || "text").toLowerCase();
245
+ if (type === "button" || type === "image" || type === "reset" || type === "submit") return "button";
246
+ if (type === "checkbox") return "checkbox";
247
+ if (type === "email" || type === "tel" || type === "text" || type === "url") return "textbox";
248
+ if (type === "number") return "spinbutton";
249
+ if (type === "radio") return "radio";
250
+ if (type === "range") return "slider";
251
+ if (type === "search") return "searchbox";
252
+ if (type === "hidden") return null;
253
+ return "textbox";
254
+ }
255
+ function computeName(element, role, context) {
256
+ if (element.getAttribute("aria-labelledby")) {
257
+ const labelled = textFromIds(element.getAttribute("aria-labelledby") ?? "", context.rootDocument);
258
+ if (labelled) return labelled;
259
+ }
260
+ const ariaLabel = element.getAttribute("aria-label");
261
+ if (ariaLabel) return normalizeText(ariaLabel, context.options.maxTextLength);
262
+ if (element instanceof HTMLInputElement && isButtonLikeInput(element)) {
263
+ return normalizeText(element.value || element.getAttribute("value") || inputFallbackName(element), context.options.maxTextLength);
264
+ }
265
+ if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {
266
+ const label = labelText(element, context);
267
+ if (label) return label;
268
+ const placeholder = element.getAttribute("placeholder");
269
+ if (placeholder) return normalizeText(placeholder, context.options.maxTextLength);
270
+ }
271
+ if (element instanceof HTMLImageElement) {
272
+ return normalizeText(element.alt || element.getAttribute("title") || "", context.options.maxTextLength);
273
+ }
274
+ if (element instanceof HTMLFieldSetElement) {
275
+ const legend = element.querySelector(":scope > legend");
276
+ if (legend) return getVisibleText(legend, context.options.maxTextLength);
277
+ }
278
+ if (rolesNamedFromContents.has(role)) {
279
+ const ownText = getVisibleText(element, context.options.maxTextLength);
280
+ if (ownText) return ownText;
281
+ }
282
+ return normalizeText(element.getAttribute("title") ?? "", context.options.maxTextLength);
283
+ }
284
+ function computeDescription(element, context) {
285
+ const describedBy = element.getAttribute("aria-describedby");
286
+ if (describedBy) return textFromIds(describedBy, context.rootDocument);
287
+ return normalizeText(element.getAttribute("title") ?? "", context.options.maxTextLength);
288
+ }
289
+ function labelText(element, context) {
290
+ if (element.labels && element.labels.length > 0) {
291
+ return normalizeText(Array.from(element.labels).map((label) => getVisibleText(label, context.options.maxTextLength)).join(" "), context.options.maxTextLength);
292
+ }
293
+ return "";
294
+ }
295
+ function getState(element, context) {
296
+ const state = {};
297
+ if (isHidden(element)) state.hidden = true;
298
+ if (isDisabled(element)) state.disabled = true;
299
+ const busy = ariaBoolean(element.getAttribute("aria-busy"));
300
+ if (busy !== void 0) state.busy = busy;
301
+ const multiselectable = ariaBoolean(element.getAttribute("aria-multiselectable"));
302
+ if (multiselectable !== void 0) state.multiselectable = multiselectable;
303
+ const sort = element.getAttribute("aria-sort");
304
+ if (sort) state.sort = normalizeText(sort, 40);
305
+ const grabbed = ariaBoolean(element.getAttribute("aria-grabbed"));
306
+ if (grabbed !== void 0) state.grabbed = grabbed;
307
+ const dropEffect = element.getAttribute("aria-dropeffect");
308
+ if (dropEffect) state.dropEffect = normalizeText(dropEffect, 80);
309
+ if (element === document.activeElement) state.focused = true;
310
+ const checked = ariaBooleanOrMixed(element.getAttribute("aria-checked"));
311
+ if (checked !== void 0) state.checked = checked;
312
+ else if (element instanceof HTMLInputElement && (element.type === "checkbox" || element.type === "radio")) {
313
+ state.checked = element.checked;
314
+ }
315
+ const selected = ariaBoolean(element.getAttribute("aria-selected"));
316
+ if (selected !== void 0) state.selected = selected;
317
+ else if (element instanceof HTMLOptionElement) state.selected = element.selected;
318
+ const expanded = ariaBoolean(element.getAttribute("aria-expanded"));
319
+ if (expanded !== void 0) state.expanded = expanded;
320
+ const pressed = ariaBooleanOrMixed(element.getAttribute("aria-pressed"));
321
+ if (pressed !== void 0) state.pressed = pressed;
322
+ const required = ariaBoolean(element.getAttribute("aria-required"));
323
+ if (required !== void 0) state.required = required;
324
+ else if ("required" in element && Boolean(element.required)) state.required = true;
325
+ const invalid = element.getAttribute("aria-invalid");
326
+ if (invalid && invalid !== "false") state.invalid = invalid === "true" ? true : invalid;
327
+ if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement) {
328
+ if (element.readOnly) state.readonly = true;
329
+ }
330
+ const current = element.getAttribute("aria-current");
331
+ if (current && current !== "false") state.current = current === "true" ? true : current;
332
+ const haspopup = element.getAttribute("aria-haspopup");
333
+ if (haspopup && haspopup !== "false") state.haspopup = haspopup === "true" ? true : haspopup;
334
+ const controls = element.getAttribute("aria-controls");
335
+ if (controls) state.controls = normalizeText(controls, context.options.maxTextLength);
336
+ const live = element.getAttribute("aria-live");
337
+ if (live) state.live = normalizeText(live, context.options.maxTextLength);
338
+ if (element.getAttribute("aria-modal") === "true") state.modal = true;
339
+ const orientation = element.getAttribute("aria-orientation");
340
+ if (orientation) state.orientation = normalizeText(orientation, 40);
341
+ const valueMin = ariaNumber(element.getAttribute("aria-valuemin"));
342
+ if (typeof valueMin === "number") state.valueMin = valueMin;
343
+ const valueMax = ariaNumber(element.getAttribute("aria-valuemax"));
344
+ if (typeof valueMax === "number") state.valueMax = valueMax;
345
+ const valueNow = ariaNumber(element.getAttribute("aria-valuenow"));
346
+ if (typeof valueNow === "number") state.valueNow = valueNow;
347
+ const valueText = element.getAttribute("aria-valuetext");
348
+ if (valueText) state.valueText = normalizeText(valueText, context.options.maxTextLength);
349
+ return state;
350
+ }
351
+ function isHidden(element) {
352
+ if (element.hasAttribute("hidden")) return true;
353
+ if (element.getAttribute("aria-hidden") === "true") return true;
354
+ const style = getComputedStyle(element);
355
+ if (style.display === "none" || style.visibility === "hidden" || style.contentVisibility === "hidden") return true;
356
+ if (Number(style.opacity) === 0) return true;
357
+ return false;
358
+ }
359
+ function isLikelyAd(element) {
360
+ const haystack = [
361
+ element.id,
362
+ element.getAttribute("class"),
363
+ element.getAttribute("aria-label"),
364
+ element.getAttribute("data-testid"),
365
+ element.getAttribute("data-test-id"),
366
+ element.getAttribute("data-name")
367
+ ].filter(Boolean).join(" ").toLowerCase();
368
+ if (/\b(ad|ads|advert|advertisement|sponsor|sponsored|placement)\b/.test(haystack)) return true;
369
+ if (element instanceof HTMLAnchorElement && normalizeText(element.textContent ?? "", 80).toLowerCase() === "ad") return true;
370
+ return false;
371
+ }
372
+ function isDisabled(element) {
373
+ if (element.getAttribute("aria-disabled") === "true") return true;
374
+ return "disabled" in element && Boolean(element.disabled);
375
+ }
376
+ function isFocusable(element) {
377
+ if (isDisabled(element) || isHidden(element)) return false;
378
+ const tabindex = element.getAttribute("tabindex");
379
+ if (tabindex !== null) return Number(tabindex) >= 0;
380
+ return element.matches("a[href],area[href],button,input,select,textarea,summary,iframe,[contenteditable=''],[contenteditable='true']");
381
+ }
382
+ function isInteractive(element, role, focusable) {
383
+ if (role && interactiveRoles.has(role)) return true;
384
+ if (element.matches("a[href],button,input,select,textarea,summary,option")) return true;
385
+ if (element.hasAttribute("onclick")) return true;
386
+ return focusable && Boolean(role);
387
+ }
388
+ function appendSpecialChildren(element, node, context) {
389
+ if (!context.options.includeSelectOptions) return;
390
+ if (element instanceof HTMLSelectElement) {
391
+ for (const option of Array.from(element.options)) {
392
+ node.children.push({
393
+ id: nextId(context),
394
+ tag: "option",
395
+ role: "option",
396
+ name: normalizeText(option.textContent ?? "", context.options.maxTextLength),
397
+ value: option.value,
398
+ state: { selected: option.selected, disabled: option.disabled },
399
+ interactive: false,
400
+ focusable: false,
401
+ selector: getCssPath(option),
402
+ xpath: getXPath(option),
403
+ children: []
404
+ });
405
+ }
406
+ }
407
+ }
408
+ function isCustomElement(element) {
409
+ return element.tagName.includes("-");
410
+ }
411
+ function appendShadowChildren(element, node, context) {
412
+ const shadowRoot = element.shadowRoot;
413
+ if (!shadowRoot) return;
414
+ for (const child of Array.from(shadowRoot.children)) {
415
+ const semanticChild = walkElement(child, context);
416
+ if (semanticChild) node.children.push(semanticChild);
417
+ }
418
+ }
419
+ function appendFrameChildren(element, node, context) {
420
+ if (!(element instanceof HTMLIFrameElement)) return;
421
+ try {
422
+ const frameDocument = element.contentDocument;
423
+ if (!frameDocument?.body) {
424
+ node.children.push(unavailableNode(context, "iframe", "iframe document unavailable"));
425
+ return;
426
+ }
427
+ const previousDocument = context.rootDocument;
428
+ context.rootDocument = frameDocument;
429
+ const child = walkElement(frameDocument.body, context);
430
+ context.rootDocument = previousDocument;
431
+ if (child) node.children.push(child);
432
+ } catch {
433
+ node.children.push(unavailableNode(context, "iframe", "cross-origin iframe"));
434
+ }
435
+ }
436
+ function unavailableNode(context, tag, reason) {
437
+ return {
438
+ id: nextId(context),
439
+ tag,
440
+ role: null,
441
+ name: "",
442
+ interactive: false,
443
+ focusable: false,
444
+ unavailableReason: reason,
445
+ children: []
446
+ };
447
+ }
448
+ function containerNode(context, tag, children) {
449
+ return {
450
+ id: nextId(context),
451
+ tag,
452
+ role: null,
453
+ name: "",
454
+ interactive: false,
455
+ focusable: false,
456
+ children
457
+ };
458
+ }
459
+ function getValue(element) {
460
+ if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {
461
+ return element.value;
462
+ }
463
+ return normalizeText(element.getAttribute("aria-valuetext") ?? element.getAttribute("aria-valuenow") ?? "", 80);
464
+ }
465
+ function getDirectText(element, maxLength) {
466
+ return normalizeText(
467
+ Array.from(element.childNodes).filter((node) => node.nodeType === Node.TEXT_NODE).map((node) => node.textContent ?? "").join(" "),
468
+ maxLength
469
+ );
470
+ }
471
+ function getVisibleText(element, maxLength) {
472
+ const parts = [];
473
+ function visit(node) {
474
+ if (node.nodeType === Node.TEXT_NODE) {
475
+ parts.push(node.textContent ?? "");
476
+ return;
477
+ }
478
+ if (node.nodeType !== Node.ELEMENT_NODE) return;
479
+ const childElement = node;
480
+ if (isHidden(childElement)) return;
481
+ for (const child of Array.from(childElement.childNodes)) visit(child);
482
+ }
483
+ visit(element);
484
+ return normalizeText(parts.join(" "), maxLength);
485
+ }
486
+ function getAttributes(element) {
487
+ const attributes = {};
488
+ for (const attribute of Array.from(element.attributes)) {
489
+ if (attribute.name === "id" || attribute.name === "href" || attribute.name === "type" || attribute.name === "role" || attribute.name === "alt" || attribute.name === "title" || attribute.name.startsWith("aria-") || attribute.name.startsWith("data-")) {
490
+ attributes[attribute.name] = attribute.value;
491
+ }
492
+ }
493
+ return attributes;
494
+ }
495
+ function getBounds(element) {
496
+ const rect = element.getBoundingClientRect();
497
+ return {
498
+ x: round(rect.x),
499
+ y: round(rect.y),
500
+ width: round(rect.width),
501
+ height: round(rect.height)
502
+ };
503
+ }
504
+ function getCssPath(element) {
505
+ if (element.id) return `#${cssEscape(element.id)}`;
506
+ const segments = [];
507
+ let current = element;
508
+ while (current && current.nodeType === Node.ELEMENT_NODE && current !== document.documentElement) {
509
+ const elementAtLevel = current;
510
+ const tag = elementAtLevel.tagName.toLowerCase();
511
+ const parent = elementAtLevel.parentElement;
512
+ if (!parent) {
513
+ segments.unshift(tag);
514
+ break;
515
+ }
516
+ const siblings = Array.from(parent.children).filter((child) => child.tagName === elementAtLevel.tagName);
517
+ const index = siblings.indexOf(elementAtLevel) + 1;
518
+ segments.unshift(siblings.length > 1 ? `${tag}:nth-of-type(${index})` : tag);
519
+ current = parent;
520
+ }
521
+ return segments.join(" > ");
522
+ }
523
+ function getXPath(element) {
524
+ const segments = [];
525
+ let current = element;
526
+ while (current && current.nodeType === Node.ELEMENT_NODE) {
527
+ const elementAtLevel = current;
528
+ const tag = elementAtLevel.tagName.toLowerCase();
529
+ const parent = elementAtLevel.parentElement;
530
+ if (!parent) {
531
+ segments.unshift(`/${tag}[1]`);
532
+ break;
533
+ }
534
+ const sameTag = Array.from(parent.children).filter((child) => child.tagName === elementAtLevel.tagName);
535
+ segments.unshift(`/${tag}[${sameTag.indexOf(elementAtLevel) + 1}]`);
536
+ current = parent;
537
+ }
538
+ return segments.join("");
539
+ }
540
+ function textFromIds(ids, rootDocument) {
541
+ return normalizeText(
542
+ ids.split(/\s+/).map((id) => {
543
+ const element = rootDocument.getElementById(id);
544
+ return element ? getVisibleText(element, 240) : "";
545
+ }).filter(Boolean).join(" "),
546
+ 240
547
+ );
548
+ }
549
+ function normalizeText(value, maxLength) {
550
+ const normalized = value.replace(/\s+/g, " ").trim();
551
+ return normalized.length > maxLength ? `${normalized.slice(0, maxLength - 1)}\u2026` : normalized;
552
+ }
553
+ function firstToken(value) {
554
+ return value?.trim().split(/\s+/)[0] || null;
555
+ }
556
+ function hasExplicitNameSource(element) {
557
+ return Boolean(
558
+ element.getAttribute("aria-label") || element.getAttribute("aria-labelledby") || element.getAttribute("title")
559
+ );
560
+ }
561
+ function hasEmptyAlt(element) {
562
+ return element.hasAttribute("alt") && element.getAttribute("alt") === "";
563
+ }
564
+ function isButtonLikeInput(input) {
565
+ return ["button", "image", "reset", "submit"].includes((input.getAttribute("type") || "").toLowerCase());
566
+ }
567
+ function inputFallbackName(input) {
568
+ const type = (input.getAttribute("type") || "").toLowerCase();
569
+ if (type === "submit") return "Submit";
570
+ if (type === "reset") return "Reset";
571
+ return "";
572
+ }
573
+ function ariaBoolean(value) {
574
+ if (value === "true") return true;
575
+ if (value === "false") return false;
576
+ return void 0;
577
+ }
578
+ function ariaBooleanOrMixed(value) {
579
+ if (value === "mixed") return "mixed";
580
+ return ariaBoolean(value);
581
+ }
582
+ function ariaNumber(value) {
583
+ if (value === null || value.trim() === "") return void 0;
584
+ const parsed = Number(value);
585
+ return Number.isFinite(parsed) ? parsed : void 0;
586
+ }
587
+ function formatState(state) {
588
+ if (!state) return "";
589
+ const entries = Object.entries(state).filter(([, value]) => value !== void 0);
590
+ return entries.length > 0 ? ` [${entries.map(([key, value]) => `${key}=${String(value)}`).join(" ")}]` : "";
591
+ }
592
+ function nextId(context) {
593
+ const id = `n${context.nextId}`;
594
+ context.nextId += 1;
595
+ return id;
596
+ }
597
+ function round(value) {
598
+ return Math.round(value * 100) / 100;
599
+ }
600
+ function cssEscape(value) {
601
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
602
+ return CSS.escape(value);
603
+ }
604
+ return value.replace(/[^a-zA-Z0-9_-]/g, (char) => `\\${char}`);
605
+ }
606
+
607
+ export {
608
+ extractSemanticTree,
609
+ formatSemanticTreeText,
610
+ observeSemanticTree
611
+ };
612
+ //# sourceMappingURL=chunk-HPZ32BKV.js.map