lazyscout 0.3.7 → 0.3.8

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/index.js CHANGED
@@ -438,6 +438,13 @@ function collectPageData() {
438
438
  }
439
439
  const disabled = el.disabled === true || el.getAttribute("aria-disabled") === "true";
440
440
  const required = el.required === true || el.getAttribute("aria-required") === "true";
441
+ const context = el.closest('form, fieldset, tr, [role="row"], li, section, article, aside, main, nav, dialog, [role="dialog"], [role="region"], .card, [class*="card" i]');
442
+ const contextAriaLabel = context?.getAttribute("aria-label");
443
+ const contextHeading = context?.querySelector("h1, h2, h3");
444
+ const rowLabel = context?.matches('tr, [role="row"]') ? context.querySelector('th, td, [role="cell"], [role="gridcell"]') : void 0;
445
+ const namedContainer = context?.querySelector("[data-title], [data-name], [data-label]");
446
+ const contextText = cleanText(contextAriaLabel || contextHeading?.textContent || namedContainer?.getAttribute("data-title") || namedContainer?.getAttribute("data-name") || namedContainer?.getAttribute("data-label") || rowLabel?.textContent);
447
+ const contextTestId = context?.getAttribute("data-testid")?.trim() || void 0;
441
448
  return {
442
449
  kind,
443
450
  role,
@@ -447,14 +454,52 @@ function collectPageData() {
447
454
  inputType,
448
455
  placeholder: attr(el, "placeholder"),
449
456
  name: attr(el, "name"),
457
+ testId: attr(el, "data-testid"),
450
458
  id: el.id || void 0,
451
459
  href: el instanceof HTMLAnchorElement ? el.href : void 0,
452
460
  options,
453
461
  required,
454
462
  disabled,
455
- cssSelector: cssSelector(el)
463
+ cssSelector: cssSelector(el),
464
+ contextText: contextText || void 0,
465
+ contextSelector: context ? cssSelector(context) : void 0,
466
+ contextTestId
456
467
  };
457
468
  }
469
+ function annotateMatches(elements) {
470
+ const groups = /* @__PURE__ */ new Map();
471
+ for (const element of elements) {
472
+ if (!element.accessibleName)
473
+ continue;
474
+ const key = `${element.role}|${element.accessibleName}`;
475
+ const group = groups.get(key) ?? [];
476
+ group.push(element);
477
+ groups.set(key, group);
478
+ }
479
+ for (const group of groups.values()) {
480
+ if (group.length < 2)
481
+ continue;
482
+ group.forEach((element, index) => {
483
+ element.matchIndex = index;
484
+ element.matchCount = group.length;
485
+ });
486
+ const scopedGroups = /* @__PURE__ */ new Map();
487
+ for (const element of group) {
488
+ if (!element.contextSelector)
489
+ continue;
490
+ const scopedKey = element.contextSelector;
491
+ const scoped = scopedGroups.get(scopedKey) ?? [];
492
+ scoped.push(element);
493
+ scopedGroups.set(scopedKey, scoped);
494
+ }
495
+ for (const scoped of scopedGroups.values()) {
496
+ scoped.forEach((element, index) => {
497
+ element.scopeIndex = index;
498
+ element.scopeMatchCount = scoped.length;
499
+ });
500
+ }
501
+ }
502
+ }
458
503
  function isCollectable(el) {
459
504
  if (el.closest('[aria-hidden="true"]'))
460
505
  return false;
@@ -491,7 +536,7 @@ function collectPageData() {
491
536
  submitButtons
492
537
  };
493
538
  });
