web-remarq 0.3.0 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +70 -58
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Visual annotation tool for design review workflows. Framework-agnostic, zero dependencies.
4
4
 
5
- Designer annotates UI elements on staging/dev, exports a report. Developer imports the report and sees markers on the exact elements. Copy annotations as agent-friendly markdown with search hints for AI coding agents.
5
+ Designer annotates UI elements on staging/dev, exports a report. Developer imports the report and sees markers on the exact elements. Export as agent-friendly JSON with source locations and search hints for AI coding agents.
6
6
 
7
7
  ## Install
8
8
 
@@ -10,6 +10,18 @@ Designer annotates UI elements on staging/dev, exports a report. Developer impor
10
10
  npm install web-remarq
11
11
  ```
12
12
 
13
+ ### Build plugins (optional)
14
+
15
+ For precise source location injection (`file:line:col` on every element):
16
+
17
+ ```bash
18
+ # Babel (React, Preact, Solid)
19
+ npm install -D @web-remarq/babel-plugin
20
+
21
+ # Vite / webpack / Rollup / esbuild / Rspack
22
+ npm install -D @web-remarq/unplugin
23
+ ```
24
+
13
25
  ## Quick Start
14
26
 
15
27
  ```ts
@@ -47,14 +59,18 @@ Remove all DOM nodes, event listeners, and observers. Full cleanup.
47
59
 
48
60
  Switch between `'light'` and `'dark'` themes.
49
61
 
50
- ### `WebRemarq.copy()`
62
+ ### `WebRemarq.copy(format?)`
51
63
 
52
- Copy annotations as agent-friendly markdown to clipboard. Includes ranked search hints (CSS selectors, class names, text content, DOM path) so AI coding agents can grep and locate the source code.
64
+ Copy annotations to clipboard.
65
+
66
+ - `'md'` (default) — agent-friendly markdown with search hints
67
+ - `'agent'` — structured JSON with source locations and grep queries
53
68
 
54
69
  ### `WebRemarq.export(format)`
55
70
 
56
- - `'md'` — downloads `.md` file with search hints (same content as `copy()`)
57
- - `'json'` — downloads `.json` file with full annotation data
71
+ - `'md'` — downloads `.md` file with search hints
72
+ - `'json'` — downloads `.json` file with full annotation data (for import)
73
+ - `'agent'` — downloads `.json` with source locations, grep queries, and confidence levels
58
74
 
59
75
  ### `WebRemarq.import(file)`
60
76
 
@@ -70,15 +86,49 @@ const result = await WebRemarq.import(input.files[0])
70
86
 
71
87
  Get all annotations, or filter by route.
72
88
 
73
- ```ts
74
- WebRemarq.getAnnotations() // all
75
- WebRemarq.getAnnotations('/casino') // by route
76
- ```
77
-
78
89
  ### `WebRemarq.clearAll()`
79
90
 
80
91
  Remove all annotations.
81
92
 
