Skip to content

Commit 4087571

Browse files
committed
0.1.5 Beta version released
1 parent 170bd8c commit 4087571

File tree

15 files changed

+866
-296
lines changed

15 files changed

+866
-296
lines changed

.npmignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
.idea/
44
*.log
55
.DS_Store
6+
package-lock.json
7+
8+
# Exclude src/ since we would be distributing dist/ in npm
9+
src/
610

711
# Git files
812
.git/
@@ -22,15 +26,12 @@ examples/
2226

2327
# Build artifacts that shouldn't be published
2428
node_modules/
25-
dist/
2629
build/
2730
.svelte-kit/
2831

2932
# Environment and config files
3033
.env*
3134
tsconfig.json
35+
tsconfig.build.json
3236
vite.config.js
33-
svelte.config.js
34-
35-
# Only include src/ directory and essential files
36-
# Everything else should be ignored unless explicitly needed
37+
svelte.config.js

CHANGELOG.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
11
# Changelog
22

33
All notable changes to this project will be documented in this file.
4-
54
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
65
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
76

87
## [Unreleased]
98

109
### Planned
1110

12-
- Base64 encoding for metadata
13-
- Configuration options
14-
- Performance optimizations
15-
- Better error handling
16-
- TypeScript definitions
11+
- Work towards making it stable.
12+
- Add the related file name too below the colored overlay.
13+
14+
## [0.1.5-beta] - 30th Aug 2025
15+
16+
### Added
17+
18+
- **Click to Open in VS Code**: Ctrl/Cmd + Click functionality to instantly open source files in VS Code
19+
- **Automatic Client-side Script Injection**: Zero-configuration setup with automatic script injection for click-to-open functionality
20+
- **Base64 Metadata Encoding**: Implemented base64 encoding for `data-svelte-trace` attributes
21+
- **Configuration Options**: Added `openInCode` configuration option to control client-side script injection
22+
- **VS Code Integration**: Seamless integration with VS Code through `vscode://` protocol links
23+
- **Enhanced User Experience**: Instant navigation from browser elements to source code with precise line and column positioning
24+
25+
### Technical Improvements
26+
27+
- Client-side event listener for `Ctrl/Cmd` + `Click` detection
28+
- Base64 encoding/decoding for metadata security and cleanliness
29+
- Configurable preprocessor options
30+
- VS Code protocol URL construction for direct editor opening
31+
- Improved metadata handling and parsing
32+
33+
### Changed
34+
35+
- Made code modular, and more readable
36+
- Metadata format now uses base64 encoding for cleaner HTML output
37+
- Enhanced preprocessor configuration system
38+
- Improved documentation with comprehensive setup guide
39+
40+
### Fixed
41+
42+
- Nothing there to fix.
1743

1844
## [0.1.0-beta] - 27th Aug 2025
1945

@@ -41,7 +67,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4167
- Metadata is not base64 encoded yet
4268
- Limited testing with complex Svelte features
4369
- No configuration options
44-
- Performance not optimized for large applications
70+
- Terrible code quality
4571

46-
[Unreleased]: https://github.com/Git002/svelte-trace/compare/v0.1.0-beta.1...HEAD
72+
[Unreleased]: https://github.com/Git002/svelte-trace/compare/v0.1.5-beta...HEAD
73+
[0.1.5-beta]: https://github.com/Git002/svelte-trace/compare/v0.1.0-beta.1...v0.1.5-beta
4774
[0.1.0-beta]: https://github.com/Git002/svelte-trace/releases/tag/v0.1.0-beta.1

README.md

Lines changed: 68 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,131 @@
11
<p align="center">
2-
<img src="https://beeimg.com/images/p32116343591.png" alt="Svelte Trace Logo" width="200" />
2+
<a href="https://github.com/Git002/svelte-trace">
3+
<img src="https://beeimg.com/images/p32116343591.png" alt="Svelte Trace Logo" width="250" />
4+
</a>
35
</p>
46

5-
<h1 align="center">svelte-trace.js</h1>
7+
<h1 align="center">Svelte Trace</h1>
68

7-
> **⚠️ Beta Stage**: This package is currently in beta and may not be stable. Use with caution.
9+
<p align="center">
10+
<strong>
11+
Instantly jump from your browser to your Svelte code in VS Code.
12+
</strong>
13+
<br />
14+
Supercharge your development workflow by <code>Ctrl + Clicking</code> any element to open its source.
15+
</p>
816

