@np-dev/ui-ai-anotation 0.1.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.
Files changed (52) hide show
  1. package/README.md +245 -0
  2. package/dist/cjs/index.cjs +1550 -0
  3. package/dist/cjs/index.cjs.map +7 -0
  4. package/dist/cjs/index.native.cjs +1004 -0
  5. package/dist/cjs/index.native.cjs.map +7 -0
  6. package/dist/cjs/index.web.cjs +83 -0
  7. package/dist/cjs/index.web.cjs.map +7 -0
  8. package/dist/esm/index.js +1524 -0
  9. package/dist/esm/index.js.map +7 -0
  10. package/dist/esm/index.native.js +1012 -0
  11. package/dist/esm/index.native.js.map +7 -0
  12. package/dist/esm/index.web.js +62 -0
  13. package/dist/esm/index.web.js.map +7 -0
  14. package/dist/types/components/AnnotationInput.d.ts +8 -0
  15. package/dist/types/components/AnnotationList.d.ts +1 -0
  16. package/dist/types/components/Draggable.d.ts +10 -0
  17. package/dist/types/components/Highlighter.d.ts +1 -0
  18. package/dist/types/components/Toolbar.d.ts +1 -0
  19. package/dist/types/index.d.ts +20 -0
  20. package/dist/types/index.web.d.ts +69 -0
  21. package/dist/types/store.d.ts +66 -0
  22. package/dist/types/utils/fiber.d.ts +51 -0
  23. package/dist/types/utils/platform.d.ts +8 -0
  24. package/dist/types/utils/screenshot.d.ts +28 -0
  25. package/package.json +115 -0
  26. package/src/components/AnnotationInput.tsx +269 -0
  27. package/src/components/AnnotationList.tsx +248 -0
  28. package/src/components/Draggable.tsx +73 -0
  29. package/src/components/Highlighter.tsx +497 -0
  30. package/src/components/Toolbar.tsx +213 -0
  31. package/src/components/native/AnnotationInput.tsx +227 -0
  32. package/src/components/native/AnnotationList.tsx +157 -0
  33. package/src/components/native/Draggable.tsx +65 -0
  34. package/src/components/native/Highlighter.tsx +239 -0
  35. package/src/components/native/Toolbar.tsx +192 -0
  36. package/src/components/native/index.ts +6 -0
  37. package/src/components/web/AnnotationInput.tsx +150 -0
  38. package/src/components/web/AnnotationList.tsx +117 -0
  39. package/src/components/web/Draggable.tsx +74 -0
  40. package/src/components/web/Highlighter.tsx +329 -0
  41. package/src/components/web/Toolbar.tsx +198 -0
  42. package/src/components/web/index.ts +6 -0
  43. package/src/extension.tsx +15 -0
  44. package/src/index.native.tsx +50 -0
  45. package/src/index.tsx +41 -0
  46. package/src/index.web.tsx +124 -0
  47. package/src/store.tsx +120 -0
  48. package/src/utils/fiber.native.ts +90 -0
  49. package/src/utils/fiber.ts +255 -0
  50. package/src/utils/platform.ts +33 -0
  51. package/src/utils/screenshot.native.ts +139 -0
  52. package/src/utils/screenshot.ts +162 -0