93
+ ## Agent Export Format
94
+
95
+ The `export('agent')` format is optimized for AI coding agents:
96
+
97
+ ```jsonc
98
+ {
99
+ "version": 1,
100
+ "format": "agent",
101
+ "viewportBucket": 1200,
102
+ "annotations": [{
103
+ "id": "a1b2c3d4",
104
+ "route": "/dashboard",
105
+ "comment": "Increase button padding",
106
+ "status": "pending",
107
+ "source": {
108
+ "file": "src/components/ActionBar.tsx",
109
+ "line": 24,
110
+ "column": 6,
111
+ "component": "ActionBar"
112
+ },
113
+ "searchHints": {
114
+ "grepQueries": [
115
+ { "query": "data-testid=\"save-btn\"", "glob": "*.{tsx,jsx,vue}", "confidence": "high" },
116
+ { "query": "\"Save changes\"", "glob": "*.{tsx,jsx,vue}", "confidence": "medium" }
117
+ ],
118
+ "domContext": "div.action-bar > button",
119
+ "tagName": "button",
120
+ "classes": ["action-button"]
121
+ }
122
+ }]
123
+ }
124
+ ```
125
+
126
+ Source detection uses a 3-level fallback:
127
+
128
+ 1. **Build plugin** — exact `file:line:col` from [`@web-remarq/babel-plugin`](https://www.npmjs.com/package/@web-remarq/babel-plugin) or [`@web-remarq/unplugin`](https://www.npmjs.com/package/@web-remarq/unplugin)
129
+ 2. **Runtime detection** — `data-source` attrs (locator.js), React fiber `_debugSource` (dev mode)
130
+ 3. **Heuristic** — grep queries ranked by confidence (`high` / `medium` / `low`)
131
+
82
132
  ## Core-only usage
83
133
 
84
134
  For programmatic access without UI:
@@ -95,57 +145,29 @@ When a user clicks an element, a multi-signal fingerprint is captured:
95
145
 
96
146
  - **Stable anchors** — `data-annotate`, `data-testid`, `id`
97
147
  - **Semantics** — tag name, text content, ARIA role/label
98
- - **Structure** — stable CSS classes (hashes stripped), DOM path with parent classes, sibling index
99
- - **Parent context** — nearest ancestor's `data-annotate` value
100
- - **Agent export** — raw classes, CSS Module decomposition (module hint + local class name)
148
+ - **Structure** — stable CSS classes (hashes stripped), DOM path, sibling index
149
+ - **Source location** — from build plugin or runtime detection
101
150
 
102
151
  ### Matching
103
152
 
104
- When loading annotations, elements are found via a fallback chain:
153
+ Elements are found via a fallback chain:
105
154
 
106
155
  1. Exact match by `data-annotate` or `data-testid`
107
156
  2. Exact match by `id`
108
157
  3. Fuzzy match using weighted scoring (text similarity, ARIA, classes, DOM path)
109
- 4. Unmatched annotations sorted into "other viewport" or "detached" panels
158
+ 4. Unmatched annotations go to "other viewport" or "detached" panels
110
159
 
111
160
  ### Viewport Breakpoints
112
161
 
113
- Annotations are tagged with a viewport bucket (width rounded to 100px). When resizing:
114
-
115
- - **Attached** — element found in current viewport
116
- - **Other viewport** — element not found, but annotation belongs to a different breakpoint (not an error)
117
- - **Detached** — element not found even in its native breakpoint (real problem)
118
-
119
- Automatic reconnection when returning to the annotation's native viewport.
120
-
121
- ### Agent-Friendly Copy
122
-
123
- The Copy button produces markdown with ranked search hints:
124
-
125
- ```markdown
126
- ### 1. [pending] "Button too small on mobile"
127
- Element: <button> "Submit"
128
- Viewport: 300px
129
-
130
- Search hints:
131
- - `data-testid="submit-btn"` — in template files
132
- - `"Submit"` — text content in templates
133
- - `.submitButton` — in CSS Module file (likely `form.module.*`)
134
- - DOM: div.form-wrapper > form > button.submit
135
- - Classes: form__submitButton__cEqts flex items-center
136
- ```
137
-
138
- ### Hash Detection
139
-
140
- Automatically strips hashed classes from CSS Modules, styled-components, Emotion, and pure hash patterns.
162
+ Annotations are tagged with a viewport bucket (width rounded to 100px). Automatic reconnection when returning to the annotation's native viewport.
141
163
 
142
164
  ### SPA Support
143
165
 
144
- Listens for `popstate`, `hashchange`, and intercepts `history.pushState`/`replaceState`. Annotations are scoped per route (`pathname + hash`).
166
+ Intercepts `history.pushState`/`replaceState` and listens for `popstate`/`hashchange`. Annotations are scoped per route.
145
167
 
146
168
  ## Stable Selectors
147
169
 
148
- Works without any markup changes, but for guaranteed stable matching add `data-annotate` to key components:
170
+ Works without any markup changes, but for guaranteed stable matching add `data-annotate`:
149
171
 
150
172
  ```html
151
173
  <CasinoTabs data-annotate="casino-tabs" />
@@ -154,21 +176,11 @@ Works without any markup changes, but for guaranteed stable matching add `data-a
154
176
 
155
177
  ## UI Components
156
178
 
157
- - **Toolbar** — fixed bottom-right panel with inspect, copy, export, import, clear, theme, minimize
179
+ - **Toolbar** — fixed bottom-right panel with inspect, spacing, copy, export, import, clear, theme, minimize
158
180
  - **Inspect mode** — hover to highlight, click to annotate
181
+ - **Spacing inspector** — visualizes margin, padding, content, flex gap on hover
159
182
  - **Markers** — numbered circles (orange = pending, green = resolved)
160
- - **Popup** — comment input for new annotations, detail view with Resolve/Delete for existing
161
- - **Other viewport panel** — annotations from different breakpoints, click to see required viewport
162
- - **Detached panel** — annotations whose elements can't be found in their native viewport
163
-
164
- ## Build Outputs
165
-
166
- | Format | File | Use |
167
- |--------|------|-----|
168
- | ESM | `dist/index.js` | Bundlers |
169
- | CJS | `dist/index.cjs` | `require()` |
170
- | IIFE | `dist/web-remarq.global.global.js` | `<script>` tag |
171
- | Types | `dist/index.d.ts` | TypeScript |
183
+ - **Popup** — comment input / detail view with Resolve/Delete
172
184
 
173
185
  ## License
174
186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-remarq",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Visual annotation tool for design review workflows",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",