@dwntgrnd/devlens 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Doren Berge
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,318 @@
1
+ # DevLens
2
+
3
+ **Live design token editor and element inspector for Next.js + Tailwind CSS projects.**
4
+
5
+ DevLens is a developer tool that appears as a floating panel inside your running application — similar to how Chrome DevTools' Elements panel lets you inspect and edit styles, except DevLens is purpose-built for design tokens. It's not a browser extension or a separate application. It's a React component you add to your layout that renders only during development and adds nothing to your production bundle.
6
+
7
+ When you open the panel, DevLens scans your document for CSS custom properties and presents each one with a visual control matched to its type. Color tokens get HSL color pickers with hue, saturation, and lightness sliders. Spacing and font-size tokens get numeric inputs with unit support. Shadow tokens get structured editors for offset, blur, spread, and color. You adjust a control, and the change is immediately visible in your actual application behind the panel — your real components, your real layout, responding in real time.
8
+
9
+ Changes made in DevLens are temporary — a hard refresh resets everything. But unlike the Chrome inspector, where style edits are lost the moment you navigate to another page, DevLens changes persist as you move through your application. Adjust your color tokens and spacing on the homepage, then click through to an inner page — your changes are still applied, because DevLens edits the underlying CSS custom properties that all your pages share. You can see how a single token adjustment affects your entire application without re-applying anything. When you're ready to make the changes permanent, DevLens generates two kinds of output. A **CSS diff** showing exactly which custom properties changed and their new values, ready to paste into your stylesheet. And a **structured prompt** formatted for Claude Code or any LLM, describing the changes in a way that an AI coding assistant can apply directly to your codebase. One visual editing session replaces multiple rounds of "make the heading smaller" → wait for build → "no, smaller than that" → wait again.
10
+
11
+ If you're building with AI-assisted development tools, DevLens sits at the point where design intent meets code. Instead of describing visual changes in words and hoping the LLM interprets them correctly, you make the changes yourself — visually, against your real components — and hand off the precise result. It also reduces round-trips to Figma for the kind of fine-tuning that happens during development: "this card shadow is too heavy," "the border radius feels off," "the muted text needs more contrast." You resolve it in the browser, generate the prompt, and move on.
12
+
13
+ ## Features
14
+
15
+ - **Token auto-detection** — Scans `:root` CSS custom properties and presents type-appropriate controls (HSL color pickers, length inputs with unit support, shadow editors, font-size sliders)
16
+ - **Modular scale control** — Adjust all typography tokens proportionally using a modular scale ratio with live preview
17
+ - **Element inspector** — Select any DOM element to view and edit its CSS classes, see computed styles, and get migration suggestions for hardcoded values
18
+ - **Class editing** — Add, remove, and replace CSS classes on any element with autocomplete, conflict detection, and category grouping
19
+ - **Typography audit** — Compare your heading hierarchy against a configured scale baseline to catch inconsistencies
20
+ - **Token migration suggestions** — Flag hardcoded Tailwind classes (e.g., `text-gray-900`) and suggest semantic token replacements (e.g., `text-foreground`)
21
+ - **Diff output** — View all changes as a CSS diff, ready to copy into your stylesheet
22
+ - **Claude Code prompt generation** — Export changes as structured prompts formatted for LLM-assisted development
23
+ - **Token creation** — Define new CSS custom properties with generated prompts for adding them to your codebase
24
+ - **Detached window** — Pop the panel out to a separate browser window for dual-monitor workflows, synced in real time via BroadcastChannel
25
+ - **Dock positions** — Attach the panel to the left, right, or bottom of the viewport
26
+ - **Raw CSS input** — Apply arbitrary CSS to any selected element for quick experimentation
27
+ - **Fully scoped styles** — All DevLens UI uses `te-` prefixed CSS classes that will not interfere with your application
28
+
29
+ ## Installation
30
+
31
+ ### Prerequisites
32
+
33
+ - A **Next.js** project (version 13 or later) using the App Router
34
+ - **Tailwind CSS** with your design tokens defined as CSS custom properties in your global stylesheet (e.g., `globals.css`)
35
+ - **Node.js** and **npm** (or yarn/pnpm)
36
+
37
+ If your project already runs with `npm run dev`, you're ready.
38
+
39
+ ### Install the package
40
+
41
+ ```bash
42
+ npm install devlens
43
+ ```
44
+
45
+ DevLens expects these packages in your project. If you're using Next.js with Tailwind, you almost certainly have them already:
46
+
47
+ - `react` >= 18.0.0
48
+ - `react-dom` >= 18.0.0
49
+ - `next` >= 13.0.0
50
+ - `lucide-react` >= 0.300.0
51
+
52
+ If you don't have `lucide-react`:
53
+
54
+ ```bash
55
+ npm install lucide-react
56
+ ```
57
+
58
+ ### Add DevLens to your layout
59
+
60
+ Open your root layout file (typically `app/layout.tsx`) and add the DevLens component inside `<body>`, after your page content:
61
+
62
+ ```tsx
63
+ // app/layout.tsx
64
+ import { DevLens } from 'devlens';
65
+
66
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
67
+ return (
68
+ <html lang="en">
69
+ <body>
70
+ {children}
71
+ {process.env.NODE_ENV === 'development' && <DevLens />}
72
+ </body>
73
+ </html>
74
+ );
75
+ }
76
+ ```
77
+
78
+ The `process.env.NODE_ENV` check ensures DevLens only renders during development. It will never appear in your production build.
79
+
80
+ ### Verify it's working
81
+
82
+ Start your dev server:
83
+
84
+ ```bash
85
+ npm run dev
86
+ ```
87
+
88
+ You should see a small floating button in the bottom-right corner of your application. Click it to open the DevLens panel. If your global stylesheet defines CSS custom properties on `:root`, they'll appear in the panel with editing controls.
89
+
90
+ ## What You'll See
91
+
92
+ The DevLens panel has three main areas:
93
+
94
+ **Token Editor** — The default tab. Lists every CSS custom property detected on your document's `:root` element, organized by group (colors, typography, spacing, shadows, etc.). Each token has a visual control appropriate to its type. Editing a token updates the live page immediately. At the top, a modular scale control lets you adjust all typography tokens proportionally.
95
+
96
+ **Element Inspector** — Switch to this tab (or use the inspector toggle) to click any element in your application and see its CSS classes, computed styles, and any migration suggestions. You can add, remove, or replace classes directly, with autocomplete and conflict detection.
97
+
98
+ **Output** — The Diff tab shows every change you've made as a CSS diff. The CC Prompt tab generates a structured prompt describing your changes, formatted for Claude Code or any LLM. Copy either output to apply your changes permanently.
99
+
100
+ The panel can be docked to the left, right, or bottom edge of the viewport, or detached into a separate browser window for dual-monitor setups.
101
+
102
+ ## Configuration
103
+
104
+ DevLens works with zero configuration. It auto-detects your CSS custom properties and provides sensible defaults. For project-specific customization, you can optionally configure token labels, grouping, migration suggestions, and more.
105
+
106
+ ### Zero config (just use it)
107
+
108
+ The Quick Start example above is all you need. DevLens will find your tokens automatically.
109
+
110
+ ### Adding token labels and grouping
111
+
112
+ If you want human-readable names for your tokens or want to organize them into custom groups, create a configuration file:
113
+
114
+ ```tsx
115
+ // devlens.config.ts
116
+ import type { DevLensConfig } from 'devlens';
117
+
118
+ export const devlensConfig: DevLensConfig = {
119
+ tokenOverrides: {
120
+ '--color-primary': {
121
+ label: 'Brand Primary',
122
+ group: 'Brand Colors',
123
+ hint: 'Main brand color used for CTAs and links',
124
+ },
125
+ '--color-primary-foreground': {
126
+ label: 'Brand Primary Text',
127
+ group: 'Brand Colors',
128
+ },
129
+ '--font-size-base': {
130
+ label: 'Body Text',
131
+ group: 'Typography',
132
+ hint: 'Base font size (1rem = 16px)',
133
+ },
134
+ },
135
+ };
136
+ ```
137
+
138
+ Then pass the config to DevLens in your layout:
139
+
140
+ ```tsx
141
+ // app/layout.tsx
142
+ import { DevLens } from 'devlens';
143
+ import { devlensConfig } from '../devlens.config';
144
+
145
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
146
+ return (
147
+ <html lang="en">
148
+ <body>
149
+ {children}
150
+ {process.env.NODE_ENV === 'development' && <DevLens {...devlensConfig} />}
151
+ </body>
152
+ </html>
153
+ );
154
+ }
155
+ ```
156
+
157
+ ### Adding migration suggestions
158
+
159
+ If your project has hardcoded Tailwind utility classes that should be replaced with semantic tokens, add a migration map. DevLens will flag these classes when you inspect elements and suggest replacements:
160
+
161
+ ```tsx
162
+ // devlens.config.ts
163
+ export const devlensConfig: DevLensConfig = {
164
+ migrationMap: {
165
+ 'text-gray-900': {
166
+ replacement: 'text-foreground',
167
+ reason: 'Use semantic color token instead of fixed gray',
168
+ confidence: 'high',
169
+ },
170
+ 'bg-white': {
171
+ replacement: 'bg-background',
172
+ reason: 'Use semantic surface token for theme support',
173
+ confidence: 'high',
174
+ },
175
+ 'text-gray-500': {
176
+ replacement: 'text-muted-foreground',
177
+ reason: 'Use semantic muted text token',
178
+ confidence: 'medium',
179
+ },
180
+ },
181
+ };
182
+ ```
183
+
184
+ ### Isolating multiple DevLens instances
185
+
186
+ If you work on multiple projects simultaneously or want to keep DevLens state separate between apps, set a namespace:
187
+
188
+ ```tsx
189
+ export const devlensConfig: DevLensConfig = {
190
+ namespace: 'my-app',
191
+ };
192
+ ```
193
+
194
+ This prefixes all localStorage keys and BroadcastChannel names so different projects don't interfere with each other.
195
+
196
+ ### Full configuration reference
197
+
198
+ | Prop | Type | Default | Description |
199
+ |------|------|---------|-------------|
200
+ | `tokenOverrides` | `Record<string, TokenOverride>` | `{}` | Labels, grouping, hints, and visibility for auto-detected tokens |
201
+ | `tokenGroups` | `string[]` | `[]` | Additional token group names beyond built-in defaults |
202
+ | `scaleBaseline` | `ScaleBaselineConfig` | `null` | Scale baseline mappings for typography audit (element → expected token) |
203
+ | `migrationMap` | `Record<string, MigrationEntry>` | Generic Tailwind map | Class migration suggestions (hardcoded → semantic) |
204
+ | `projectTextSizeClasses` | `string[]` | `[]` | Additional text size classes for typography detection |
205
+ | `namespace` | `string` | `'devlens'` | Namespace for localStorage keys and BroadcastChannel isolation |
206
+ | `detachedRoute` | `string` | `'/dev/devlens-detached'` | Route path for detached window |
207
+ | `previewFontFamily` | `string` | `'inherit'` | Font family used in typography preview |
208
+ | `forceEnable` | `boolean` | `false` | Render DevLens outside of `development` environment |
209
+
210
+ ### Type reference
211
+
212
+ <details>
213
+ <summary>TokenOverride</summary>
214
+
215
+ ```typescript
216
+ interface TokenOverride {
217
+ label?: string; // Human-readable name shown in the panel
218
+ group?: string; // Group heading (tokens with the same group are listed together)
219
+ type?: TokenType; // Force a control type: 'hsl-color' | 'length' | 'shadow' | 'font-size' | 'other'
220
+ hint?: string; // Tooltip shown on hover
221
+ usedBy?: string[]; // Component names that reference this token (informational)
222
+ hidden?: boolean; // Hide this token from the panel
223
+ managedByScale?: boolean; // Indicate this token is controlled by the modular scale
224
+ }
225
+ ```
226
+
227
+ </details>
228
+
229
+ <details>
230
+ <summary>MigrationEntry</summary>
231
+
232
+ ```typescript
233
+ interface MigrationEntry {
234
+ replacement: string; // Suggested replacement class
235
+ reason?: string; // Explanation shown to the user
236
+ confidence?: 'high' | 'medium'; // Confidence indicator
237
+ }
238
+ ```
239
+
240
+ </details>
241
+
242
+ <details>
243
+ <summary>ScaleBaselineConfig</summary>
244
+
245
+ ```typescript
246
+ interface ScaleBaselineConfig {
247
+ mapping: ScaleBaselineMapping[];
248
+ }
249
+
250
+ interface ScaleBaselineMapping {
251
+ selector: string; // CSS selector — 'h1', 'h2', 'p'
252
+ fontSizeVar: string; // CSS variable — '--font-size-page-title'
253
+ lineHeightVar: string; // CSS variable — '--line-height-page-title'
254
+ fontWeight?: number; // Font weight (omit to inherit)
255
+ scaleLabel: string; // Human-readable label for this scale step
256
+ }
257
+ ```
258
+
259
+ </details>
260
+
261
+ ## Detached Window
262
+
263
+ DevLens can pop out to a separate browser window for dual-monitor workflows. This is useful when you want the editing panel on one screen and your application on another. The main app and detached panel stay synced in real time — changes you make in either window are immediately reflected in the other.
264
+
265
+ To enable this, add a page route for the detached window:
266
+
267
+ ```tsx
268
+ // app/dev/devlens-detached/page.tsx
269
+ import { DevLens } from 'devlens';
270
+ import { devlensConfig } from '../../../devlens.config';
271
+
272
+ export default function DevLensDetachedPage() {
273
+ return (
274
+ <html lang="en">
275
+ <body style={{ margin: 0, padding: 0 }}>
276
+ <DevLens {...devlensConfig} forceEnable />
277
+ </body>
278
+ </html>
279
+ );
280
+ }
281
+ ```
282
+
283
+ Note: `forceEnable` is needed here because this page runs outside your main layout. The `detachedRoute` config prop should match this file's route path (the default is `/dev/devlens-detached`).
284
+
285
+ Click the detach icon in the DevLens panel header to open the separate window.
286
+
287
+ ## How It Works
288
+
289
+ DevLens runs entirely in the browser. It does not start a server, modify your files, or access your filesystem.
290
+
291
+ On mount, it reads all CSS custom properties from the document's `:root` element using `getComputedStyle`. It infers each token's type from its value (HSL colors, pixel/rem lengths, box-shadow syntax) and renders the appropriate editing control. When you adjust a control, DevLens calls `document.documentElement.style.setProperty()` to update the value — the browser re-renders immediately, and your actual components respond because they reference those same custom properties.
292
+
293
+ All DevLens UI is styled with `te-` prefixed CSS classes loaded from a single scoped stylesheet (`devlens.css`). There's no CSS-in-JS runtime, no global style injection, and no risk of interfering with your application's styles.
294
+
295
+ The detached window feature uses the browser's `BroadcastChannel` API to synchronize state between the main window and the detached panel. Both instances share the same namespace and listen for change events.
296
+
297
+ ## Roadmap
298
+
299
+ - **Direct file writes** — A companion dev server process that writes CSS changes directly to your stylesheet, eliminating the copy-paste step. This is a well-understood architecture (WebSocket bridge between browser UI and a Node.js file-writing process) and is planned for a future release.
300
+ - **Non-Next.js React support** — Remove the `next/dynamic` dependency to support Vite, Remix, and other React frameworks.
301
+ - **VS Code / Cursor extension** — Surface token editing directly in the editor sidebar.
302
+ - **Component mapping** — Identify which components consume which tokens for targeted editing.
303
+
304
+ ## Example App
305
+
306
+ A complete working example lives in [`examples/next-app/`](./examples/next-app/). To run it:
307
+
308
+ ```bash
309
+ cd examples/next-app
310
+ npm install
311
+ npm run dev
312
+ ```
313
+
314
+ Open [http://localhost:3000](http://localhost:3000). The example demonstrates zero-config auto-detection, token overrides with custom labels, migration suggestions, and the detached window route.
315
+
316
+ ## License
317
+
318
+ MIT — see [LICENSE](./LICENSE) for details.