494
- return {
539
+ const result = {
495
540
  title: document.title,
496
541
  headings: Array.from(document.querySelectorAll("h1, h2, h3")).map((el) => cleanText(el.textContent)).filter(Boolean).slice(0, 30),
497
542
  links: collect("a[href]", "link", "link"),
@@ -523,6 +568,9 @@ function collectPageData() {
523
568
  stateContent: Array.from(document.querySelectorAll('[aria-live], [data-state], [data-testid*="state" i]')).filter(isCollectable).map((element) => cleanText(element.textContent)).filter(Boolean).slice(0, 30),
524
569
  validationMessages: Array.from(document.querySelectorAll('[role="alert"], [aria-invalid="true"], .error, .errors, .invalid-feedback')).filter(isCollectable).map((element) => cleanText(element.textContent)).filter(Boolean).slice(0, 20)
525
570
  };
571
+ annotateMatches([...result.links, ...result.buttons, ...result.inputs, ...result.textareas, ...result.selects]);
572
+ annotateMatches(result.forms.flatMap((form) => [...form.fields, ...form.submitButtons]));
573
+ return result;
526
574
  }
527
575
 
528
576
  // ../../packages/explorer/dist/mapToPageModel.js
@@ -1817,13 +1865,23 @@ function assignModules(pages) {
1817
1865
 
1818
1866
  // ../../packages/generators/dist/testcases/targets.js
1819
1867
  function toTargetRef(element) {
1868
+ const needsDisambiguation = element.matchCount !== void 0 && element.matchCount > 1;
1869
+ const disambiguation = needsDisambiguation ? {
1870
+ nth: element.scopeMatchCount && element.scopeMatchCount > 1 ? element.scopeIndex : element.contextSelector || element.contextText ? void 0 : element.matchIndex,
1871
+ matchCount: element.matchCount,
1872
+ contextText: element.contextText,
1873
+ contextSelector: element.contextSelector,
1874
+ contextTestId: element.contextTestId
1875
+ } : void 0;
1820
1876
  if (element.accessibleName) {
1821
- return { role: element.role, name: element.accessibleName };
1877
+ return { role: element.role, name: element.accessibleName, ...disambiguation };
1822
1878
  }
1823
1879
  if (element.placeholder) {
1824
- return { role: element.role, placeholder: element.placeholder };
1880
+ return { role: element.role, placeholder: element.placeholder, ...disambiguation };
1825
1881
  }
1826
- return { role: element.role, cssSelector: element.cssSelector };
1882
+ if (element.testId)
1883
+ return { testId: element.testId, ...disambiguation };
1884
+ return { role: element.role, cssSelector: element.cssSelector, ...disambiguation };
1827
1885
  }
1828
1886
  function labelOf(element) {
1829
1887
  return element.accessibleName || element.placeholder || element.name || element.id || element.tagName;
@@ -2612,6 +2670,38 @@ async function openWorkspace(root) {
2612
2670
  async function browserProfileDirectory(root, projectId) {
2613
2671
  return join(await ensureProject(root, projectId), "browser-profile");
2614
2672
  }
2673
+ async function browserProfileStatus(root, projectId) {
2674
+ const directory = join(projectDirectory(root, projectId), "browser-profile");
2675
+ try {
2676
+ const entries = await readdir(directory);
2677
+ const candidates = [
2678
+ directory,
2679
+ join(directory, "Local State"),
2680
+ join(directory, "Default"),
2681
+ join(directory, "Default", "Cookies"),
2682
+ join(directory, "Default", "Local Storage")
2683
+ ];
2684
+ const modifiedTimes = await Promise.all(candidates.map(async (candidate) => {
2685
+ try {
2686
+ return (await stat(candidate)).mtimeMs;
2687
+ } catch {
2688
+ return 0;
2689
+ }
2690
+ }));
2691
+ return {
2692
+ profileExists: true,
2693
+ browserDataDetected: entries.includes("Default") || entries.includes("Local State"),
2694
+ cookieStoreDetected: modifiedTimes[3] > 0 || modifiedTimes[4] > 0,
2695
+ lastModifiedAt: new Date(Math.max(...modifiedTimes)).toISOString()
2696
+ };
2697
+ } catch {
2698
+ return { profileExists: false, browserDataDetected: false, cookieStoreDetected: false };
2699
+ }
2700
+ }
2701
+ async function clearBrowserProfile(root, projectId) {
2702
+ const directory = join(projectDirectory(root, projectId), "browser-profile");
2703
+ await rm(directory, { recursive: true, force: true });
2704
+ }
2615
2705
  async function readProject(root, projectId) {
2616
2706
  try {
2617
2707
  const directory = projectDirectory(root, projectId);
@@ -3789,6 +3879,11 @@ function registerWorkspaceRoutes(app, root) {
3789
3879
  await page.goto(body.url, { waitUntil: "domcontentloaded" });
3790
3880
  return reply.send({ opened: true });
3791
3881
  });
3882
+ app.get("/api/workspace/projects/:projectId/auth-session/status", async (request) => browserProfileStatus(root, request.params.projectId));
3883
+ app.delete("/api/workspace/projects/:projectId/auth-session", async (request, reply) => {
3884
+ await clearBrowserProfile(root, request.params.projectId);
3885
+ return reply.send({ cleared: true });
3886
+ });
3792
3887
  app.get("/api/workspace/projects/:projectId/screenshots", async (request) => readScreenshots(root, request.params.projectId));
3793
3888
  app.post("/api/workspace/projects/:projectId/screenshots", async (request) => saveScreenshot(root, request.params.projectId, request.body));
3794
3889
  app.get("/api/workspace/projects/:projectId/screenshots/:name", async (request, reply) => {
@@ -3992,7 +4087,7 @@ async function openInBrowser(url) {
3992
4087
  }
3993
4088
 
3994
4089
  // src/version.ts
3995
- var VERSION = true ? "0.3.7" : "0.0.0-dev";
4090
+ var VERSION = true ? "0.3.8" : "0.0.0-dev";
3996
4091
 
3997
4092
  // src/commands/serve.ts
3998
4093
  var DEFAULT_PORT = 4321;