@qds.dev/code 0.8.2 → 0.9.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/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # @qds.dev/code
2
+
3
+ **Interactive code previews and playgrounds for Qwik**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@qds.dev/code.svg)](https://www.npmjs.com/package/@qds.dev/code)
6
+
7
+ ## Overview
8
+
9
+ Documentation with static code examples is hard to learn from. You want to experiment, modify, and see results immediately, but building a live code playground is complex. You need sandboxed execution, bundling, and preview rendering.
10
+
11
+ **@qds.dev/code** provides a PreviewCompiler class that bundles and executes Qwik code in the browser. Powered by Rolldown WASM for fast bundling, your users can compile code and see instant results without any server setup.
12
+
13
+ **What makes this different:** Incremental builds. WASM-based bundling for instant feedback. No remote compilation, no cold starts, no server costs.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @qds.dev/code
19
+ ```
20
+
21
+ **Note:** Typically used in documentation sites, not application code. The WASM bundler adds significant weight (~2MB+). It's recommended to only show the component preview when the user has made the intent they would like to edit code or view a preview.
22
+
23
+ ## Quick Start
24
+
25
+ **Simplest case:** Compile and run code
26
+
27
+ ```typescript
28
+ import { PreviewCompiler } from '@qds.dev/code/preview';
29
+ import { component$ } from '@qwik.dev/core';
30
+
31
+ export default component$(() => {
32
+ const compiler = new PreviewCompiler({
33
+ deps: {
34
+ '@qwik.dev/core': './path-to-core-module'
35
+ }
36
+ });
37
+
38
+ const result = await compiler.compile({
39
+ srcInputs: {
40
+ '/src/app.tsx': `export default component$(() => {
41
+ return <button>Click me</button>;
42
+ });`
43
+ }
44
+ });
45
+
46
+ return <div>{/* Render result */}</div>;
47
+ });
48
+ ```
49
+
50
+ **Common pattern:** Browser-based bundling
51
+
52
+ ```typescript
53
+ import { PreviewCompiler } from '@qds.dev/code/preview';
54
+
55
+ export default component$(() => {
56
+ const compiler = new PreviewCompiler({
57
+ deps: {
58
+ '@qwik.dev/core': './path-to-core-module'
59
+ }
60
+ });
61
+
62
+ const compile$ = $(async (code: string) => {
63
+ return await compiler.compile({
64
+ srcInputs: { '/src/app.tsx': code }
65
+ });
66
+ });
67
+
68
+ return <div>{/* Use compile$ for interactive editing */}</div>;
69
+ });
70
+ ```
71
+
72
+ ## Architecture
73
+
74
+ For package internals, dependency relationships, and design decisions, see [ARCHITECTURE.md](./ARCHITECTURE.md).
75
+
76
+ ## API
77
+
78
+ | Export | Purpose |
79
+ |--------|---------|
80
+ | `.` | debug function for development logging |
81
+ | `./preview` | PreviewCompiler class and compilation utilities |
82
+ | `./preview/node` | Server-side helpers for REPL |
83
+
84
+ ## Why This Pattern?
85
+
86
+ **Browser-based bundling:** We use Rolldown WASM instead of server-side compilation because it eliminates network latency and server costs. Your users get instant feedback. No waiting for compilation, no server to configure or maintain.
87
+
88
+ **Component isolation:** Previews run in sandboxed iframes, isolated from your main application. This prevents code in previews from affecting your documentation site's state or styles. Users can experiment freely without breaking anything.
89
+
90
+ ## Related Packages
91
+
92
+ **Depends on:**
93
+ - [@rolldown/browser](https://www.npmjs.com/package/@rolldown/browser) - WASM bundler for in-browser compilation
94
+
95
+ **Used by:**
96
+ - QDS documentation site - Powers all interactive code examples
97
+
98
+ ## Known Limitations
99
+
100
+ - **Bundle size:** The WASM bundler adds significant weight (~2MB+ for Rolldown). This package is designed for documentation sites where rich interactivity justifies the cost, not for production applications.
101
+ - **Documentation only:** Not intended for production apps. The bundle size and browser-based compilation are optimized for learning environments.
102
+ - **Modern browsers:** Requires WebAssembly and modern JavaScript features (ES2020+). Won't work in IE11 or older browsers.