vite-plugin-ai-annotator 1.0.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.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # vite-plugin-ai-annotator
2
+
3
+ AI-powered element annotator for Vite - Pick elements and get instant AI code modifications.
4
+
5
+ [![Watch the Tutorial](https://img.youtube.com/vi/OuKnfCbmfTg/maxresdefault.jpg)](https://youtu.be/OuKnfCbmfTg)
6
+ > 📺 **[Watch the Tutorial Video](https://youtu.be/OuKnfCbmfTg)** - See the plugin in action!
7
+
8
+ ## What can this plugin help you?
9
+
10
+ After installing the plugin, you can:
11
+ - **Point directly at any element** on your webapp
12
+ - **Type a short request** like "make it bigger", "center it", "change color to blue"
13
+ - **Wait for AI to modify your code** - it automatically finds and updates the source files
14
+ - **See instant results** - your changes appear immediately in the browser
15
+
16
+ > Save cognitive load, because it's precious.
17
+
18
+ ## Prerequisites
19
+
20
+ This plugin requires **Claude Code** to provide AI assistance:
21
+
22
+ ```bash
23
+ # Install Claude Code globally
24
+ bun install -g @anthropic-ai/claude-code
25
+
26
+ # Verify installation
27
+ claude --version
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ This is an **ESM-only Vite plugin**. Installation is simple!
33
+
34
+ ### 1. Install
35
+
36
+ ```bash
37
+ bun add -d vite-plugin-ai-annotator
38
+ ```
39
+
40
+ ### 2. Add to Your Vite Config
41
+
42
+ ```typescript
43
+ import { defineConfig } from 'vite';
44
+ import annotator from 'vite-plugin-ai-annotator';
45
+
46
+ export default defineConfig({
47
+ plugins: [
48
+ annotator(),
49
+ ],
50
+ });
51
+ ```
52
+
53
+ ### 3. Start Your Dev Server
54
+
55
+ ```bash
56
+ bun dev
57
+ ```
58
+
59
+ That's it! The annotator toolbar will automatically appear in your application.
60
+
61
+ ## Plugin Options
62
+
63
+ ```typescript
64
+ annotator({
65
+ port: 7318, // Server port (default: 7318)
66
+ verbose: false, // Enable detailed logging (default: false)
67
+ })
68
+ ```
69
+
70
+ ## Framework Support
71
+
72
+ Works with all Vite-supported frameworks:
73
+
74
+ - ⚛️ **React** - Detects components, props, and state
75
+ - 🟢 **Vue** - Understands composition/options API
76
+ - 🅰️ **Angular** - Recognizes components and directives
77
+ - 🟠 **Svelte** - Identifies components and stores
78
+ - 📄 **Vanilla JS** - Works with plain HTML/CSS/JS
79
+
80
+ ## Team Collaboration
81
+
82
+ Want your entire team to modify the app? Configure for network access:
83
+
84
+ ```typescript
85
+ annotator({
86
+ port: 7318,
87
+ listenAddress: '0.0.0.0', // Accept connections from network
88
+ publicAddress: 'https://myapp.com:7318', // Public URL for the toolbar
89
+ })
90
+ ```
91
+
92
+ Now anyone on your team can:
93
+ 1. Open the app at `https://myapp.com`
94
+ 2. Use the annotator toolbar to modify the UI
95
+ 3. Changes are saved directly to the source files
96
+ 4. Everyone sees updates in real-time!
97
+
98
+ **Happy coding! 🚀**
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Framework component detection and file location extraction
3
+ */
4
+ import { ElementSelector } from '../utils/xpath';
5
+ export interface ComponentInfo {
6
+ componentLocation: string;
7
+ componentName?: string;
8
+ elementLocation?: {
9
+ file: string;
10
+ line: number;
11
+ column: number;
12
+ endLine?: number;
13
+ endColumn?: number;
14
+ source?: string;
15
+ };
16
+ framework?: 'vue' | 'react' | 'angular' | 'svelte' | 'vanilla';
17
+ sourceMap?: {
18
+ originalLine: number;
19
+ originalColumn: number;
20
+ originalSource: string;
21
+ originalName?: string;
22
+ };
23
+ sourceHierarchy?: string;
24
+ selectors?: {
25
+ primary: ElementSelector;
26
+ fallbacks: string[];
27
+ confidence: 'high' | 'medium' | 'low';
28
+ };
29
+ }
30
+ /**
31
+ * Find the nearest component in the DOM tree
32
+ */
33
+ export declare function findNearestComponent(element: Element, verbose?: boolean): ComponentInfo | null;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Inspection Manager for mouse inspection mode handling
3
+ */
4
+ export interface InspectionManager {
5
+ enterInspectionMode(): void;
6
+ exitInspectionMode(): void;
7
+ isInInspectionMode(): boolean;
8
+ destroy(): void;
9
+ }
10
+ export declare function createInspectionManager(onElementSelect?: (element: Element) => void, shouldIgnoreElement?: (element: Element) => boolean, isElementSelected?: (element: Element) => boolean): InspectionManager;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Element Selection Manager for element selection, highlighting, and badge management
3
+ */
4
+ import type { ElementData } from '../rpc/define';
5
+ export interface SelectedElementInfo {
6
+ color: string;
7
+ originalOutline: string;
8
+ originalOutlineOffset: string;
9
+ index: number;
10
+ }
11
+ export interface ElementSelectionManager {
12
+ selectElement(element: Element, componentFinder?: (el: Element) => any): void;
13
+ deselectElement(element: Element): void;
14
+ clearAllSelections(): void;
15
+ hasElement(element: Element): boolean;
16
+ getSelectedElements(): Map<Element, SelectedElementInfo>;
17
+ getSelectedCount(): number;
18
+ findSelectedParent(element: Element): Element | null;
19
+ findSelectedChildren(element: Element): Element[];
20
+ buildHierarchicalStructure(componentFinder?: (el: Element) => any, imagePaths?: Map<Element, string>): ElementData[];
21
+ setOnEditClick(callback: (element: Element) => void): void;
22
+ updateBadgeCommentIndicator(element: Element, hasComment: boolean): void;
23
+ }
24
+ export declare function createElementSelectionManager(): ElementSelectionManager;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * InstantCode Annotator Toolbar
3
+ *
4
+ * Browser component that:
5
+ * 1. Connects to InstantCode server via Socket.IO
6
+ * 2. Handles RPC requests from server (element selection, screenshots, etc.)
7
+ * 3. Shows toolbar UI with inspect/clear buttons
8
+ * 4. Shows commentPopover for adding comments when elements are selected
9
+ */
10
+ import { LitElement } from 'lit';
11
+ export declare class AnnotatorToolbar extends LitElement {
12
+ wsEndpoint: string;
13
+ verbose: boolean;
14
+ private connected;
15
+ private sessionId;
16
+ private selectionCount;
17
+ private isInspecting;
18
+ private commentPopover;
19
+ private popoverCleanup;
20
+ private socket;
21
+ private rpc;
22
+ private selectionManager;
23
+ private inspectionManager;
24
+ private elementComments;
25
+ private consoleBuffer;
26
+ private originalConsoleMethods;
27
+ static styles: import("lit").CSSResult;
28
+ connectedCallback(): void;
29
+ disconnectedCallback(): void;
30
+ private initializeManagers;
31
+ private initializeConsoleCapture;
32
+ private restoreConsoleMethods;
33
+ private connectToServer;
34
+ private registerRpcHandlers;
35
+ private reportPageContext;
36
+ private getPageContext;
37
+ private getSelectedElements;
38
+ private triggerSelection;
39
+ private captureScreenshot;
40
+ private clearSelection;
41
+ private injectCSS;
42
+ private injectJS;
43
+ private getConsoleLogs;
44
+ private handleElementSelected;
45
+ private removeSelectedElement;
46
+ private showCommentPopoverForElement;
47
+ private handlePopoverKeydown;
48
+ private hideCommentPopover;
49
+ private handlePopoverInput;
50
+ private shouldIgnoreElement;
51
+ private cleanup;
52
+ private log;
53
+ private toggleInspect;
54
+ private handleClearClick;
55
+ private renderCursorIcon;
56
+ private renderTrashIcon;
57
+ private renderCloseIcon;
58
+ private renderHelpIcon;
59
+ private renderErrorIcon;
60
+ private openHelpPage;
61
+ render(): import("lit-html").TemplateResult<1>;
62
+ }
63
+ declare global {
64
+ interface HTMLElementTagNameMap {
65
+ 'annotator-toolbar': AnnotatorToolbar;
66
+ }
67
+ }