9-
`svelte-trace` is a **Svelte 5 preprocessor** (unofficial) that enables visual editing by adding metadata to HTML elements. It creates a bridge between visual editors and your actual Svelte code, making it possible to build tools like visual website builders that directly modify your source files.
17+
<p align="center">
18+
<a href="https://www.npmjs.com/package/svelte-trace"><img src="https://img.shields.io/npm/v/svelte-trace.svg" alt="NPM Version"></a>
19+
<a href="https://github.com/Git002/svelte-trace/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/svelte-trace.svg" alt="License"></a>
20+
</p>
1021

11-
## 🚀 What does svelte-trace do?
22+
> ⚠️ BETA Stage: This package is currently in BETA stage, and may evolve. Things might break, and your feedback is most welcomed. Happy Coding!
1223
13-
It automatically adds `data-svelte-trace` attributes to all HTML elements in your Svelte components. These attributes contain metadata about the element's location in your source code, including:
24+
---
1425

15-
- File path
16-
- Class attribute position (start/end offsets)
17-
- Line numbers and positioning data
26+
`svelte-trace` is a Svelte 5 preprocessor that closes the gap between your rendered application and your source code. Stop hunting for components in your file tree—just `Ctrl + Click` in your browser, and **instantly land in the right file and line in VS Code!**
1827

19-
This enables the creation of visual editors that can:
28+
## 🚀 Key Features
2029

21-
- Click on any element in the browser
22-
- Instantly know where it exists in your code
23-
- Make real-time changes to your Svelte files
24-
- Support Tailwind classes, inline styles, and more (in future)
30+
- **🖱️ Click to Open in VS Code:** `Ctrl + Click` (or `Cmd + Click`) any element during development to open its source file directly in your editor, pinpointing the exact line and column.
2531

26-
## 🎯 Use Cases
32+
- **✨ Zero Configuration:** The client-side script that enables the click-to-open functionality is injected automatically. Just add the preprocessor to your config, and you're done.
2733

28-
- **Visual Website Builders**: Build Webflow-like editors for Svelte
29-
- **Design Systems**: Allow designers to modify components visually
30-
- **Rapid Prototyping**: Speed up development with visual editing tools
31-
- **Client Editing**: Let clients make content/style changes without coding
32-
- **Developer Tools**: Create better debugging and development experiences
34+
- **🛠️ Extensible for Tooling:** Under the hood, it works by adding source code metadata to your HTML elements. This powerful foundation can be used to build advanced tools like visual editors like webflow/figma, but for svelte and edit code in realtime visually.
3335

3436
## 📦 Installation
3537

3638
```bash
3739
npm install svelte-trace --save-dev
3840
```
3941

40-
## 🔧 Usage
42+
## 🔧 Getting Started in 3 Steps
4143

42-
### Basic Setup
44+
### Step 1: Update your svelte.config.js
4345

44-
Add SvelteTrace to your `svelte.config.js`:
46+
Add svelteTrace to your preprocessor array. It's that simple.
4547

46-
```javascript
48+
```js
49+
// Basic svelte.config.js
4750
import adapter from "@sveltejs/adapter-auto";
4851
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
4952
import { svelteTrace } from "svelte-trace";
5053

5154
/** @type {import('@sveltejs/kit').Config} */
5255
const config = {
56+
// Add svelteTrace() to your preprocessors
5357
preprocess: [vitePreprocess(), svelteTrace()],
54-
5558
kit: {
56-
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
57-
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
58-
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
5959
adapter: adapter(),
6060
},
61-
62-
extensions: [".svelte"],
6361
};
6462

6563
export default config;
6664
```
6765

68-
## 📋 Example Output
66+
### Step 2: Run your dev server
6967

70-
**Input:**
71-
72-
```html
73-
<div class="bg-blue-500 text-white">
74-
<h1 class="text-2xl font-bold">Hello World</h1>
75-
<p>This is a paragraph</p>
76-
</div>
68+
```bash
69+
npm run dev
7770
```
7871

79-
**Output:**
72+
### Step 3: Ctrl + Click Anything!
8073

81-
```html
82-
<div class="bg-blue-500 text-white" data-svelte-trace="loc[45,67]-f[src/App.svelte]">
83-
<h1 class="text-2xl font-bold" data-svelte-trace="loc[120,142]-f[src/App.svelte]">Hello World</h1>
84-
<p data-svelte-trace="loc[-1,-1]-f[src/App.svelte]">This is a paragraph</p>
85-
</div>
86-
```
87-
88-
## 📊 Metadata Format
74+
Open your application in the browser, hold down the `Ctrl` (or `Cmd` on Mac) key, and `click` on any element. It will instantly open in your VS Code editor.
8975

90-
The `data-svelte-trace` attribute contains:
76+
## ⚙️ Configuration
9177

