sdocs 0.0.17 → 0.0.19
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 +281 -0
- package/dist/client/App.svelte +1 -3
- package/dist/client/views/PreviewFrame.svelte +0 -4
- package/dist/ui/styles/theme.css +5 -5
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# sdocs
|
|
2
|
+
|
|
3
|
+
A lightweight documentation tool for Svelte 5 components. Discover `.sdoc` files in your project and get an interactive component explorer with live previews, prop controls, and code highlighting.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Initialize config
|
|
9
|
+
npx sdocs init
|
|
10
|
+
|
|
11
|
+
# Start dev server
|
|
12
|
+
npx sdocs dev
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install sdocs
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Requirements:** Svelte 5, Vite 6+, `@sveltejs/vite-plugin-svelte` 5+
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
sdocs can be used in two ways: as a **standalone CLI tool** or **embedded in your existing project**.
|
|
26
|
+
|
|
27
|
+
### Standalone (CLI)
|
|
28
|
+
|
|
29
|
+
Run sdocs as its own dev server:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx sdocs dev # Start dev server with HMR
|
|
33
|
+
npx sdocs build # Build static documentation site
|
|
34
|
+
npx sdocs preview # Preview the built site locally
|
|
35
|
+
npx sdocs init # Scaffold a sdocs.config.js file
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Embedded in a SvelteKit / Vite Project
|
|
39
|
+
|
|
40
|
+
Use sdocs as a Vite plugin inside your existing project. This way sdocs runs alongside your app without needing a separate server.
|
|
41
|
+
|
|
42
|
+
**1. Add the Vite plugin**
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
// vite.config.js
|
|
46
|
+
import { sveltekit } from '@sveltejs/kit/vite';
|
|
47
|
+
import { sdocsPlugin } from 'sdocs/vite';
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
plugins: [
|
|
51
|
+
sveltekit(),
|
|
52
|
+
sdocsPlugin({
|
|
53
|
+
include: ['./src/lib/**/*.sdoc'],
|
|
54
|
+
css: './src/styles/global.css',
|
|
55
|
+
logo: 'My Design System',
|
|
56
|
+
})
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The plugin discovers `.sdoc` files and exposes them via a `virtual:sdocs` module.
|
|
62
|
+
|
|
63
|
+
**2. Create a page that mounts the sdocs app**
|
|
64
|
+
|
|
65
|
+
```svelte
|
|
66
|
+
<!-- src/routes/docs/+page.svelte -->
|
|
67
|
+
<script>
|
|
68
|
+
import App from 'sdocs/client';
|
|
69
|
+
import { docs, cssNames } from 'virtual:sdocs';
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<App
|
|
73
|
+
{docs}
|
|
74
|
+
{cssNames}
|
|
75
|
+
logo="My Design System"
|
|
76
|
+
sidebarConfig={{
|
|
77
|
+
order: { root: ['Components', '*'] },
|
|
78
|
+
open: ['Components'],
|
|
79
|
+
}}
|
|
80
|
+
/>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**3. Add the virtual module type declaration** (optional, for TypeScript)
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
// src/app.d.ts or any .d.ts file
|
|
87
|
+
declare module 'virtual:sdocs' {
|
|
88
|
+
import type { DocEntry } from 'sdocs';
|
|
89
|
+
export const docs: DocEntry[];
|
|
90
|
+
export const cssNames: string[];
|
|
91
|
+
export default docs;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
That's it — your docs page lives at `/docs` inside your existing app.
|
|
96
|
+
|
|
97
|
+
## Writing Docs
|
|
98
|
+
|
|
99
|
+
sdocs supports three types of doc files:
|
|
100
|
+
|
|
101
|
+
### Component Docs (`.sdoc`)
|
|
102
|
+
|
|
103
|
+
Document a Svelte component with interactive controls and examples.
|
|
104
|
+
|
|
105
|
+
```svelte
|
|
106
|
+
<!-- Button.sdoc -->
|
|
107
|
+
<script lang="ts">
|
|
108
|
+
import Button from './Button.svelte';
|
|
109
|
+
|
|
110
|
+
export const meta = {
|
|
111
|
+
component: Button,
|
|
112
|
+
title: 'Components / Button',
|
|
113
|
+
description: 'A flexible button component.',
|
|
114
|
+
args: {
|
|
115
|
+
label: 'Click me',
|
|
116
|
+
size: 'md',
|
|
117
|
+
disabled: false,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
{#snippet Default()}
|
|
123
|
+
<Button {...args} />
|
|
124
|
+
{/snippet}
|
|
125
|
+
|
|
126
|
+
{#snippet WithIcon()}
|
|
127
|
+
<Button>
|
|
128
|
+
<Icon name="settings" /> Settings
|
|
129
|
+
</Button>
|
|
130
|
+
{/snippet}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- **`component`** — the Svelte component to document (auto-extracts props, events, snippets, methods, state, CSS custom properties)
|
|
134
|
+
- **`title`** — slash-separated path for sidebar navigation (e.g. `'Components / Button'`)
|
|
135
|
+
- **`args`** — default prop values, used as initial values for interactive controls
|
|
136
|
+
- **`Default` snippet** — gets live interactive controls. Auto-generated as `<Component {...args} />` if omitted.
|
|
137
|
+
- **Named snippets** — static examples listed in the sidebar
|
|
138
|
+
|
|
139
|
+
### Page Docs (`.page.sdoc`)
|
|
140
|
+
|
|
141
|
+
Freeform content pages with auto-generated table of contents.
|
|
142
|
+
|
|
143
|
+
```svelte
|
|
144
|
+
<!-- GettingStarted.page.sdoc -->
|
|
145
|
+
<script lang="ts">
|
|
146
|
+
export const meta = {
|
|
147
|
+
title: 'Docs / Getting Started',
|
|
148
|
+
description: 'How to set up sdocs.',
|
|
149
|
+
};
|
|
150
|
+
</script>
|
|
151
|
+
|
|
152
|
+
<h1>Getting Started</h1>
|
|
153
|
+
<p>Install sdocs and create your first doc file.</p>
|
|
154
|
+
|
|
155
|
+
<h2>Installation</h2>
|
|
156
|
+
<p>Run <code>npm install sdocs</code>...</p>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Table of contents is auto-generated from `<h2>`, `<h3>`, and `<h4>` headings.
|
|
160
|
+
|
|
161
|
+
### Layout Docs (`.layout.sdoc`)
|
|
162
|
+
|
|
163
|
+
Component compositions rendered in an isolated iframe.
|
|
164
|
+
|
|
165
|
+
```svelte
|
|
166
|
+
<!-- LoginForm.layout.sdoc -->
|
|
167
|
+
<script lang="ts">
|
|
168
|
+
import Card from './Card.svelte';
|
|
169
|
+
import Input from './Input.svelte';
|
|
170
|
+
import Button from './Button.svelte';
|
|
171
|
+
|
|
172
|
+
export const meta = {
|
|
173
|
+
title: 'Patterns / Login Form',
|
|
174
|
+
description: 'A login form combining multiple components.',
|
|
175
|
+
settings: { padding: '24px' },
|
|
176
|
+
};
|
|
177
|
+
</script>
|
|
178
|
+
|
|
179
|
+
<Card padding="24px">
|
|
180
|
+
<Input label="Email" type="email" />
|
|
181
|
+
<Input label="Password" type="password" />
|
|
182
|
+
<Button>Sign in</Button>
|
|
183
|
+
</Card>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Prop Extraction
|
|
187
|
+
|
|
188
|
+
sdocs automatically extracts from your Svelte components:
|
|
189
|
+
|
|
190
|
+
| What | Source |
|
|
191
|
+
|------|--------|
|
|
192
|
+
| **Props** | `$props()` destructuring + `interface Props {}` |
|
|
193
|
+
| **Events** | Callback props (`onclick`, `onchange`, etc.) |
|
|
194
|
+
| **Snippets** | Props typed as `Snippet` or `Snippet<[...]>` |
|
|
195
|
+
| **Methods** | Exported functions |
|
|
196
|
+
| **State** | Exported `$state` / `$derived` values |
|
|
197
|
+
| **CSS Custom Properties** | `var(--name)` usages in `<style>` |
|
|
198
|
+
|
|
199
|
+
JSDoc comments on props are picked up as descriptions.
|
|
200
|
+
|
|
201
|
+
## Interactive Controls
|
|
202
|
+
|
|
203
|
+
The Default snippet gets live controls based on prop types:
|
|
204
|
+
|
|
205
|
+
| Prop Type | Control |
|
|
206
|
+
|-----------|---------|
|
|
207
|
+
| `string` | Text input |
|
|
208
|
+
| `number` | Number input |
|
|
209
|
+
| `boolean` | Checkbox |
|
|
210
|
+
| Color (`#hex`) | Color picker |
|
|
211
|
+
| Dimension (`16px`) | Number + unit |
|
|
212
|
+
|
|
213
|
+
## Configuration
|
|
214
|
+
|
|
215
|
+
Create `sdocs.config.js` in your project root (or run `npx sdocs init`):
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
/** @type {import('sdocs').SdocsConfig} */
|
|
219
|
+
export default {
|
|
220
|
+
// Glob pattern(s) to find .sdoc files
|
|
221
|
+
include: ['./src/**/*.sdoc'],
|
|
222
|
+
|
|
223
|
+
// Dev server port
|
|
224
|
+
port: 3000,
|
|
225
|
+
|
|
226
|
+
// Open browser on start
|
|
227
|
+
open: true,
|
|
228
|
+
|
|
229
|
+
// Sidebar logo text
|
|
230
|
+
logo: 'My Design System',
|
|
231
|
+
|
|
232
|
+
// CSS loaded in preview iframes
|
|
233
|
+
css: './src/styles/global.css',
|
|
234
|
+
|
|
235
|
+
// Sidebar ordering
|
|
236
|
+
sidebar: {
|
|
237
|
+
order: {
|
|
238
|
+
root: ['Components', '*', 'Documentation'],
|
|
239
|
+
},
|
|
240
|
+
open: ['Components'],
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### CSS Stylesheet Switching
|
|
246
|
+
|
|
247
|
+
Provide named stylesheets to let users switch between them (e.g. light/dark themes):
|
|
248
|
+
|
|
249
|
+
```js
|
|
250
|
+
css: {
|
|
251
|
+
light: './src/styles/light.css',
|
|
252
|
+
dark: './src/styles/dark.css',
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Sidebar Ordering
|
|
257
|
+
|
|
258
|
+
Control the order of items in the sidebar with `sidebar.order`. Use `'*'` as a wildcard for remaining items in alphabetical order:
|
|
259
|
+
|
|
260
|
+
```js
|
|
261
|
+
sidebar: {
|
|
262
|
+
order: {
|
|
263
|
+
root: ['Getting Started', 'Components', '*'],
|
|
264
|
+
Components: ['Button', 'Input', '*'],
|
|
265
|
+
},
|
|
266
|
+
open: ['Components'],
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Package Exports
|
|
271
|
+
|
|
272
|
+
| Export | Description |
|
|
273
|
+
|--------|-------------|
|
|
274
|
+
| `sdocs` | Main entry — `sdocsPlugin` + types |
|
|
275
|
+
| `sdocs/vite` | Vite plugin function |
|
|
276
|
+
| `sdocs/client` | App.svelte UI component |
|
|
277
|
+
| `sdocs/ui` | Reusable UI components (Button, Frame, Icon, Control, NavTree, Stack) |
|
|
278
|
+
|
|
279
|
+
## License
|
|
280
|
+
|
|
281
|
+
MIT
|
package/dist/client/App.svelte
CHANGED
|
@@ -83,15 +83,11 @@
|
|
|
83
83
|
|
|
84
84
|
<style>
|
|
85
85
|
.sdocs-preview-frame {
|
|
86
|
-
border: 1px solid var(--color-base-200);
|
|
87
|
-
border-radius: 6px;
|
|
88
86
|
overflow: hidden;
|
|
89
87
|
background: var(--color-base-0);
|
|
90
88
|
}
|
|
91
89
|
.sdocs-preview-frame.full-height {
|
|
92
90
|
flex: 1;
|
|
93
|
-
border: none;
|
|
94
|
-
border-radius: 0;
|
|
95
91
|
}
|
|
96
92
|
.sdocs-iframe {
|
|
97
93
|
width: 100%;
|
package/dist/ui/styles/theme.css
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Layer 2 — Semantic aliases (per-theme, use these in components)
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
.sdocs-app {
|
|
10
10
|
/* zinc — Tailwind v4 zinc (oklch), 150-850 interpolated */
|
|
11
11
|
--color-zinc-0: #fff;
|
|
12
12
|
--color-zinc-50: oklch(0.985 0 0);
|
|
@@ -454,12 +454,12 @@
|
|
|
454
454
|
--mono: 'JetBrains Mono', 'SF Mono', Monaco, Consolas, monospace;
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
-
|
|
457
|
+
.sdocs-app {
|
|
458
458
|
font-family: var(--sans);
|
|
459
459
|
}
|
|
460
460
|
|
|
461
|
-
|
|
462
|
-
[data-sdocs-theme="light"] {
|
|
461
|
+
.sdocs-app,
|
|
462
|
+
.sdocs-app[data-sdocs-theme="light"] {
|
|
463
463
|
/* base — layouts, backgrounds, surfaces, borders, text */
|
|
464
464
|
--color-base-0: var(--color-zinc-0);
|
|
465
465
|
--color-base-50: var(--color-zinc-50);
|
|
@@ -684,7 +684,7 @@ body {
|
|
|
684
684
|
--color-action-950: var(--color-blue-950);
|
|
685
685
|
}
|
|
686
686
|
|
|
687
|
-
[data-sdocs-theme="dark"] {
|
|
687
|
+
.sdocs-app[data-sdocs-theme="dark"] {
|
|
688
688
|
/* base — layouts, backgrounds, surfaces, borders, text (inverted) */
|
|
689
689
|
--color-base-0: var(--color-zinc-1000);
|
|
690
690
|
--color-base-50: var(--color-zinc-950);
|