vite-plugin-ai-annotator 1.14.7 → 1.14.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.
@@ -11,6 +11,7 @@ import { LitElement } from 'lit';
11
11
  export declare class AnnotatorToolbar extends LitElement {
12
12
  wsEndpoint: string;
13
13
  verbose: boolean;
14
+ demo: boolean;
14
15
  private connected;
15
16
  private sessionId;
16
17
  private selectionCount;
@@ -37,6 +38,7 @@ export declare class AnnotatorToolbar extends LitElement {
37
38
  private initializeConsoleCapture;
38
39
  private restoreConsoleMethods;
39
40
  private connectToServer;
41
+ private wrapRpcHandler;
40
42
  private registerRpcHandlers;
41
43
  private reportPageContext;
42
44
  private getPageContext;
@@ -6236,12 +6236,6 @@
6236
6236
  static isValidId(id) {
6237
6237
  return Boolean(id) && /^\S.*$/.test(id) && !/[[\](){}<>]/.test(id);
6238
6238
  }
6239
- /**
6240
- * Generate optimized CSS selector using optimal-select library
6241
- */
6242
- static generateOptimalSelector(element) {
6243
- return this.generateEnhancedCSSSelector(element);
6244
- }
6245
6239
  /**
6246
6240
  * Generate enhanced CSS selector optimized for browser environment
6247
6241
  */
@@ -6324,7 +6318,7 @@
6324
6318
  */
6325
6319
  static generateElementSelector(element) {
6326
6320
  const xpath = this.generateXPath(element);
6327
- const cssSelector = this.generateOptimalSelector(element);
6321
+ const cssSelector = this.generateEnhancedCSSSelector(element);
6328
6322
  const siblings = Array.from(element.parentElement?.children || []).filter((sibling) => sibling.tagName === element.tagName);
6329
6323
  const position = siblings.length > 1 ? {
6330
6324
  index: siblings.indexOf(element) + 1,
@@ -6365,13 +6359,6 @@
6365
6359
  if (element.getAttribute("aria-label")) {
6366
6360
  fallbacks.push(`[aria-label="${element.getAttribute("aria-label")}"]`);
6367
6361
  }
6368
- const textContent = element.textContent?.trim();
6369
- if (textContent && textContent.length > 0 && textContent.length < 50) {
6370
- const elementsWithSameText = Array.from(document.querySelectorAll("*")).filter((el) => el.textContent?.trim() === textContent);
6371
- if (elementsWithSameText.length === 1) {
6372
- fallbacks.push(`${element.tagName.toLowerCase()}:contains("${textContent}")`);
6373
- }
6374
- }
6375
6362
  let confidence = "low";
6376
6363
  if (this.validateXPath(primary.xpath, element) && this.validateCSSSelector(primary.cssSelector, element)) {
6377
6364
  confidence = "high";
@@ -6563,6 +6550,8 @@
6563
6550
  cleanup?.();
6564
6551
  badge.remove();
6565
6552
  overlay.remove();
6553
+ selectedElements.delete(element);
6554
+ selectionGroups.delete(element);
6566
6555
  return;
6567
6556
  }
6568
6557
  const rect = element.getBoundingClientRect();
@@ -6830,6 +6819,7 @@
6830
6819
  const rect = element.getBoundingClientRect();
6831
6820
  overlay.style.cssText = `
6832
6821
  position: fixed;
6822
+ margin: 0 !important;
6833
6823
  left: ${rect.left}px;
6834
6824
  top: ${rect.top}px;
6835
6825
  width: ${rect.width}px;
@@ -7053,6 +7043,7 @@
7053
7043
  }
7054
7044
  return componentInfo;
7055
7045
  }
7046
+ if (!element.parentElement) return null;
7056
7047
  return findNearestComponent(element.parentElement, verbose);
7057
7048
  } catch (e5) {
7058
7049
  logger.error("Error finding nearest component:", e5);
@@ -7292,7 +7283,7 @@
7292
7283
  const locationInfo = {};
7293
7284
  if (vnode?.loc) {
7294
7285
  locationInfo.elementLocation = {
7295
- file: vnode.loc.source || "",
7286
+ file: "",
7296
7287
  line: vnode.loc.start?.line || 0,
7297
7288
  column: vnode.loc.start?.column || 0,
7298
7289
  endLine: vnode.loc.end?.line,
@@ -7536,6 +7527,7 @@
7536
7527
  super(...arguments);
7537
7528
  this.wsEndpoint = "http://localhost:7318";
7538
7529
  this.verbose = false;
7530
+ this.demo = false;
7539
7531
  this.connected = false;
7540
7532
  this.sessionId = "";
7541
7533
  this.selectionCount = 0;
@@ -7579,8 +7571,12 @@
7579
7571
  connectedCallback() {
7580
7572
  super.connectedCallback();
7581
7573
  this.initializeManagers();
7582
- this.initializeConsoleCapture();
7583
- this.connectToServer();
7574
+ if (this.demo) {
7575
+ this.connected = true;
7576
+ } else {
7577
+ this.initializeConsoleCapture();
7578
+ this.connectToServer();
7579
+ }
7584
7580
  }
7585
7581
  disconnectedCallback() {
7586
7582
  super.disconnectedCallback();
@@ -7671,73 +7667,27 @@
7671
7667
  this.log("Connection error:", error.message);
7672
7668
  });
7673
7669
  }
7674
- registerRpcHandlers() {
7675
- if (!this.rpc) return;
7676
- this.rpc.handle.getPageContext(async () => {
7677
- try {
7678
- return await this.getPageContext();
7679
- } catch (error) {
7680
- this.log("[getPageContext] Handler error:", error);
7681
- throw { message: error instanceof Error ? error.message : String(error), code: "INTERNAL_ERROR", data: void 0 };
7682
- }
7683
- });
7684
- this.rpc.handle.getSelectedElements(async () => {
7685
- try {
7686
- return await this.getSelectedElements();
7687
- } catch (error) {
7688
- this.log("[getSelectedElements] Handler error:", error);
7689
- throw { message: error instanceof Error ? error.message : String(error), code: "INTERNAL_ERROR", data: void 0 };
7690
- }
7691
- });
7692
- this.rpc.handle.triggerSelection(async (mode, selector, selectorType) => {
7693
- try {
7694
- return await this.triggerSelection(mode, selector, selectorType);
7695
- } catch (error) {
7696
- this.log("[triggerSelection] Handler error:", error);
7697
- throw { message: error instanceof Error ? error.message : String(error), code: "INTERNAL_ERROR", data: void 0 };
7698
- }
7699
- });
7700
- this.rpc.handle.captureScreenshot(async (type, selector, quality) => {
7670
+ wrapRpcHandler(name, handler) {
7671
+ return (async (...args) => {
7701
7672
  try {
7702
- return await this.captureScreenshot(type, selector, quality);
7673
+ return await handler(...args);
7703
7674
  } catch (error) {
7704
- this.log("[captureScreenshot] Handler error:", error);
7705
- throw { message: error instanceof Error ? error.message : String(error), code: "INTERNAL_ERROR", data: void 0 };
7706
- }
7707
- });
7708
- this.rpc.handle.clearSelection(async () => {
7709
- try {
7710
- return await this.clearSelection();
7711
- } catch (error) {
7712
- this.log("[clearSelection] Handler error:", error);
7675
+ this.log(`[${name}] Handler error:`, error);
7713
7676
  throw { message: error instanceof Error ? error.message : String(error), code: "INTERNAL_ERROR", data: void 0 };
7714
7677
  }
7715
7678
  });
7679
+ }
7680
+ registerRpcHandlers() {
7681
+ if (!this.rpc) return;
7682
+ this.rpc.handle.getPageContext(this.wrapRpcHandler("getPageContext", async () => this.getPageContext()));
7683
+ this.rpc.handle.getSelectedElements(this.wrapRpcHandler("getSelectedElements", async () => this.getSelectedElements()));
7684
+ this.rpc.handle.triggerSelection(this.wrapRpcHandler("triggerSelection", async (mode, selector, selectorType) => this.triggerSelection(mode, selector, selectorType)));
7685
+ this.rpc.handle.captureScreenshot(this.wrapRpcHandler("captureScreenshot", async (type, selector, quality) => this.captureScreenshot(type, selector, quality)));
7686
+ this.rpc.handle.clearSelection(this.wrapRpcHandler("clearSelection", async () => this.clearSelection()));
7716
7687
  this.rpc.handle.ping(async () => "pong");
7717
- this.rpc.handle.injectCSS(async (css) => {
7718
- try {
7719
- return await this.injectCSS(css);
7720
- } catch (error) {
7721
- this.log("[injectCSS] Handler error:", error);
7722
- throw { message: error instanceof Error ? error.message : String(error), code: "INTERNAL_ERROR", data: void 0 };
7723
- }
7724
- });
7725
- this.rpc.handle.injectJS(async (code) => {
7726
- try {
7727
- return await this.injectJS(code);
7728
- } catch (error) {
7729
- this.log("[injectJS] Handler error:", error);
7730
- throw { message: error instanceof Error ? error.message : String(error), code: "INTERNAL_ERROR", data: void 0 };
7731
- }
7732
- });
7733
- this.rpc.handle.getConsole(async (clear) => {
7734
- try {
7735
- return await this.getConsoleLogs(clear);
7736
- } catch (error) {
7737
- this.log("[getConsole] Handler error:", error);
7738
- throw { message: error instanceof Error ? error.message : String(error), code: "INTERNAL_ERROR", data: void 0 };
7739
- }
7740
- });
7688
+ this.rpc.handle.injectCSS(this.wrapRpcHandler("injectCSS", async (css) => this.injectCSS(css)));
7689
+ this.rpc.handle.injectJS(this.wrapRpcHandler("injectJS", async (code) => this.injectJS(code)));
7690
+ this.rpc.handle.getConsole(this.wrapRpcHandler("getConsole", async (clear) => this.getConsoleLogs(clear)));
7741
7691
  }
7742
7692
  reportPageContext() {
7743
7693
  if (!this.socket?.connected) return;
@@ -8029,9 +7979,6 @@
8029
7979
  this.popoverCleanup();
8030
7980
  this.popoverCleanup = null;
8031
7981
  }
8032
- const popoverEl = this.shadowRoot?.querySelector(".popover");
8033
- if (popoverEl) {
8034
- }
8035
7982
  this.commentPopover = { visible: false, element: null, comment: "" };
8036
7983
  }
8037
7984
  handlePopoverInput(e5) {
@@ -8211,6 +8158,10 @@
8211
8158
  }
8212
8159
  async copySessionId() {
8213
8160
  this.exitInspectingMode();
8161
+ if (this.demo) {
8162
+ this.showToast("Demo mode \u2014 no server");
8163
+ return;
8164
+ }
8214
8165
  if (!this.sessionId) {
8215
8166
  this.showToast("No session ID");
8216
8167
  return;
@@ -8599,6 +8550,9 @@
8599
8550
  __decorateClass([
8600
8551
  n4({ attribute: "verbose", type: Boolean })
8601
8552
  ], AnnotatorToolbar.prototype, "verbose", 2);
8553
+ __decorateClass([
8554
+ n4({ attribute: "demo", type: Boolean })
8555
+ ], AnnotatorToolbar.prototype, "demo", 2);
8602
8556
  __decorateClass([
8603
8557
  r5()
8604
8558
  ], AnnotatorToolbar.prototype, "connected", 2);