gravity-core 1.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gravity Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,281 @@
1
+ # gravity-core
2
+
3
+ **Gravity** - AI-powered CSS layout diagnostics for any IDE.
4
+
5
+ Connect your browser to get real-time layout issue detection. Works with VSCode, Cursor, Kiro, Warp, and any IDE with MCP support.
6
+
7
+ ## 🎯 What It Does
8
+
9
+ Ask your AI assistant: *"Why is my modal not showing?"*
10
+
11
+ Gravity will:
12
+ 1. Connect to your browser
13
+ 2. Inspect the actual DOM element
14
+ 3. Analyze its position, styles, and visibility
15
+ 4. Return specific issues and fixes
16
+
17
+ ## 🚀 Quick Start (2 minutes)
18
+
19
+ ### 1. Install Package
20
+
21
+ ```bash
22
+ npm install gravity-core
23
+ ```
24
+
25
+ ### 2. Load Chrome Extension
26
+
27
+ 1. Go to `chrome://extensions`
28
+ 2. Enable "Developer mode"
29
+ 3. Click "Load unpacked"
30
+ 4. Select the `extension/` folder from the repo
31
+ 5. ✅ Done!
32
+
33
+ ### 3. Connect to Tab
34
+
35
+ 1. Click the Gravity extension icon
36
+ 2. Click "Connect to Tab"
37
+ 3. Status turns 🟢 Green
38
+
39
+ ### 4. Configure Your IDE
40
+
41
+ **VSCode:**
42
+ ```json
43
+ {
44
+ "mcpServers": {
45
+ "gravity": {
46
+ "command": "npx",
47
+ "args": ["gravity-core"],
48
+ "disabled": false
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ **Cursor:**
55
+ Same as VSCode
56
+
57
+ **Kiro:**
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "gravity": {
62
+ "command": "npx",
63
+ "args": ["gravity-core"],
64
+ "disabled": false
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ **Warp or any IDE with MCP:**
71
+ Add the same config to your IDE's MCP settings.
72
+
73
+ ### 5. Start Diagnosing
74
+
75
+ Ask your AI:
76
+ - "Diagnose the #modal element"
77
+ - "Why is the .button not showing?"
78
+ - "Check if the browser is connected"
79
+
80
+ ## 📊 Example Output
81
+
82
+ ```json
83
+ {
84
+ "element": "#modal",
85
+ "found": true,
86
+ "issues": [
87
+ {
88
+ "type": "offscreen-right",
89
+ "severity": "high",
90
+ "message": "Element extends 50px beyond right edge of viewport",
91
+ "suggestion": "Add max-width: 100% or use overflow: hidden on parent"
92
+ }
93
+ ],
94
+ "position": {
95
+ "left": 100,
96
+ "top": 50,
97
+ "width": 500,
98
+ "height": 300
99
+ },
100
+ "viewport": {
101
+ "width": 1920,
102
+ "height": 1080
103
+ }
104
+ }
105
+ ```
106
+
107
+ ## 🔌 How It Works
108
+
109
+ ```
110
+ Your IDE (VSCode, Cursor, Kiro, etc.)
111
+
112
+ MCP Server (gravity-core)
113
+
114
+ WebSocket Connection (port 9224)
115
+
116
+ Chrome Extension (running native bridge)
117
+
118
+ Browser Tab (DOM, CSS, Layout data)
119
+ ```
120
+
121
+ **No manual setup needed!** The extension automatically runs the native bridge when you connect to a tab.
122
+
123
+ ## 📚 Detected Issues
124
+
125
+ - 🔴 **Offscreen elements** - Left, right, top, bottom
126
+ - 🔴 **Hidden elements** - display: none, visibility: hidden, opacity: 0
127
+ - 🟡 **Z-index issues** - Missing or low z-index
128
+ - 🟡 **Dimension issues** - Zero width/height
129
+ - 🟢 **Overflow issues** - overflow: hidden clipping content
130
+ - 🟢 **Positioning issues** - Uncentered modals
131
+
132
+ ## 🎯 Common Workflows
133
+
134
+ ### Fix Offscreen Modal
135
+
136
+ 1. Browser: Open page with broken layout
137
+ 2. Extension: Click icon → "Connect to Tab" (🟢 Green)
138
+ 3. IDE: Ask AI: "Diagnose the .modal element"
139
+ 4. AI: Shows "Element extends 50px beyond right edge"
140
+ 5. You: Add `max-width: 100%` to CSS
141
+ 6. Browser: Refreshes automatically
142
+ 7. AI: Diagnose again → ✅ Fixed!
143
+
144
+ ### Debug Hidden Element
145
+
146
+ 1. Browser: Open page with hidden element
147
+ 2. Extension: Connect to tab
148
+ 3. IDE: Ask AI: "Why is the #button not showing?"
149
+ 4. AI: "The element has display: none"
150
+ 5. You: Change CSS to `display: block`
151
+ 6. AI: Diagnose again → ✅ Visible!
152
+
153
+ ## 🔧 API Reference
154
+
155
+ ### Gravity
156
+
157
+ ```typescript
158
+ import { Gravity } from 'gravity-core';
159
+
160
+ const bridge = new Gravity(options);
161
+ ```
162
+
163
+ #### Methods
164
+
165
+ ##### `connectBrowser(port?: number): Promise<void>`
166
+
167
+ Connect to browser.
168
+
169
+ ```javascript
170
+ await bridge.connectBrowser();
171
+ ```
172
+
173
+ ##### `disconnectBrowser(): Promise<void>`
174
+
175
+ Disconnect from browser.
176
+
177
+ ```javascript
178
+ await bridge.disconnectBrowser();
179
+ ```
180
+
181
+ ##### `isConnected(): boolean`
182
+
183
+ Check if connected.
184
+
185
+ ```javascript
186
+ if (bridge.isConnected()) {
187
+ console.log('Connected!');
188
+ }
189
+ ```
190
+
191
+ ##### `diagnoseLayout(selector: string): Promise<DiagnosticResult>`
192
+
193
+ Diagnose layout issues.
194
+
195
+ ```javascript
196
+ const result = await bridge.diagnoseLayout('#modal');
197
+ console.log(result.issues);
198
+ ```
199
+
200
+ #### Events
201
+
202
+ ```javascript
203
+ bridge.on('connected', () => {
204
+ console.log('Connected to browser!');
205
+ });
206
+
207
+ bridge.on('disconnected', () => {
208
+ console.log('Disconnected from browser');
209
+ });
210
+
211
+ bridge.on('error', (error) => {
212
+ console.error('Error:', error);
213
+ });
214
+ ```
215
+
216
+ ## 🐛 Troubleshooting
217
+
218
+ **"Not connected to browser"**
219
+ - Make sure Chrome/Edge is open
220
+ - Click extension icon → "Connect to Tab"
221
+ - Status should turn green
222
+
223
+ **"Extension not loaded"**
224
+ - Go to `chrome://extensions`
225
+ - Enable "Developer mode"
226
+ - Click "Load unpacked"
227
+ - Select the `extension/` folder
228
+
229
+ **"Port 9224 already in use"**
230
+ - Edit extension's `background.js`
231
+ - Change `WEBSOCKET_PORT` to 9225
232
+ - Update IDE config with `GRAVITY_PORT: 9225`
233
+
234
+ **"Element not found"**
235
+ - Check selector is correct
236
+ - Make sure element exists in page
237
+ - Try simpler selector: `div` instead of `#modal`
238
+
239
+ ## 📖 Documentation
240
+
241
+ - [Setup Guide](./SETUP.md) - Complete setup instructions
242
+ - [Architecture](./ARCHITECTURE.md) - How it works under the hood
243
+
244
+ ## 🚀 Supported IDEs
245
+
246
+ - ✅ VSCode
247
+ - ✅ Cursor
248
+ - ✅ Kiro
249
+ - ✅ Warp
250
+ - ✅ Any IDE with MCP support
251
+
252
+ ## 🔒 Security
253
+
254
+ - ✅ Extension only connects to localhost
255
+ - ✅ WebSocket server only accepts local connections
256
+ - ✅ No external API calls
257
+ - ✅ All data stays local
258
+ - ✅ No user data collection
259
+
260
+ ## 📝 License
261
+
262
+ MIT
263
+
264
+ ## 🤝 Contributing
265
+
266
+ Contributions welcome! Please open an issue or PR on GitHub.
267
+
268
+ ## 📞 Support
269
+
270
+ - [GitHub Issues](https://github.com/gravity/core/issues)
271
+ - [Documentation](https://gravity.dev)
272
+
273
+ ---
274
+
275
+ **Ready to diagnose layouts in real-time?**
276
+
277
+ ```bash
278
+ npm install gravity-core
279
+ ```
280
+
281
+ Then load the extension and configure your IDE. Happy debugging! 🎉