@sedum-dev/core 0.1.0-alpha.6 → 0.1.0-alpha.9

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.
@@ -179,14 +179,18 @@ var SedumPageScript = (() => {
179
179
  return true;
180
180
  }
181
181
  return false;
182
- }, publicText = function(element, visualOnly = false) {
182
+ }, publicText = function(element, visualOnly = false, ownOnly = false) {
183
183
  const parts = [];
184
184
  for (const node of flatTextNodes(element)) {
185
185
  const parent = node.parentElement;
186
- if (parent && visible(parent, visualOnly) && !excludedTextAncestor(parent))
186
+ if (parent && visible(parent, visualOnly) && !excludedTextAncestor(parent) && !(ownOnly && insideNestedControl(element, parent)))
187
187
  parts.push(node.textContent ?? "");
188
188
  }
189
189
  return parts.join(" ").replace(/\s+/g, " ").trim();
190
+ }, insideNestedControl = function(element, node) {
191
+ for (let current = node; current && current !== element; current = composedParent(current))
192
+ if (interactive(current)) return true;
193
+ return false;
190
194
  }, referencedLabelText = function(element) {
191
195
  const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT);
192
196
  const parts = [];
@@ -223,7 +227,7 @@ var SedumPageScript = (() => {
223
227
  const value = element.value.trim();
224
228
  if (value) return value;
225
229
  }
226
- return publicText(element, visualOnly) || element.getAttribute("title")?.trim() || "";
230
+ return publicText(element, visualOnly, true) || element.getAttribute("title")?.trim() || "";
227
231
  }, nearbyText = function(element) {
228
232
  const box = element.getBoundingClientRect();
229
233
  if (!box.width || !box.height) return "";
@@ -279,6 +283,8 @@ var SedumPageScript = (() => {
279
283
  }, iconName = function(element) {
280
284
  for (const node of Array.from(element.querySelectorAll("i,span,em"))) {
281
285
  if (node.textContent?.trim()) continue;
286
+ if (!node.getClientRects().length || insideNestedControl(element, node))
287
+ continue;
282
288
  for (const token of Array.from(node.classList)) {
283
289
  const match = /^(?:fa|bi|glyphicon|icon|mdi|ti|ri)-([a-z][a-z0-9-]*)$/.exec(token);
284
290
  if (match && !/^(lg|[0-9]x|fw|solid|regular|light|brands|spin|pulse|border|inverse|stack.*|rotate.*|flip.*)$/.test(
@@ -329,15 +335,28 @@ var SedumPageScript = (() => {
329
335
  let distance = Infinity;
330
336
  if (sameLine && rect.right <= box.left + 2)
331
337
  distance = box.left - rect.right;
338
+ else if (sameLine && rect.left >= box.right - 2)
339
+ distance = rect.left - box.right;
332
340
  else if (rect.bottom <= box.top + 2 && rect.left < box.right)
333
341
  distance = box.top - rect.bottom;
334
342
  if (distance > 400) continue;
335
343
  if (!best || distance < best.distance) best = { text: value, distance };
336
344
  }
337
345
  return best?.text ?? "";
338
- }, candidateName = function(element) {
346
+ }, hiddenControlText = function(element) {
347
+ const parts = [];
348
+ for (const node of flatTextNodes(element)) {
349
+ const parent = node.parentElement;
350
+ if (!parent || parent.closest(
351
+ "script,style,noscript,input,textarea,select,[contenteditable]"
352
+ ) || insideNestedControl(element, parent))
353
+ continue;
354
+ parts.push(node.textContent ?? "");
355
+ }
356
+ return parts.join(" ").replace(/\s+/g, " ").trim();
357
+ }, candidateName = function(element, hoverRevealed3 = false) {
339
358
  const visualOnly = ariaHiddenOnly(element);
340
- return label(element, visualOnly) || mediaName(element) || nearbyText(element) || hostLabel(element) || iconName(element) || describedText(element) || rowLabel(element);
359
+ return label(element, visualOnly) || (hoverRevealed3 ? hiddenControlText(element) : "") || mediaName(element) || nearbyText(element) || hostLabel(element) || iconName(element) || describedText(element) || rowLabel(element);
341
360
  }, hintWords = function(text) {
342
361
  return text.toLocaleLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
343
362
  }, addsWords = function(text, name) {
@@ -370,6 +389,19 @@ var SedumPageScript = (() => {
370
389
  const placeholder = element.getAttribute("placeholder")?.trim() ?? "";
371
390
  if (placeholder && placeholder !== name)
372
391
  addPart(`placeholder "${clip(placeholder)}"`, placeholder);
392
+ const ariaLabel = element.getAttribute("aria-label")?.trim();
393
+ const labelledBy = element.getAttribute("aria-labelledby")?.split(/\s+/).some((id) => {
394
+ const labelled = document.getElementById(id);
395
+ return labelled && referencedLabelText(labelled);
396
+ });
397
+ const nativeLabel = Array.from(element.labels ?? []).some(
398
+ (node) => Boolean(publicText(node).trim())
399
+ );
400
+ if (placeholder && placeholder === name && !ariaLabel && !labelledBy && !nativeLabel) {
401
+ const caption = nearbyText(element) || rowLabel(element);
402
+ if (caption && caption !== placeholder)
403
+ addPart(`label "${clip(caption)}"`, caption);
404
+ }
373
405
  }
374
406
  const named = element.hasAttribute("aria-label") || element.hasAttribute("aria-labelledby");
375
407
  const shown = publicText(element, true);
@@ -412,6 +444,16 @@ var SedumPageScript = (() => {
412
444
  if (kind) addPart(`${kind[1]} icon`, kind[1]);
413
445
  }
414
446
  if (kbdText && kbdText === shown) addPart("keyboard shortcut");
447
+ const items = Array.from(element.querySelectorAll("*")).filter((node) => node !== element && interactive(node) && !visible(node)).slice(0, 6).map((node) => {
448
+ const glyph = Array.from(node.querySelectorAll("i,span,em")).flatMap((icon) => Array.from(icon.classList)).map(
449
+ (token) => /^(?:fa|bi|icon|mdi|ti|ri)-([a-z][a-z0-9-]*)$/.exec(token)?.[1]
450
+ ).find(
451
+ (name2) => name2 && !/^(lg|[0-9]x|fw|solid|regular|light)$/.test(name2)
452
+ );
453
+ return [glyph?.replace(/-/g, " "), referencedLabelText(node)].filter(Boolean).join(" ");
454
+ }).filter(Boolean);
455
+ if (items.length)
456
+ addPart(`menu "${clip(items.join(", "), 80)}"`, items.join(" "));
415
457
  return parts.join(", ");
416
458
  }, countBadgeKind = function(node, count) {
417
459
  const tokens = [];
@@ -474,7 +516,191 @@ var SedumPageScript = (() => {
474
516
  for (let node = parent; node; node = composedParent(node))
475
517
  if (interactive(node)) return false;
476
518
  const inside = allElements(element, 500);
477
- return !!inside && !inside.some((node) => interactive(node) || node.hasAttribute("role"));
519
+ if (!inside) return false;
520
+ const controls = inside.filter(
521
+ (node) => interactive(node) || node.hasAttribute("role")
522
+ );
523
+ if (!controls.length) return true;
524
+ return controls.every(
525
+ (control) => !interactive(control) || !publicText(control, true)
526
+ ) && !!publicText(element, false, true);
527
+ }, selectorList = function(text) {
528
+ const selectors = [];
529
+ let start = 0;
530
+ let depth = 0;
531
+ let quote = "";
532
+ for (let index = 0; index < text.length; index++) {
533
+ const char = text[index];
534
+ if (quote) {
535
+ if (char === quote && text[index - 1] !== "\\") quote = "";
536
+ } else if (char === '"' || char === "'") quote = char;
537
+ else if (char === "(" || char === "[") depth++;
538
+ else if (char === ")" || char === "]") depth--;
539
+ else if (char === "," && depth === 0) {
540
+ selectors.push(text.slice(start, index).trim());
541
+ start = index + 1;
542
+ }
543
+ }
544
+ selectors.push(text.slice(start).trim());
545
+ return selectors.filter(Boolean);
546
+ }, specificity = function(selector) {
547
+ if (/\\|\||::|:[\w-]+\(/.test(selector)) return null;
548
+ const attributes = selector.match(/\[[^\]]*\]/g)?.length ?? 0;
549
+ const bare = selector.replace(/\[[^\]]*\]/g, " ");
550
+ const ids = bare.match(/#[\w-]+/g)?.length ?? 0;
551
+ const classes = bare.match(/\.[\w-]+/g)?.length ?? 0;
552
+ const pseudos = bare.match(/:(?!:)[\w-]+/g)?.length ?? 0;
553
+ const withoutQualifiers = bare.replace(/#[\w-]+|\.[\w-]+|:(?!:)[\w-]+/g, "").replace(/\*/g, "");
554
+ const types = withoutQualifiers.match(/(?:^|[\s>+~])([a-zA-Z][\w-]*)/g)?.length ?? 0;
555
+ return [ids, attributes + classes + pseudos, types];
556
+ }, stronger = function(a, b, property) {
557
+ const importantA = a.style.getPropertyPriority(property) === "important";
558
+ const importantB = b.style.getPropertyPriority(property) === "important";
559
+ if (importantA !== importantB) return importantA;
560
+ if (!a.specificity || !b.specificity) return false;
561
+ for (let index = 0; index < 3; index++) {
562
+ if (a.specificity[index] !== b.specificity[index])
563
+ return a.specificity[index] > b.specificity[index];
564
+ }
565
+ return a.order > b.order;
566
+ }, hoverWins = function(element, property, reveal) {
567
+ let winner = null;
568
+ for (const rule of cascadeRules) {
569
+ if (!rule.style.getPropertyValue(property)) continue;
570
+ try {
571
+ if (!element.matches(rule.match)) continue;
572
+ } catch {
573
+ return false;
574
+ }
575
+ if (!rule.specificity) return false;
576
+ if (!winner || stronger(rule, winner, property)) winner = rule;
577
+ }
578
+ return winner?.order === reveal.order && winner.selector === reveal.selector;
579
+ }, readHoverRules = function() {
580
+ const rules = [];
581
+ const declarations = [];
582
+ let order = 0;
583
+ let complete = true;
584
+ const visit = (list, safe = true) => {
585
+ for (const rule of Array.from(list)) {
586
+ if (rule instanceof CSSStyleRule) {
587
+ const style = rule.style;
588
+ const display = style.display !== "" && style.display !== "none";
589
+ const visibility = style.visibility === "visible";
590
+ const opacity = style.opacity !== "" && Number.parseFloat(style.opacity) > 0;
591
+ const reveals = display || visibility || opacity;
592
+ for (const selector of selectorList(rule.selectorText)) {
593
+ const revealed = selector.replace(/:hover/g, "").trim();
594
+ const declaration = {
595
+ selector,
596
+ match: revealed,
597
+ specificity: safe ? specificity(selector) : null,
598
+ order: ++order,
599
+ style
600
+ };
601
+ try {
602
+ document.querySelector(revealed);
603
+ } catch {
604
+ continue;
605
+ }
606
+ declarations.push(declaration);
607
+ if (!safe || !declaration.specificity || !reveals || !selector.includes(":hover"))
608
+ continue;
609
+ const at = selector.lastIndexOf(":hover");
610
+ const host = selector.slice(0, at).replace(/:hover/g, "").trim();
611
+ if (!host || host === revealed) continue;
612
+ try {
613
+ document.querySelector(host);
614
+ rules.push({
615
+ ...declaration,
616
+ revealed,
617
+ host,
618
+ display,
619
+ visibility,
620
+ opacity
621
+ });
622
+ } catch {
623
+ }
624
+ }
625
+ } else if (rule instanceof CSSImportRule) {
626
+ try {
627
+ if (rule.styleSheet) visit(rule.styleSheet.cssRules, safe);
628
+ else complete = false;
629
+ } catch {
630
+ complete = false;
631
+ }
632
+ } else if ("cssRules" in rule) {
633
+ const name = rule.constructor.name;
634
+ if (name === "CSSMediaRule" && !matchMedia(rule.conditionText).matches)
635
+ continue;
636
+ if (name === "CSSSupportsRule" && !CSS.supports(rule.conditionText))
637
+ continue;
638
+ visit(
639
+ rule.cssRules,
640
+ safe && ![
641
+ "CSSLayerBlockRule",
642
+ "CSSScopeRule",
643
+ "CSSContainerRule"
644
+ ].includes(name)
645
+ );
646
+ }
647
+ }
648
+ };
649
+ for (const sheet of Array.from(document.styleSheets)) {
650
+ try {
651
+ visit(sheet.cssRules);
652
+ } catch {
653
+ complete = false;
654
+ }
655
+ }
656
+ cascadeRules = complete ? declarations : [];
657
+ if (!complete) return [];
658
+ return rules;
659
+ }, hoverHost = function(element) {
660
+ if (!interactive(element)) return null;
661
+ if (element.closest("[hidden],[inert],[aria-hidden='true']")) return null;
662
+ hoverRules ??= readHoverRules();
663
+ const path3 = [];
664
+ for (let node = element; node && node !== document.body; node = composedParent(node)) {
665
+ path3.push(node);
666
+ if (node !== element && interactive(node)) return null;
667
+ }
668
+ const plans = /* @__PURE__ */ new Map();
669
+ for (const node of path3) {
670
+ for (const rule of hoverRules) {
671
+ if (!node.matches(rule.revealed)) continue;
672
+ let host = node;
673
+ while (host && !host.matches(rule.host)) host = composedParent(host);
674
+ if (!host || !visible(host)) continue;
675
+ const plan = plans.get(host) ?? {
676
+ display: /* @__PURE__ */ new Set(),
677
+ visibility: false,
678
+ opacity: false
679
+ };
680
+ if (rule.display && hoverWins(node, "display", rule))
681
+ plan.display.add(node);
682
+ plan.visibility ||= rule.visibility && hoverWins(node, "visibility", rule);
683
+ plan.opacity ||= rule.opacity && hoverWins(node, "opacity", rule);
684
+ plans.set(host, plan);
685
+ }
686
+ }
687
+ return Array.from(plans).filter(([host, plan]) => {
688
+ for (const node of path3.slice(0, path3.indexOf(host) + 1)) {
689
+ const style = getComputedStyle(node);
690
+ if (style.contentVisibility === "hidden") return false;
691
+ if (node instanceof HTMLElement && (node.style.display === "none" || node.style.visibility === "hidden" || Number.parseFloat(node.style.opacity) === 0))
692
+ return false;
693
+ if (style.display === "none" && !plan.display.has(node))
694
+ return false;
695
+ if ((style.visibility === "hidden" || style.visibility === "collapse") && !plan.visibility)
696
+ return false;
697
+ if (Number.parseFloat(style.opacity) === 0 && !plan.opacity)
698
+ return false;
699
+ }
700
+ return true;
701
+ }).map(([host]) => host).sort((a, b) => path3.indexOf(a) - path3.indexOf(b))[0] ?? null;
702
+ }, hoverRevealed = function(element) {
703
+ return !visible(element) && !!hoverHost(element);
478
704
  }, landmarkOf = function(node) {
479
705
  const tag = node.tagName.toLowerCase();
480
706
  const explicit = node.getAttribute("role");
@@ -672,7 +898,7 @@ var SedumPageScript = (() => {
672
898
  break;
673
899
  }
674
900
  const sameLabel = Array.from(possible).filter(
675
- (item2) => visible(item2) && label(item2) === name
901
+ (item2) => (visible(item2) || hoverRevealed(item2)) && (label(item2) || mediaName(item2) || iconName(item2)) === name
676
902
  );
677
903
  if (sameLabel.length > 1) {
678
904
  region = lastUnique;
@@ -680,6 +906,7 @@ var SedumPageScript = (() => {
680
906
  }
681
907
  lastUnique = region;
682
908
  if (region.matches("article,li,[data-product],[role='listitem']")) break;
909
+ if (operation === "click" && pointerTarget(region)) break;
683
910
  const container = region;
684
911
  if (operation === "read" && container.classList.length > 0 && Array.from(container.parentElement?.children ?? []).some(
685
912
  (sibling) => sibling !== container && sibling.tagName === container.tagName && sibling.classList.length === container.classList.length && Array.from(container.classList).every(
@@ -743,6 +970,7 @@ var SedumPageScript = (() => {
743
970
  };
744
971
  const outline = [];
745
972
  titleCache.clear();
973
+ hoverRules = void 0;
746
974
  for (const element of elements) {
747
975
  if (element.matches("h1,h2,h3,h4,h5,h6,[role='heading']")) {
748
976
  const text = visible(element) ? publicText(element) : "";
@@ -757,12 +985,13 @@ var SedumPageScript = (() => {
757
985
  }
758
986
  }
759
987
  const proxied = operation === "click" ? toggleLabel(element) : null;
760
- if (!(visible(element) || transparentToggle(element) || operation === "click" && ariaHiddenOnly(element)) || (operation === "read" ? !readable(element) : !interactive(element) && !proxied && (operation !== "click" || !pointerTarget(element))))
988
+ const shownByHover = operation === "click" && !visible(element) ? hoverHost(element) : null;
989
+ if (!(visible(element) || transparentToggle(element) || operation === "click" && (ariaHiddenOnly(element) || shownByHover)) || (operation === "read" ? !readable(element) : !interactive(element) && !proxied && (operation !== "click" || !pointerTarget(element))))
761
990
  continue;
762
991
  if (operation === "fill" && !editable(element)) continue;
763
992
  if (operation === "click" && editable(element) && !element.matches("input[type='checkbox'],input[type='radio']") && role(element) !== "combobox" && !element.readOnly)
764
993
  continue;
765
- const rawName = operation === "read" ? label(element) : candidateName(element);
994
+ const rawName = operation === "read" ? label(element) : candidateName(element, !!shownByHover);
766
995
  if (!rawName) continue;
767
996
  const name = boundedName(rawName);
768
997
  const ref = `${documentId}-${++sequence}`;
@@ -876,6 +1105,8 @@ var SedumPageScript = (() => {
876
1105
  }
877
1106
  return parts.join(" ").replace(/\s+/g, " ").trim();
878
1107
  }, digest = function() {
1108
+ return pageText(DIGEST_LIMIT);
1109
+ }, pageText = function(limit) {
879
1110
  const current = version();
880
1111
  const selectedModal = modal();
881
1112
  if (selectedModal === void 0)
@@ -919,7 +1150,7 @@ var SedumPageScript = (() => {
919
1150
  const part2 = !selection ? "" : name ? `${name}: ${selection}` : selection;
920
1151
  if (!part2) continue;
921
1152
  size += Array.from(part2).length + (pieces.length ? 1 : 0);
922
- if (size > DIGEST_LIMIT)
1153
+ if (size > limit)
923
1154
  return {
924
1155
  protocol: PAGE_PROTOCOL,
925
1156
  version: current,
@@ -936,7 +1167,7 @@ var SedumPageScript = (() => {
936
1167
  const kind = /^\d{1,4}\+?$/.test(text) ? countBadgeKind(parent, text) : "";
937
1168
  const part = kind ? `${kind} icon badge: ${text}` : text;
938
1169
  size += Array.from(part).length + (pieces.length ? 1 : 0);
939
- if (size > DIGEST_LIMIT)
1170
+ if (size > limit)
940
1171
  return {
941
1172
  protocol: PAGE_PROTOCOL,
942
1173
  version: current,
@@ -985,6 +1216,32 @@ var SedumPageScript = (() => {
985
1216
  if (!text) return { status: "empty" };
986
1217
  if (Array.from(text).length > 4096) return { status: "too_long" };
987
1218
  return { status: "ok", text };
1219
+ }, controlState = function(target) {
1220
+ const current = version();
1221
+ if (!snapshot || snapshot.operation !== "click" && snapshot.operation !== "fill" || !same(snapshot.version, current) || !same(target.version, current))
1222
+ return { status: "stale" };
1223
+ const element = refElement(target.ref);
1224
+ const candidate = snapshot.candidates.find(
1225
+ (item) => item.ref === target.ref
1226
+ );
1227
+ if (!element || !candidate || element.tagName.toLowerCase() !== target.tag || candidate.name !== target.name)
1228
+ return { status: "stale" };
1229
+ const control = toggleLabel(element) ?? element;
1230
+ const ariaChecked = control.getAttribute("aria-checked");
1231
+ const checked = isToggle(control) ? control.checked : ariaChecked === "true" || ariaChecked === "mixed" ? true : ariaChecked === "false" ? false : null;
1232
+ const active = (root) => {
1233
+ const focused2 = root.activeElement;
1234
+ return focused2?.shadowRoot ? active(focused2.shadowRoot) ?? focused2 : focused2;
1235
+ };
1236
+ const focused = active(document);
1237
+ const textField = element instanceof HTMLInputElement && FILLABLE_INPUT_TYPES.has(element.type) && element.type !== "password" || element instanceof HTMLTextAreaElement;
1238
+ return {
1239
+ status: "ok",
1240
+ disabled: disabled(control),
1241
+ checked,
1242
+ focused: !!focused && (focused === control || deepContains(control, focused)),
1243
+ value: textField ? element.value : element instanceof HTMLElement && element.isContentEditable ? element.textContent ?? "" : null
1244
+ };
988
1245
  }, aim = function(ref, expected) {
989
1246
  const current = version();
990
1247
  if (!snapshot || !same(snapshot.version, current))
@@ -996,9 +1253,10 @@ var SedumPageScript = (() => {
996
1253
  if (expected && element.tagName.toLowerCase() !== expected.tag)
997
1254
  return { actionable: false, reason: "stale" };
998
1255
  const candidate = snapshot?.candidates.find((item) => item.ref === ref);
999
- if (!candidate || candidateName(element) !== owned.get(element)?.rawName || JSON.stringify(peers(element, candidate.name).texts) !== JSON.stringify(candidate.peers) || expected && expected.name !== candidate.name)
1256
+ if (!candidate || candidateName(element, !!hoverHost(element)) !== owned.get(element)?.rawName || JSON.stringify(peers(element, candidate.name).texts) !== JSON.stringify(candidate.peers) || expected && expected.name !== candidate.name)
1000
1257
  return { actionable: false, reason: "stale" };
1001
- if (!(visible(element) || transparentToggle(element) || ariaHiddenOnly(element)) || disabled(element))
1258
+ const shownBy = visible(element) ? null : hoverHost(element);
1259
+ if (!(visible(element) || transparentToggle(element) || ariaHiddenOnly(element) || shownBy) || disabled(element))
1002
1260
  return { actionable: false, reason: "not_actionable" };
1003
1261
  const enclosingLink = element.closest("a[href]");
1004
1262
  if (enclosingLink) {
@@ -1008,9 +1266,10 @@ var SedumPageScript = (() => {
1008
1266
  return { actionable: false, reason: "not_actionable" };
1009
1267
  }
1010
1268
  const hitTest = () => {
1011
- const rect = element.getBoundingClientRect();
1269
+ const target = shownBy && !visible(element) ? shownBy : element;
1270
+ const rect = target.getBoundingClientRect();
1012
1271
  if (!rect.width || !rect.height) return null;
1013
- const points = expected ? [[expected.point.x / rect.width, expected.point.y / rect.height]] : [
1272
+ const points = expected && target === element && !expected.hover ? [[expected.point.x / rect.width, expected.point.y / rect.height]] : [
1014
1273
  [0.5, 0.5],
1015
1274
  [0.25, 0.5],
1016
1275
  [0.75, 0.5],
@@ -1022,7 +1281,7 @@ var SedumPageScript = (() => {
1022
1281
  const y = rect.top + rect.height * fy;
1023
1282
  if (x < 0 || y < 0 || x >= innerWidth || y >= innerHeight) continue;
1024
1283
  const hit = deepElementFromPoint(x, y);
1025
- if (hit && deepContains(element, hit)) {
1284
+ if (hit && deepContains(target, hit)) {
1026
1285
  return {
1027
1286
  actionable: true,
1028
1287
  aim: {
@@ -1032,7 +1291,8 @@ var SedumPageScript = (() => {
1032
1291
  revision: current.revision,
1033
1292
  tag: element.tagName.toLowerCase(),
1034
1293
  name: candidate.name,
1035
- point: { x: rect.width * fx, y: rect.height * fy },
1294
+ point: target === element ? { x: rect.width * fx, y: rect.height * fy } : { x: 0, y: 0 },
1295
+ ...shownBy ? { hover: true } : {},
1036
1296
  box: {
1037
1297
  x: Math.max(0, rect.left / innerWidth),
1038
1298
  y: Math.max(0, rect.top / innerHeight),
@@ -1056,8 +1316,15 @@ var SedumPageScript = (() => {
1056
1316
  if (!same(version(), current) || refElement(ref) !== element)
1057
1317
  return { actionable: false, reason: "stale" };
1058
1318
  return hitTest() ?? { actionable: false, reason: "not_actionable" };
1319
+ }, hoverElement = function(expected) {
1320
+ const current = version();
1321
+ if (!snapshot || !same(snapshot.version, current)) return null;
1322
+ const element = refElement(expected.ref);
1323
+ if (!element || element.tagName.toLowerCase() !== expected.tag || candidateName(element, true) !== owned.get(element)?.rawName)
1324
+ return null;
1325
+ return visible(element) ? null : hoverHost(element);
1059
1326
  };
1060
- observe2 = observe, composedParent2 = composedParent, allElements2 = allElements, flatTextNodes2 = flatTextNodes, deepElementFromPoint2 = deepElementFromPoint, deepContains2 = deepContains, version2 = version, same2 = same, clearRefs2 = clearRefs, visible2 = visible, modal2 = modal, excludedTextAncestor2 = excludedTextAncestor, publicText2 = publicText, referencedLabelText2 = referencedLabelText, label2 = label, nearbyText2 = nearbyText, mediaName2 = mediaName, hostLabel2 = hostLabel, iconName2 = iconName, describedText2 = describedText, rowLabel2 = rowLabel, candidateName2 = candidateName, hintWords2 = hintWords, addsWords2 = addsWords, siteRootLink2 = siteRootLink, nameHint2 = nameHint, countBadgeKind2 = countBadgeKind, clippedAway2 = clippedAway, ariaHiddenOnly2 = ariaHiddenOnly, isToggle2 = isToggle, transparentToggle2 = transparentToggle, toggleLabel2 = toggleLabel, pointerTarget2 = pointerTarget, landmarkOf2 = landmarkOf, landmarkRoot2 = landmarkRoot, locationOf2 = locationOf, shortText2 = shortText, containerTitle2 = containerTitle, sectionOf2 = sectionOf, boundedName2 = boundedName, role2 = role, interactive2 = interactive, readable2 = readable, editable2 = editable, disabled2 = disabled, path2 = path, inArticleBody2 = inArticleBody, itemContext2 = itemContext, peers2 = peers, scan2 = scan, collect2 = collect, selectOnly2 = selectOnly, selectedText2 = selectedText, digest2 = digest, refElement2 = refElement, fillElement2 = fillElement, readTarget2 = readTarget, aim2 = aim;
1327
+ observe2 = observe, composedParent2 = composedParent, allElements2 = allElements, flatTextNodes2 = flatTextNodes, deepElementFromPoint2 = deepElementFromPoint, deepContains2 = deepContains, version2 = version, same2 = same, clearRefs2 = clearRefs, visible2 = visible, modal2 = modal, excludedTextAncestor2 = excludedTextAncestor, publicText2 = publicText, insideNestedControl2 = insideNestedControl, referencedLabelText2 = referencedLabelText, label2 = label, nearbyText2 = nearbyText, mediaName2 = mediaName, hostLabel2 = hostLabel, iconName2 = iconName, describedText2 = describedText, rowLabel2 = rowLabel, hiddenControlText2 = hiddenControlText, candidateName2 = candidateName, hintWords2 = hintWords, addsWords2 = addsWords, siteRootLink2 = siteRootLink, nameHint2 = nameHint, countBadgeKind2 = countBadgeKind, clippedAway2 = clippedAway, ariaHiddenOnly2 = ariaHiddenOnly, isToggle2 = isToggle, transparentToggle2 = transparentToggle, toggleLabel2 = toggleLabel, pointerTarget2 = pointerTarget, selectorList2 = selectorList, specificity2 = specificity, stronger2 = stronger, hoverWins2 = hoverWins, readHoverRules2 = readHoverRules, hoverHost2 = hoverHost, hoverRevealed2 = hoverRevealed, landmarkOf2 = landmarkOf, landmarkRoot2 = landmarkRoot, locationOf2 = locationOf, shortText2 = shortText, containerTitle2 = containerTitle, sectionOf2 = sectionOf, boundedName2 = boundedName, role2 = role, interactive2 = interactive, readable2 = readable, editable2 = editable, disabled2 = disabled, path2 = path, inArticleBody2 = inArticleBody, itemContext2 = itemContext, peers2 = peers, scan2 = scan, collect2 = collect, selectOnly2 = selectOnly, selectedText2 = selectedText, digest2 = digest, pageText2 = pageText, refElement2 = refElement, fillElement2 = fillElement, readTarget2 = readTarget, controlState2 = controlState, aim2 = aim, hoverElement2 = hoverElement;
1061
1328
  const documentId = Array.from(crypto.getRandomValues(new Uint32Array(4))).map((part) => part.toString(16)).join("-");
1062
1329
  let revision = 0;
1063
1330
  let route = location.href;
@@ -1124,6 +1391,8 @@ var SedumPageScript = (() => {
1124
1391
  [/(?:^|-)play(?:$|-)/, "play"],
1125
1392
  [/(?:^|-)pause(?:$|-)/, "pause"]
1126
1393
  ];
1394
+ let hoverRules;
1395
+ let cascadeRules = [];
1127
1396
  const SECTIONING = "article,aside,main,nav,section";
1128
1397
  const SECTION_TITLE_LIMIT = 60;
1129
1398
  const titleCache = /* @__PURE__ */ new Map();
@@ -1162,6 +1431,7 @@ var SedumPageScript = (() => {
1162
1431
  },
1163
1432
  collect,
1164
1433
  digest,
1434
+ visibleText: () => pageText(Number.MAX_SAFE_INTEGER),
1165
1435
  pageVersion: version,
1166
1436
  findBySignals: ({ operation }) => {
1167
1437
  const first = collect({ operation });
@@ -1169,7 +1439,9 @@ var SedumPageScript = (() => {
1169
1439
  },
1170
1440
  clickTarget: (ref) => aim(ref),
1171
1441
  readTarget,
1442
+ controlState,
1172
1443
  checkAim: (expected) => aim(expected.ref, expected),
1444
+ hoverElement,
1173
1445
  fillElement,
1174
1446
  clearRefs,
1175
1447
  quiet: async ({ ms, timeoutMs }) => {
@@ -1209,6 +1481,7 @@ var SedumPageScript = (() => {
1209
1481
  var modal2;
1210
1482
  var excludedTextAncestor2;
1211
1483
  var publicText2;
1484
+ var insideNestedControl2;
1212
1485
  var referencedLabelText2;
1213
1486
  var label2;
1214
1487
  var nearbyText2;
@@ -1217,6 +1490,7 @@ var SedumPageScript = (() => {
1217
1490
  var iconName2;
1218
1491
  var describedText2;
1219
1492
  var rowLabel2;
1493
+ var hiddenControlText2;
1220
1494
  var candidateName2;
1221
1495
  var hintWords2;
1222
1496
  var addsWords2;
@@ -1229,6 +1503,13 @@ var SedumPageScript = (() => {
1229
1503
  var transparentToggle2;
1230
1504
  var toggleLabel2;
1231
1505
  var pointerTarget2;
1506
+ var selectorList2;
1507
+ var specificity2;
1508
+ var stronger2;
1509
+ var hoverWins2;
1510
+ var readHoverRules2;
1511
+ var hoverHost2;
1512
+ var hoverRevealed2;
1232
1513
  var landmarkOf2;
1233
1514
  var landmarkRoot2;
1234
1515
  var locationOf2;
@@ -1250,8 +1531,11 @@ var SedumPageScript = (() => {
1250
1531
  var selectOnly2;
1251
1532
  var selectedText2;
1252
1533
  var digest2;
1534
+ var pageText2;
1253
1535
  var refElement2;
1254
1536
  var fillElement2;
1255
1537
  var readTarget2;
1538
+ var controlState2;
1256
1539
  var aim2;
1540
+ var hoverElement2;
1257
1541
  })();
@@ -270,6 +270,11 @@
270
270
  "items": {
271
271
  "type": "object",
272
272
  "properties": {
273
+ "provider": {
274
+ "type": "string",
275
+ "minLength": 1,
276
+ "maxLength": 120
277
+ },
273
278
  "modality": {
274
279
  "type": "string",
275
280
  "const": "vision"
@@ -644,6 +649,44 @@
644
649
  "maxLength": 120
645
650
  }
646
651
  },
652
+ "goal": {
653
+ "type": "object",
654
+ "properties": {
655
+ "completion": {
656
+ "type": "string",
657
+ "const": "planner"
658
+ },
659
+ "text": {
660
+ "type": "string"
661
+ },
662
+ "actions": {
663
+ "type": "integer",
664
+ "minimum": 0,
665
+ "maximum": 9007199254740991
666
+ },
667
+ "requests": {
668
+ "type": "integer",
669
+ "minimum": 0,
670
+ "maximum": 9007199254740991
671
+ },
672
+ "reason": {
673
+ "type": "string"
674
+ },
675
+ "dataSeed": {
676
+ "type": "integer",
677
+ "minimum": -9007199254740991,
678
+ "maximum": 9007199254740991
679
+ }
680
+ },
681
+ "required": [
682
+ "completion",
683
+ "text",
684
+ "actions",
685
+ "requests",
686
+ "reason"
687
+ ],
688
+ "additionalProperties": false
689
+ },
647
690
  "sourceStack": {
648
691
  "minItems": 1,
649
692
  "type": "array",
@@ -1081,6 +1124,11 @@
1081
1124
  "items": {
1082
1125
  "type": "object",
1083
1126
  "properties": {
1127
+ "provider": {
1128
+ "type": "string",
1129
+ "minLength": 1,
1130
+ "maxLength": 120
1131
+ },
1084
1132
  "modality": {
1085
1133
  "type": "string",
1086
1134
  "const": "vision"
@@ -1444,6 +1492,11 @@
1444
1492
  "items": {
1445
1493
  "type": "object",
1446
1494
  "properties": {
1495
+ "provider": {
1496
+ "type": "string",
1497
+ "minLength": 1,
1498
+ "maxLength": 120
1499
+ },
1447
1500
  "modality": {
1448
1501
  "type": "string",
1449
1502
  "const": "vision"
@@ -145,9 +145,18 @@ interface Ai {
145
145
  (sentence: string, values?: AiValues): Promise<void>;
146
146
  /** Run several steps in order; they share one values object. */
147
147
  (sentences: readonly string[], values?: AiValues): Promise<void>;
148
+ /** Run a bounded goal until planner completion. Verify the outcome separately. */
149
+ goal(goal: string, values?: AiValues, options?: {
150
+ readonly generateData?: boolean;
151
+ }): Promise<void>;
148
152
  /** Name a block of steps; every step inside is reported under the name. */
149
153
  group<T>(name: string, body: () => Promise<T> | T): Promise<T>;
150
154
  group(name: string, sentences: readonly string[], values?: AiValues): Promise<void>;
155
+ /**
156
+ * Ask whether a claim holds on the page now, to branch on what the page
157
+ * shows. It is judged like a verify, never retried, and never fails the test.
158
+ */
159
+ holds(claim: string, values?: AiValues): Promise<boolean>;
151
160
  /** Read the text of the element a description refers to. */
152
161
  extract(description: string): Promise<string>;
153
162
  extract<T>(description: string, parser: Parser<T>): Promise<T>;
@@ -1,3 +1,3 @@
1
- export { j as Ai, k as AiValue, A as AiValues, o as Parser, p as SecretValue, T as TestBody, q as TestContext, r as TestInfo, s as TestOptions, C as secret, G as test } from './script-api-D3if59MQ.js';
1
+ export { j as Ai, k as AiValue, A as AiValues, o as Parser, p as SecretValue, T as TestBody, q as TestContext, r as TestInfo, s as TestOptions, C as secret, G as test } from './script-api-DzYBsXzT.js';
2
2
  export { expect } from 'playwright/test';
3
3
  export { BrowserContext, Locator, Page } from 'playwright-core';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sedum-dev/core",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.1.0-alpha.9",
4
4
  "repository": "https://github.com/sedum-dev/sedum",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,7 +25,9 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
+ "@faker-js/faker": "10.6.0",
28
29
  "jiti": "2.7.0",
30
+ "p-queue": "9.3.3",
29
31
  "playwright": "1.63.0",
30
32
  "playwright-core": "1.63.0",
31
33
  "sharp": "0.35.5",