package/README.md ADDED
@@ -0,0 +1,245 @@
1
+ # react-ai-anotation
2
+
3
+ AI-powered annotation toolkit for React and React Native apps. Enables component inspection, annotation, and screenshot capture for AI-assisted development workflows.
4
+
5
+ ## Features
6
+
7
+ - 🔍 **Component Inspector** - Hover/tap to identify React components
8
+ - 📝 **Annotations** - Add notes to components for AI context
9
+ - 📷 **Screenshots** - Capture component screenshots (web + native)
10
+ - 🖱️ **Draggable Toolbar** - Non-intrusive floating UI
11
+ - 🌐 **Cross-platform** - Works on Web, iOS, and Android
12
+ - 🧩 **Chrome Extension** - Annotate any website!
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ # Using npm
18
+ npm install react-ai-anotation
19
+
20
+ # Using yarn
21
+ yarn add react-ai-anotation
22
+
23
+ # Using bun
24
+ bun add react-ai-anotation
25
+ ```
26
+
27
+ ### Additional dependencies
28
+
29
+ **For Web:**
30
+ ```bash
31
+ npm install framer-motion html2canvas lucide-react
32
+ ```
33
+
34
+ **For React Native:**
35
+ ```bash
36
+ npm install react-native-view-shot
37
+
38
+ # Optional for clipboard support
39
+ npm install expo-clipboard
40
+
41
+ # Optional for saving to camera roll
42
+ npm install expo-media-library
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ ### Web (React)
48
+
49
+ ```tsx
50
+ import { AiAnnotationProvider } from 'react-ai-anotation';
51
+
52
+ function App() {
53
+ return (
54
+ <AiAnnotationProvider>
55
+ <YourApp />
56
+ </AiAnnotationProvider>
57
+ );
58
+ }
59
+ ```
60
+
61
+ ### React Native
62
+
63
+ ```tsx
64
+ import { AiAnnotationProvider } from 'react-ai-anotation/native';
65
+ // or
66
+ import { AiAnnotationProvider } from 'react-ai-anotation';
67
+
68
+ function App() {
69
+ return (
70
+ <AiAnnotationProvider>
71
+ <YourApp />
72
+ </AiAnnotationProvider>
73
+ );
74
+ }
75
+ ```
76
+
77
+ ## API
78
+
79
+ ### Components
80
+
81
+ #### `AiAnnotationProvider`
82
+
83
+ Wraps your app to provide annotation functionality.
84
+
85
+ ```tsx
86
+ <AiAnnotationProvider>
87
+ {children}
88
+ </AiAnnotationProvider>
89
+ ```
90
+
91
+ #### `Toolbar`
92
+
93
+ The floating toolbar with annotation controls. Automatically rendered by the provider.
94
+
95
+ #### `Highlighter`
96
+
97
+ Component inspector overlay. Highlights components on hover (web) or tap (native).
98
+
99
+ **Native-specific props:**
100
+ ```tsx
101
+ interface HighlighterProps {
102
+ onInspect?: (event: GestureResponderEvent) => {
103
+ name: string;
104
+ rect: { x: number; y: number; width: number; height: number };
105
+ } | null;
106
+ }
107
+ ```
108
+
109
+ ### Hooks
110
+
111
+ #### `useAiAnnotation()`
112
+
113
+ Access annotation state and dispatch actions.
114
+
115
+ ```tsx
116
+ const { state, dispatch } = useAiAnnotation();
117
+
118
+ // State shape
119
+ interface State {
120
+ mode: 'disabled' | 'inspecting';
121
+ annotations: Annotation[];
122
+ hoveredElement: any;
123
+ hoveredComponentInfo: { name: string } | null;
124
+ isMinimized: boolean;
125
+ showList: boolean;
126
+ }
127
+
128
+ // Actions
129
+ dispatch({ type: 'SET_MODE', payload: 'inspecting' });
130
+ dispatch({ type: 'ADD_ANNOTATION', payload: { id, componentName, note, timestamp } });
131
+ dispatch({ type: 'REMOVE_ANNOTATION', payload: annotationId });
132
+ dispatch({ type: 'CLEAR_ALL_ANNOTATIONS' });
133
+ dispatch({ type: 'TOGGLE_MINIMIZED' });
134
+ dispatch({ type: 'TOGGLE_LIST' });
135
+ ```
136
+
137
+ ### Utilities
138
+
139
+ #### `captureScreenshot(element, options)`
140
+
141
+ Capture a screenshot of an element/view.
142
+
143
+ **Web:**
144
+ ```tsx
145
+ import { captureScreenshot } from 'react-ai-anotation';
146
+
147
+ const result = await captureScreenshot(htmlElement, {
148
+ scale: 2,
149
+ copyToClipboard: true,
150
+ download: false,
151
+ });
152
+ ```
153
+
154
+ **Native:**
155
+ ```tsx
156
+ import { captureScreenshot } from 'react-ai-anotation/native';
157
+
158
+ const viewRef = useRef<View>(null);
159
+
160
+ const result = await captureScreenshot(viewRef, {
161
+ scale: 2,
162
+ format: 'png',
163
+ copyToClipboard: true,
164
+ saveToCameraRoll: false,
165
+ });
166
+ ```
167
+
168
+ #### Platform Detection
169
+
170
+ ```tsx
171
+ import { isWeb, isNative, getPlatform, isTauriEnv } from 'react-ai-anotation';
172
+
173
+ if (isWeb) {
174
+ // Web-specific code
175
+ }
176
+
177
+ if (isNative) {
178
+ // React Native-specific code
179
+ }
180
+
181
+ const platform = getPlatform(); // 'web' | 'ios' | 'android' | 'native'
182
+ ```
183
+
184
+ ## Toolbar Controls
185
+
186
+ | Button | Description |
187
+ |--------|-------------|
188
+ | ⋮⋮ | Drag handle - move the toolbar |
189
+ | 👆/🚫 | Toggle inspection mode |
190
+ | 📋 | View annotation list |
191
+ | 📋 | Copy annotations as JSON |
192
+ | ➖/⬜ | Minimize/expand toolbar |
193
+
194
+ ## Workflow
195
+
196
+ 1. **Enable Inspection** - Click the inspection toggle
197
+ 2. **Select Component** - Hover (web) or tap (native) on a component
198
+ 3. **Lock Selection** - Click to lock the selection (web)
199
+ 4. **Add Annotation** - Click the + button to add a note
200
+ 5. **Copy Annotations** - Copy all annotations as JSON for AI context
201
+
202
+ ## Tauri Support
203
+
204
+ The package includes special handling for Tauri apps (web apps running in Tauri):
205
+
206
+ ```tsx
207
+ import { isTauriEnv, captureScreenshot } from 'react-ai-anotation';
208
+
209
+ if (isTauriEnv()) {
210
+ // Uses @tauri-apps/plugin-clipboard-manager for clipboard
211
+ }
212
+ ```
213
+
214
+ ## Chrome Extension
215
+
216
+ Use the annotation toolkit on any website as a Chrome extension!
217
+
218
+ ### Build the Extension
219
+
220
+ ```bash
221
+ cd packages/react-ai-anotation
222
+ bun install
223
+ bun run build:extension
224
+ ```
225
+
226
+ ### Install in Chrome
227
+
228
+ 1. Go to `chrome://extensions/`
229
+ 2. Enable **Developer mode** (toggle in top right)
230
+ 3. Click **Load unpacked**
231
+ 4. Select the `dist/` folder
232
+
233
+ ### Usage
234
+
235
+ 1. Click the extension icon to open the popup
236
+ 2. Toggle "Enable Inspector" to activate on the current page
237
+ 3. Hover over elements to highlight them
238
+ 4. Click to add annotations
239
+ 5. Use the floating toolbar to manage annotations
240
+
241
+ See [extension/README.md](extension/README.md) for more details.
242
+
243
+ ## License
244
+
245
+ MIT