sdocs 0.0.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 +43 -0
- package/bin/sdocs.js +2 -0
- package/dist/Sdocs.svelte +1210 -0
- package/dist/Sdocs.svelte.d.ts +5 -0
- package/dist/cli/app-plugin.d.ts +7 -0
- package/dist/cli/app-plugin.js +69 -0
- package/dist/cli/config.d.ts +12 -0
- package/dist/cli/config.js +34 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +72 -0
- package/dist/cli/server.d.ts +2 -0
- package/dist/cli/server.js +62 -0
- package/dist/docgen.d.ts +47 -0
- package/dist/docgen.js +463 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -0
- package/dist/internal/ComponentPreview.svelte +58 -0
- package/dist/internal/ComponentPreview.svelte.d.ts +17 -0
- package/dist/internal/CssPropsTable.svelte +239 -0
- package/dist/internal/CssPropsTable.svelte.d.ts +11 -0
- package/dist/internal/Home.svelte +92 -0
- package/dist/internal/Home.svelte.d.ts +9 -0
- package/dist/internal/MethodsTable.svelte +72 -0
- package/dist/internal/MethodsTable.svelte.d.ts +7 -0
- package/dist/internal/PropsTable.svelte +342 -0
- package/dist/internal/PropsTable.svelte.d.ts +12 -0
- package/dist/internal/Showcase.svelte +130 -0
- package/dist/internal/Showcase.svelte.d.ts +21 -0
- package/dist/types.d.ts +162 -0
- package/dist/types.js +1 -0
- package/dist/ui/Badge/Badge.docs.svelte +46 -0
- package/dist/ui/Badge/Badge.docs.svelte.d.ts +26 -0
- package/dist/ui/Badge/Badge.svelte +59 -0
- package/dist/ui/Badge/Badge.svelte.d.ts +17 -0
- package/dist/ui/Badge/index.d.ts +1 -0
- package/dist/ui/Badge/index.js +1 -0
- package/dist/ui/Checkbox/Checkbox.docs.svelte +51 -0
- package/dist/ui/Checkbox/Checkbox.docs.svelte.d.ts +27 -0
- package/dist/ui/Checkbox/Checkbox.svelte +169 -0
- package/dist/ui/Checkbox/Checkbox.svelte.d.ts +18 -0
- package/dist/ui/Checkbox/index.d.ts +1 -0
- package/dist/ui/Checkbox/index.js +1 -0
- package/dist/ui/CodeBlock/CodeBlock.docs.svelte +28 -0
- package/dist/ui/CodeBlock/CodeBlock.docs.svelte.d.ts +24 -0
- package/dist/ui/CodeBlock/CodeBlock.svelte +101 -0
- package/dist/ui/CodeBlock/CodeBlock.svelte.d.ts +7 -0
- package/dist/ui/CodeBlock/index.d.ts +1 -0
- package/dist/ui/CodeBlock/index.js +1 -0
- package/dist/ui/Frame/Frame.docs.svelte +140 -0
- package/dist/ui/Frame/Frame.docs.svelte.d.ts +26 -0
- package/dist/ui/Frame/Frame.svelte +88 -0
- package/dist/ui/Frame/Frame.svelte.d.ts +15 -0
- package/dist/ui/Frame/index.d.ts +1 -0
- package/dist/ui/Frame/index.js +1 -0
- package/dist/ui/InputNumber/InputNumber.docs.svelte +50 -0
- package/dist/ui/InputNumber/InputNumber.docs.svelte.d.ts +26 -0
- package/dist/ui/InputNumber/InputNumber.svelte +275 -0
- package/dist/ui/InputNumber/InputNumber.svelte.d.ts +26 -0
- package/dist/ui/InputNumber/index.d.ts +1 -0
- package/dist/ui/InputNumber/index.js +1 -0
- package/dist/ui/InputText/InputText.docs.svelte +43 -0
- package/dist/ui/InputText/InputText.docs.svelte.d.ts +26 -0
- package/dist/ui/InputText/InputText.svelte +116 -0
- package/dist/ui/InputText/InputText.svelte.d.ts +22 -0
- package/dist/ui/InputText/index.d.ts +1 -0
- package/dist/ui/InputText/index.js +1 -0
- package/dist/ui/Panel/CollapsiblePanel.docs.svelte +45 -0
- package/dist/ui/Panel/CollapsiblePanel.docs.svelte.d.ts +25 -0
- package/dist/ui/Panel/CollapsiblePanel.svelte +93 -0
- package/dist/ui/Panel/CollapsiblePanel.svelte.d.ts +14 -0
- package/dist/ui/Panel/index.d.ts +1 -0
- package/dist/ui/Panel/index.js +1 -0
- package/dist/ui/Placeholder/Placeholder.docs.svelte +49 -0
- package/dist/ui/Placeholder/Placeholder.docs.svelte.d.ts +26 -0
- package/dist/ui/Placeholder/Placeholder.svelte +99 -0
- package/dist/ui/Placeholder/Placeholder.svelte.d.ts +21 -0
- package/dist/ui/Placeholder/index.d.ts +1 -0
- package/dist/ui/Placeholder/index.js +1 -0
- package/dist/ui/Radio/Radio.docs.svelte +67 -0
- package/dist/ui/Radio/Radio.docs.svelte.d.ts +27 -0
- package/dist/ui/Radio/Radio.svelte +165 -0
- package/dist/ui/Radio/Radio.svelte.d.ts +22 -0
- package/dist/ui/Radio/RadioGroup.docs.svelte +70 -0
- package/dist/ui/Radio/RadioGroup.docs.svelte.d.ts +27 -0
- package/dist/ui/Radio/RadioGroup.svelte +98 -0
- package/dist/ui/Radio/RadioGroup.svelte.d.ts +27 -0
- package/dist/ui/Radio/index.d.ts +2 -0
- package/dist/ui/Radio/index.js +2 -0
- package/dist/ui/SegmentControl/SegmentControl.docs.svelte +54 -0
- package/dist/ui/SegmentControl/SegmentControl.docs.svelte.d.ts +25 -0
- package/dist/ui/SegmentControl/SegmentControl.svelte +120 -0
- package/dist/ui/SegmentControl/SegmentControl.svelte.d.ts +18 -0
- package/dist/ui/SegmentControl/index.d.ts +1 -0
- package/dist/ui/SegmentControl/index.js +1 -0
- package/dist/ui/Stack/Stack.docs.svelte +63 -0
- package/dist/ui/Stack/Stack.docs.svelte.d.ts +26 -0
- package/dist/ui/Stack/Stack.svelte +45 -0
- package/dist/ui/Stack/Stack.svelte.d.ts +19 -0
- package/dist/ui/Stack/index.d.ts +1 -0
- package/dist/ui/Stack/index.js +1 -0
- package/dist/ui/Table/Body.svelte +17 -0
- package/dist/ui/Table/Body.svelte.d.ts +11 -0
- package/dist/ui/Table/Caption.svelte +17 -0
- package/dist/ui/Table/Caption.svelte.d.ts +11 -0
- package/dist/ui/Table/Cell.svelte +24 -0
- package/dist/ui/Table/Cell.svelte.d.ts +15 -0
- package/dist/ui/Table/Foot.svelte +17 -0
- package/dist/ui/Table/Foot.svelte.d.ts +11 -0
- package/dist/ui/Table/Head.svelte +17 -0
- package/dist/ui/Table/Head.svelte.d.ts +11 -0
- package/dist/ui/Table/Header.svelte +27 -0
- package/dist/ui/Table/Header.svelte.d.ts +17 -0
- package/dist/ui/Table/Row.svelte +19 -0
- package/dist/ui/Table/Row.svelte.d.ts +13 -0
- package/dist/ui/Table/Table.docs.svelte +197 -0
- package/dist/ui/Table/Table.docs.svelte.d.ts +28 -0
- package/dist/ui/Table/Table.svelte +140 -0
- package/dist/ui/Table/Table.svelte.d.ts +27 -0
- package/dist/ui/Table/index.js +10 -0
- package/dist/ui/css/colors.css +377 -0
- package/dist/ui/css/global.css +10 -0
- package/dist/ui/index.d.ts +12 -0
- package/dist/ui/index.js +12 -0
- package/dist/virtual-sdocs.d.ts +20 -0
- package/dist/vite-plugin.d.ts +18 -0
- package/dist/vite-plugin.js +206 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.js +2 -0
- package/package.json +76 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { parseProps } from './docgen.js';
|
|
3
|
+
const VIRTUAL_MODULE_ID = 'virtual:sdocs';
|
|
4
|
+
const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID;
|
|
5
|
+
/**
|
|
6
|
+
* Extract export order from a .docs.svelte file
|
|
7
|
+
* Returns array of exported names in order
|
|
8
|
+
*/
|
|
9
|
+
function extractExportOrder(source) {
|
|
10
|
+
// Match: export { Name1, Name2, Name3 }
|
|
11
|
+
const exportMatch = source.match(/export\s*\{([^}]+)\}/);
|
|
12
|
+
if (exportMatch) {
|
|
13
|
+
return exportMatch[1]
|
|
14
|
+
.split(',')
|
|
15
|
+
.map(s => s.trim())
|
|
16
|
+
.filter(s => s && s !== 'meta');
|
|
17
|
+
}
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Extract snippet source code from a .docs.svelte file
|
|
22
|
+
* Returns a map of snippet name -> source code
|
|
23
|
+
*/
|
|
24
|
+
function extractSnippetSources(source) {
|
|
25
|
+
const snippets = {};
|
|
26
|
+
// Match {#snippet Name(args)}...{/snippet} blocks
|
|
27
|
+
// Using a simple approach that handles nested braces
|
|
28
|
+
const snippetRegex = /\{#snippet\s+(\w+)\s*\([^)]*\)\}/g;
|
|
29
|
+
let match;
|
|
30
|
+
while ((match = snippetRegex.exec(source)) !== null) {
|
|
31
|
+
const snippetName = match[1];
|
|
32
|
+
const startIndex = match.index;
|
|
33
|
+
const startTag = match[0];
|
|
34
|
+
const contentStart = startIndex + startTag.length;
|
|
35
|
+
// Find the matching {/snippet} by counting nesting
|
|
36
|
+
let depth = 1;
|
|
37
|
+
let pos = contentStart;
|
|
38
|
+
while (depth > 0 && pos < source.length) {
|
|
39
|
+
const nextOpen = source.indexOf('{#snippet', pos);
|
|
40
|
+
const nextClose = source.indexOf('{/snippet}', pos);
|
|
41
|
+
if (nextClose === -1)
|
|
42
|
+
break;
|
|
43
|
+
if (nextOpen !== -1 && nextOpen < nextClose) {
|
|
44
|
+
depth++;
|
|
45
|
+
pos = nextOpen + 9; // length of '{#snippet'
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
depth--;
|
|
49
|
+
if (depth === 0) {
|
|
50
|
+
// Extract the content between start tag and {/snippet}
|
|
51
|
+
const content = source.slice(contentStart, nextClose).trim();
|
|
52
|
+
snippets[snippetName] = content;
|
|
53
|
+
}
|
|
54
|
+
pos = nextClose + 10; // length of '{/snippet}'
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return snippets;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Vite plugin that extracts prop information from Svelte 5 components
|
|
62
|
+
* and attaches it as __docgen metadata for runtime access.
|
|
63
|
+
* Also extracts snippet source code from doc files.
|
|
64
|
+
* Provides a virtual module for auto-loading doc files.
|
|
65
|
+
*/
|
|
66
|
+
export function sdocsPlugin(options = {}) {
|
|
67
|
+
const docgenCache = new Map();
|
|
68
|
+
const snippetSourceCache = new Map();
|
|
69
|
+
// Normalize include patterns for import.meta.glob in virtual modules.
|
|
70
|
+
// Virtual modules require absolute paths (starting with /) or alias prefixes ($lib/).
|
|
71
|
+
// Convert relative patterns like ./src/** or src/** to /src/**
|
|
72
|
+
const rawPatterns = options.include
|
|
73
|
+
? Array.isArray(options.include)
|
|
74
|
+
? options.include
|
|
75
|
+
: [options.include]
|
|
76
|
+
: ['$lib/**/*.docs.{svelte,svx}'];
|
|
77
|
+
const includePatterns = rawPatterns.map((p) => {
|
|
78
|
+
if (p.startsWith('/') || p.startsWith('$'))
|
|
79
|
+
return p;
|
|
80
|
+
if (p.startsWith('./'))
|
|
81
|
+
return '/' + p.slice(2);
|
|
82
|
+
if (p.startsWith('../'))
|
|
83
|
+
return p; // relative traversal — keep as-is
|
|
84
|
+
return '/' + p;
|
|
85
|
+
});
|
|
86
|
+
// Generate the virtual module code with import.meta.glob
|
|
87
|
+
function generateVirtualModuleCode() {
|
|
88
|
+
const globs = includePatterns
|
|
89
|
+
.map((pattern) => `import.meta.glob('${pattern}', { eager: true })`)
|
|
90
|
+
.join(',\n ');
|
|
91
|
+
if (includePatterns.length === 1) {
|
|
92
|
+
return `export const docs = ${globs};`;
|
|
93
|
+
}
|
|
94
|
+
// Multiple patterns - merge them
|
|
95
|
+
return `const modules = [
|
|
96
|
+
${globs}
|
|
97
|
+
];
|
|
98
|
+
export const docs = Object.assign({}, ...modules);`;
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
name: 'sdocs',
|
|
102
|
+
enforce: 'post', // Run after Svelte plugin compiles to JS
|
|
103
|
+
resolveId(id) {
|
|
104
|
+
if (id === VIRTUAL_MODULE_ID) {
|
|
105
|
+
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
load(id) {
|
|
109
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
110
|
+
return generateVirtualModuleCode();
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
configureServer(devServer) {
|
|
114
|
+
// Watch for new/deleted doc files and trigger full reload
|
|
115
|
+
// This fixes the issue where import.meta.glob doesn't detect new files
|
|
116
|
+
devServer.watcher.on('add', (file) => {
|
|
117
|
+
if (file.includes('.docs.svelte') || file.includes('.docs.svx')) {
|
|
118
|
+
console.log(`[sdocs] New doc file detected: ${file}`);
|
|
119
|
+
// Send full reload to pick up new glob entries
|
|
120
|
+
devServer.ws.send({ type: 'full-reload' });
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
devServer.watcher.on('unlink', (file) => {
|
|
124
|
+
if (file.includes('.docs.svelte') || file.includes('.docs.svx')) {
|
|
125
|
+
console.log(`[sdocs] Doc file removed: ${file}`);
|
|
126
|
+
devServer.ws.send({ type: 'full-reload' });
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
transform(code, id) {
|
|
131
|
+
const isSvelte = id.endsWith('.svelte');
|
|
132
|
+
const isSvx = id.endsWith('.svx');
|
|
133
|
+
if (!isSvelte && !isSvx) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
// Handle doc files - extract snippet source code and export order (both .svelte and .svx)
|
|
137
|
+
if (id.includes('.docs.')) {
|
|
138
|
+
try {
|
|
139
|
+
const source = readFileSync(id, 'utf-8');
|
|
140
|
+
const snippetSources = extractSnippetSources(source);
|
|
141
|
+
const exampleOrder = extractExportOrder(source);
|
|
142
|
+
const hasSnippets = Object.keys(snippetSources).length > 0;
|
|
143
|
+
const hasOrder = exampleOrder.length > 0;
|
|
144
|
+
if (hasSnippets || hasOrder) {
|
|
145
|
+
snippetSourceCache.set(id, snippetSources);
|
|
146
|
+
// Add exports to the compiled module
|
|
147
|
+
let newCode = code;
|
|
148
|
+
if (hasSnippets) {
|
|
149
|
+
newCode += `\nexport const __snippetSources = ${JSON.stringify(snippetSources)};`;
|
|
150
|
+
}
|
|
151
|
+
if (hasOrder) {
|
|
152
|
+
newCode += `\nexport const __exampleOrder = ${JSON.stringify(exampleOrder)};`;
|
|
153
|
+
}
|
|
154
|
+
return { code: newCode + '\n', map: null };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
if (process.env.DEBUG) {
|
|
159
|
+
console.warn(`[sdocs] Failed to extract snippets from ${id}:`, err);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
// Handle regular component files - extract prop docgen (only .svelte, not .svx)
|
|
165
|
+
if (!isSvelte) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
// Skip internal sdocs components - they don't need docgen
|
|
169
|
+
if (id.includes('/internal/') || id.includes('\\internal\\')) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
// Read the original source file to parse props
|
|
174
|
+
const source = readFileSync(id, 'utf-8');
|
|
175
|
+
const docgen = parseProps(source);
|
|
176
|
+
if (docgen.props.length > 0 || docgen.methods.length > 0) {
|
|
177
|
+
docgenCache.set(id, docgen);
|
|
178
|
+
// The Svelte plugin has already compiled to JS
|
|
179
|
+
// Find the default export and attach __docgen to it
|
|
180
|
+
const docgenJson = JSON.stringify(docgen);
|
|
181
|
+
// Look for the component export pattern in compiled Svelte 5 code
|
|
182
|
+
// Pattern: "export default <ComponentName>" (client) or "export default function <Name>" (SSR)
|
|
183
|
+
if (code.includes('export default')) {
|
|
184
|
+
// Match "export default ComponentName" but not "export default function"
|
|
185
|
+
const exportMatch = code.match(/export\s+default\s+(?!function\b)(\w+)/);
|
|
186
|
+
if (exportMatch) {
|
|
187
|
+
const componentName = exportMatch[1];
|
|
188
|
+
// Add docgen assignment before the export
|
|
189
|
+
const modifiedCode = code.replace(new RegExp(`(export\\s+default\\s+)(${componentName})`), `${componentName}.__docgen = ${docgenJson};\n$1$2`);
|
|
190
|
+
return { code: modifiedCode, map: null };
|
|
191
|
+
}
|
|
192
|
+
// For SSR: "export default function ComponentName" - skip docgen injection
|
|
193
|
+
// SSR components are not interactive, docgen is only needed for client
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
catch (err) {
|
|
198
|
+
if (process.env.DEBUG) {
|
|
199
|
+
console.warn(`[sdocs] Failed to parse ${id}:`, err);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
export default sdocsPlugin;
|
package/dist/vite.d.ts
ADDED
package/dist/vite.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sdocs",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"bin": {
|
|
5
|
+
"sdocs": "./bin/sdocs.js"
|
|
6
|
+
},
|
|
7
|
+
"scripts": {
|
|
8
|
+
"dev": "vite dev",
|
|
9
|
+
"build": "vite build && npm run prepack",
|
|
10
|
+
"preview": "vite preview",
|
|
11
|
+
"prepare": "svelte-kit sync || echo ''",
|
|
12
|
+
"prepack": "svelte-kit sync && svelte-package && publint",
|
|
13
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
14
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"bin",
|
|
19
|
+
"!dist/**/*.test.*",
|
|
20
|
+
"!dist/**/*.spec.*"
|
|
21
|
+
],
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"**/*.css"
|
|
24
|
+
],
|
|
25
|
+
"svelte": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"svelte": "./dist/index.js",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./vite": {
|
|
35
|
+
"types": "./dist/vite.d.ts",
|
|
36
|
+
"default": "./dist/vite.js"
|
|
37
|
+
},
|
|
38
|
+
"./virtual": {
|
|
39
|
+
"types": "./dist/virtual-sdocs.d.ts"
|
|
40
|
+
},
|
|
41
|
+
"./Sdocs.svelte": {
|
|
42
|
+
"svelte": "./dist/Sdocs.svelte",
|
|
43
|
+
"default": "./dist/Sdocs.svelte"
|
|
44
|
+
},
|
|
45
|
+
"./ui/css/global.css": "./dist/ui/css/global.css"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"svelte": "^5.0.0",
|
|
49
|
+
"vite": "^6.0.0 || ^7.0.0",
|
|
50
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.0 || ^6.0.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"vite": { "optional": true },
|
|
54
|
+
"@sveltejs/vite-plugin-svelte": { "optional": true }
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@sveltejs/adapter-auto": "^7.0.0",
|
|
58
|
+
"@sveltejs/kit": "^2.50.1",
|
|
59
|
+
"@sveltejs/package": "^2.5.7",
|
|
60
|
+
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
|
61
|
+
"mdsvex": "^0.12.6",
|
|
62
|
+
"publint": "^0.3.17",
|
|
63
|
+
"svelte": "^5.48.2",
|
|
64
|
+
"svelte-check": "^4.3.5",
|
|
65
|
+
"typescript": "^5.9.3",
|
|
66
|
+
"vite": "^7.3.1"
|
|
67
|
+
},
|
|
68
|
+
"keywords": [
|
|
69
|
+
"svelte",
|
|
70
|
+
"documentation",
|
|
71
|
+
"components"
|
|
72
|
+
],
|
|
73
|
+
"dependencies": {
|
|
74
|
+
"lucide-svelte": "^0.563.0"
|
|
75
|
+
}
|
|
76
|
+
}
|