92-
- `loc[start,end]`: Character offsets of the class attribute in the file (-1,-1 if no class)
93-
- `f[filepath]`: Relative path to the source file
78+
The preprocessor is designed to work **out-of-the-box**. However, you can customize its behavior.
9479

95-
**Future versions will use base64 encoding for more compact metadata.**
80+
```js
81+
// svelte.config.js
82+
import { svelteTrace } from "svelte-trace";
9683

97-
## 🛠️ Building Visual Editors
84+
const config = {
85+
// The client-side "Open in VS Code" script is injected by default.
86+
// Set to false if you only want the metadata for building custom tools.
87+
preprocess: [svelteTrace({ openInCode: false })],
88+
// ...
89+
};
90+
```
9891

99-
With SvelteTrace, you can build editors that:
92+
## 🤔 How It Works
10093

101-
1. **Parse metadata**: Extract file paths and positions from DOM elements
102-
2. **Locate source code**: Find exact locations in your Svelte files
103-
3. **Make changes**: Modify classes, styles, or content programmatically
104-
4. **Update files**: Write changes back to your source code in real-time
94+
`svelte-trace` parses your Svelte components during the build process and injects a `data-svelte-trace` attribute into every HTML element. This attribute contains the element's exact location in your source code.
10595

106-
Example of reading the metadata:
96+
Input Svelte Code:
10797

108-
```javascript
109-
// Get element metadata
110-
const element = document.querySelector("[data-svelte-trace]");
111-
const metadata = element.getAttribute("data-svelte-trace");
98+
```html
99+
<div>
100+
<h1>Hello World</h1>
101+
</div>
102+
```
112103

113-
// Parse: "loc[45,67]-f[src/App.svelte]"
114-
const [locPart, filePart] = metadata.split("-f");
115-
const [start, end] = locPart.match(/\d+/g).map(Number);
116-
const filepath = filePart.slice(1, -1); // Remove brackets
104+
Output HTML:
117105

118-
console.log({ start, end, filepath });
119-
// { start: 45, end: 67, filepath: "src/App.svelte" }
106+
```html
107+
<div data-svelte-trace="dGFnWzQ6Ml0tbG9jWy0xOi0xXS1mW3NyYy9yb3V0ZXMvK3BhZ2Uuc3ZlbHRlXQ==">
108+
<h1 data-svelte-trace="dGFnWzU6NF0tbG9jWy0xOi0xXS1mW3NyYy9yb3V0ZXMvK3BhZ2Uuc3ZlbHRlXQ==">
109+
Hello World
110+
</h1>
111+
</div>
120112
```
121113

122-
## 🎨 Framework Compatibility
123-
124-
-**Svelte 5**: Full support
125-
-**SvelteKit**: Full support
126-
-**Vite**: Full support
127-
-**Tailwind CSS**: Works perfectly
128-
- ⚠️ **Svelte 4**: Not tested (may work)
114+
The automatically injected client-side script listens for `Ctrl` + `Click` events, reads this attribute, and constructs a `vscode://` link to open the file instantly.
129115

130-
## 🚧 Current Limitations (Beta)
116+
## 🎯 Advanced Use Case: Building Visual Editors
131117

132-
- Metadata is not yet base64 encoded
133-
- Limited testing with complex Svelte features
134-
- No configuration options yet
135-
- Performance not optimized for large applications
136-
- May conflict with SSR in some edge cases
118+
While the primary feature is the "Open in VS Code" workflow, the metadata added by svelte-trace is powerful. It creates a bridge that allows you to build sophisticated tools, such as:
137119

138-
## 🗺️ Roadmap
120+
- **Visual Website Builders:** Create Webflow-like editors for Svelte.
121+
- **Client-Facing Edit Tools:** Let clients make content or style changes safely.
122+
- **Enhanced DevTools:** Build custom debugging and development experiences.
139123

140-
- [ ] Base64 encoding for metadata
141-
- [ ] Configuration options
142-
- [ ] Performance optimizations
143-
- [ ] Better error handling
144-
- [ ] Support for more Svelte features
145-
- [ ] Official visual editor
146-
- [ ] React/Vue preprocessors
124+
To build these tools, you can disable the default click handler with openInCode: false and implement your own logic to parse the data-svelte-trace attributes.
147125

148126
## 🤝 Contributing
149127

150-
We welcome contributions! This is beta software and needs testing across different Svelte applications.
128+
We welcome contributions! This is beta software and needs testing across different Svelte applications. Please report issues, suggest features, or submit pull requests.
151129

152130
## 📄 License
153131

index.d.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)