@veluai/velu 0.2.13 → 0.2.15

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 (109) hide show
  1. package/README.md +80 -80
  2. package/dist/cli.js +37 -37
  3. package/package.json +64 -64
  4. package/runtime/velu-ui/base.css +320 -320
  5. package/runtime/velu-ui/components/Accordion.jsx +64 -64
  6. package/runtime/velu-ui/components/ApiClient.jsx +207 -207
  7. package/runtime/velu-ui/components/ApiField.jsx +87 -87
  8. package/runtime/velu-ui/components/ApiPath.jsx +63 -63
  9. package/runtime/velu-ui/components/ApiReferencePage.jsx +384 -384
  10. package/runtime/velu-ui/components/ApiSamples.jsx +36 -36
  11. package/runtime/velu-ui/components/ApiSidebar.jsx +122 -122
  12. package/runtime/velu-ui/components/AskBar.jsx +71 -71
  13. package/runtime/velu-ui/components/Callout.jsx +114 -114
  14. package/runtime/velu-ui/components/Card.jsx +131 -131
  15. package/runtime/velu-ui/components/Chatbot.jsx +885 -885
  16. package/runtime/velu-ui/components/CodeBlock.jsx +375 -375
  17. package/runtime/velu-ui/components/Columns.jsx +56 -56
  18. package/runtime/velu-ui/components/ContextMenu.jsx +298 -273
  19. package/runtime/velu-ui/components/ErrorCard.jsx +138 -138
  20. package/runtime/velu-ui/components/Field.jsx +81 -81
  21. package/runtime/velu-ui/components/Image.jsx +163 -163
  22. package/runtime/velu-ui/components/Logo.jsx +31 -31
  23. package/runtime/velu-ui/components/MethodBadge.jsx +31 -31
  24. package/runtime/velu-ui/components/NavSelect.jsx +108 -108
  25. package/runtime/velu-ui/components/NotFound.jsx +63 -63
  26. package/runtime/velu-ui/components/PageFeedback.jsx +219 -219
  27. package/runtime/velu-ui/components/PageFooter.jsx +145 -145
  28. package/runtime/velu-ui/components/PageHeader.jsx +422 -422
  29. package/runtime/velu-ui/components/PageNav.jsx +77 -77
  30. package/runtime/velu-ui/components/PoweredBy.jsx +51 -51
  31. package/runtime/velu-ui/components/Prompt.jsx +115 -115
  32. package/runtime/velu-ui/components/Search.jsx +460 -460
  33. package/runtime/velu-ui/components/Sidebar.jsx +254 -254
  34. package/runtime/velu-ui/components/SocialLinks.jsx +90 -90
  35. package/runtime/velu-ui/components/Steps.jsx +65 -65
  36. package/runtime/velu-ui/components/ThemeToggle.jsx +48 -48
  37. package/runtime/velu-ui/components/Toc.jsx +537 -537
  38. package/runtime/velu-ui/components/TocBar.jsx +195 -195
  39. package/runtime/velu-ui/components/Tree.jsx +87 -87
  40. package/runtime/velu-ui/components/TryItBar.jsx +102 -102
  41. package/runtime/velu-ui/components/accordion.css +92 -92
  42. package/runtime/velu-ui/components/api-page.css +208 -208
  43. package/runtime/velu-ui/components/api.css +635 -635
  44. package/runtime/velu-ui/components/ask-bar.css +94 -94
  45. package/runtime/velu-ui/components/card.css +105 -105
  46. package/runtime/velu-ui/components/chatbot.css +622 -622
  47. package/runtime/velu-ui/components/code-block.css +263 -263
  48. package/runtime/velu-ui/components/context-menu.css +173 -173
  49. package/runtime/velu-ui/components/docs-layout.css +822 -822
  50. package/runtime/velu-ui/components/field.css +82 -82
  51. package/runtime/velu-ui/components/image.css +237 -237
  52. package/runtime/velu-ui/components/nav-select.css +157 -157
  53. package/runtime/velu-ui/components/not-found.css +94 -94
  54. package/runtime/velu-ui/components/page-feedback.css +241 -241
  55. package/runtime/velu-ui/components/page-footer.css +130 -130
  56. package/runtime/velu-ui/components/page-header.css +558 -558
  57. package/runtime/velu-ui/components/page-nav.css +50 -50
  58. package/runtime/velu-ui/components/powered-by.css +92 -92
  59. package/runtime/velu-ui/components/prompt.css +99 -99
  60. package/runtime/velu-ui/components/search.css +307 -307
  61. package/runtime/velu-ui/components/sidebar.css +205 -205
  62. package/runtime/velu-ui/components/steps.css +77 -77
  63. package/runtime/velu-ui/components/theme-toggle.css +102 -102
  64. package/runtime/velu-ui/components/toc-bar.css +234 -234
  65. package/runtime/velu-ui/components/tree.css +49 -49
  66. package/runtime/velu-ui/index.js +54 -54
  67. package/runtime/velu-ui/lib/api-send.js +92 -92
  68. package/runtime/velu-ui/lib/brand-icons.jsx +103 -103
  69. package/runtime/velu-ui/lib/component-schemas.js +100 -100
  70. package/runtime/velu-ui/lib/copyText.js +64 -64
  71. package/runtime/velu-ui/lib/docs-assistant.js +250 -250
  72. package/runtime/velu-ui/lib/lang-icons.jsx +147 -147
  73. package/runtime/velu-ui/lib/pagefind.js +113 -113
  74. package/runtime/velu-ui/lib/prism-langs.js +957 -957
  75. package/runtime/velu-ui/lib/prism-loader.js +74 -74
  76. package/runtime/velu-ui/lib/resolveIcon.jsx +29 -29
  77. package/runtime/velu-ui/lib/scrollIntoNearestView.js +66 -66
  78. package/runtime/velu-ui/mdx-components.jsx +105 -105
  79. package/runtime/velu-ui/primitives/Cluster.jsx +49 -49
  80. package/runtime/velu-ui/primitives/Stack.jsx +63 -63
  81. package/runtime/velu-ui/primitives/Switcher.jsx +57 -57
  82. package/runtime/velu-ui/primitives/stack.css +3 -3
  83. package/runtime/velu-ui/primitives/switcher.css +25 -25
  84. package/runtime/velu-ui/styles.css +46 -46
  85. package/runtime/velu-ui/tokens.css +4 -4
  86. package/schema/velu.schema.json +423 -423
  87. package/src/lib/extract-mdx-error.js +170 -170
  88. package/src/lib/issues.js +159 -159
  89. package/src/lib/known-components.js +34 -34
  90. package/src/navigation.js +443 -443
  91. package/src/runtime/App.jsx +1669 -1668
  92. package/src/runtime/ErrorBoundary.jsx +54 -54
  93. package/src/runtime/client-entry.jsx +22 -22
  94. package/src/runtime/server-entry.jsx +16 -16
  95. package/src/template.html +48 -48
  96. package/templates/starter/ai-tools/claude-code.mdx +26 -26
  97. package/templates/starter/ai-tools/cursor.mdx +17 -17
  98. package/templates/starter/api-reference/introduction.mdx +43 -43
  99. package/templates/starter/development.mdx +19 -19
  100. package/templates/starter/essentials/code.mdx +29 -29
  101. package/templates/starter/essentials/images.mdx +29 -29
  102. package/templates/starter/essentials/markdown.mdx +25 -25
  103. package/templates/starter/essentials/navigation.mdx +39 -39
  104. package/templates/starter/essentials/settings.mdx +30 -30
  105. package/templates/starter/favicon.svg +6 -6
  106. package/templates/starter/index.mdx +31 -31
  107. package/templates/starter/openapi.json +160 -160
  108. package/templates/starter/quickstart.mdx +31 -31
  109. package/templates/starter/velu.json +41 -41
@@ -1,170 +1,170 @@
1
- // Normalize a thrown error — from a Vite/MDX transform, an SSR render, or a
2
- // React error boundary — into the shared `issue` shape (see ./issues.js).
3
- //
4
- // Isomorphic: no Node `path` import (path handling is string-based) so the
5
- // browser ErrorBoundary can reuse it. The single hard rule is PATH SAFETY:
6
- // never surface an absolute path that isn't under the user's project — those
7
- // are Velu/Vite internals and must be stripped.
8
- import { makeIssue, suggestComponent } from './issues.js';
9
-
10
- // Unwrap a few layers of `err.cause` when the outer message is generic.
11
- function unwrap(err) {
12
- let e = err;
13
- let depth = 0;
14
- while (e && e.cause && depth < 3) {
15
- // Stop if the current layer already carries useful location info.
16
- if (e.loc || e.line || /`[^`]+` to be defined/.test(e.message || '')) break;
17
- e = e.cause;
18
- depth += 1;
19
- }
20
- return e || err;
21
- }
22
-
23
- const toPosix = (p) => String(p).replace(/\\/g, '/');
24
-
25
- // Make an absolute path project-relative; return null for anything that isn't
26
- // inside the project (i.e. our internals — never shown).
27
- function rel(rawPath, projectDir) {
28
- if (!rawPath) return null;
29
- let p = toPosix(rawPath).replace(/[?#].*$/, ''); // drop ?query / #hash
30
- const root = projectDir ? toPosix(projectDir).replace(/\/+$/, '') : '';
31
- if (root && p.toLowerCase().startsWith(root.toLowerCase())) {
32
- return p.slice(root.length).replace(/^\/+/, '');
33
- }
34
- // Already-relative, project-owned path (no drive letter, no node_modules).
35
- if (!/^([a-zA-Z]:\/|\/)/.test(p) && !/node_modules/.test(p)) return p;
36
- return null; // absolute and outside the project → hide it
37
- }
38
-
39
- // Strip any absolute path (and node_modules refs) from a message so internals
40
- // never leak; collapse them to "…".
41
- function cleanMessage(msg) {
42
- if (!msg) return '';
43
- return String(msg)
44
- .replace(/([a-zA-Z]:\\|\/)[^\s'"()]+/g, (m) => (/node_modules|[\\/]vite[\\/]|@veluai|velu-cli|velu-ui/.test(m) ? '…' : m))
45
- .trim();
46
- }
47
-
48
- // Pull a "(line:col)" / "(line:col-line:col)" position out of a message tail.
49
- // MDX/vfile errors often carry the location only in the message string, with
50
- // err.line/err.loc left undefined.
51
- function parseLocFromMessage(msg) {
52
- const m = /\((\d+):(\d+)(?:-\d+:\d+)?\)\s*$/.exec(String(msg || ''));
53
- return m ? { line: Number(m[1]), column: Number(m[2]) } : null;
54
- }
55
-
56
- // Drop a trailing "(line:col-…)" from a message once we've surfaced it as a
57
- // separate location, so it isn't shown twice.
58
- function stripLocSuffix(msg) {
59
- return String(msg || '').replace(/\s*\(\d+:\d+(?:-\d+:\d+)?\)\s*$/, '').trim();
60
- }
61
-
62
- // Phrases that mark a genuine MDX *parse* error (vs a runtime throw).
63
- const MDX_SYNTAX_RE =
64
- /closing tag|unexpected closing|could not parse (?:expression|import|export)|unexpected character|unexpected end of|expected a closing|expected the closing|unexpected `|in expression|misnested|before name/i;
65
-
66
- // Keep a code frame only when it clearly belongs to a project file; otherwise
67
- // drop it (an internal frame would leak paths and confuse the author).
68
- function safeFrame(frame, fileIsProjectOwned) {
69
- if (!frame || !fileIsProjectOwned) return null;
70
- const text = String(frame);
71
- if (/node_modules|[\\/]vite[\\/]|@veluai[\\/]/.test(text)) return null;
72
- return text;
73
- }
74
-
75
- export function extractMdxError(rawErr, opts = {}) {
76
- const { projectDir = '', knownComponents = [], file: fileHint = null } = opts;
77
-
78
- // A component (runtime) or the compile-time prop check attaches a ready-made
79
- // issue. Trust it directly — it already carries plain-language wording, a
80
- // suggestion, and (from the compile-time check) a file:line. Walk the cause
81
- // chain since Vite/rollup may re-wrap the thrown error.
82
- let tagged = null;
83
- for (let e = rawErr, depth = 0; e && depth < 6; e = e.cause, depth += 1) {
84
- if (e.veluIssue) {
85
- tagged = e.veluIssue;
86
- break;
87
- }
88
- }
89
- if (tagged) return makeIssue({ ...tagged, file: tagged.file || fileHint });
90
-
91
- const err = unwrap(rawErr) || {};
92
- const message = err.message || String(rawErr || '');
93
-
94
- // 1) Unknown component (MDX render: `_missingMdxReference`). The message
95
- // tail carries the spot: "...referenced in your code at `7:1-7:54` in
96
- // `<abs path>`" — pull the line/column + file out so the author knows
97
- // exactly where to look (path relative-ized for safety).
98
- const missing = /Expected component `([^`]+)` to be defined/.exec(message);
99
- if (missing) {
100
- const name = missing[1];
101
- const at = /referenced in your code at `(\d+):(\d+)/.exec(message);
102
- const inFile = /\bin `([^`]+)`/.exec(message);
103
- const relFile = inFile ? rel(inFile[1], projectDir) : null;
104
- return makeIssue({
105
- category: 'unknown-component',
106
- file: relFile || fileHint,
107
- line: at ? Number(at[1]) : null,
108
- column: at ? Number(at[2]) : null,
109
- title: `<${name}> is not a built-in component`,
110
- detail: '',
111
- hint: 'Components are built in — check the spelling and capitalization (you don’t import them).',
112
- suggestion: suggestComponent(name, knownComponents),
113
- });
114
- }
115
-
116
- // 2) Compile error carrying a source location (Vite plugin / MDX / vfile).
117
- // The location may be on err.loc, on err.line/column, or only inside the
118
- // message text — try all three.
119
- const loc =
120
- err.loc ||
121
- (err.line != null ? { line: err.line, column: err.column, file: err.file } : null) ||
122
- parseLocFromMessage(err.reason || message);
123
- const rawFile = err.id || (loc && loc.file) || err.file || null;
124
- const file = rel(rawFile, projectDir) || fileHint;
125
- const fileIsProjectOwned = Boolean(file) && rel(rawFile, projectDir) != null;
126
- const frame = safeFrame(err.frame, fileIsProjectOwned || Boolean(fileHint));
127
- const detail = cleanMessage(stripLocSuffix(err.reason || message));
128
- const isSyntax = MDX_SYNTAX_RE.test(message);
129
- const isFrontmatter =
130
- err.source === 'remark-frontmatter' ||
131
- /\byaml\b|frontmatter/i.test(message) ||
132
- (loc && loc.line === 1 && /unexpected|expected/i.test(message) && /---/.test(message));
133
-
134
- if (loc || isSyntax || (frame && fileIsProjectOwned)) {
135
- return makeIssue({
136
- category: isFrontmatter ? 'frontmatter' : 'mdx-syntax',
137
- file,
138
- line: loc ? loc.line : null,
139
- column: loc ? loc.column : null,
140
- frame,
141
- title: detail || (isFrontmatter ? 'Invalid frontmatter' : 'MDX syntax error'),
142
- detail: '',
143
- hint: isFrontmatter
144
- ? 'Check the YAML between the --- markers — indentation, quotes, and colons.'
145
- : 'Make sure every <Component> has a matching closing tag and that { } braces are balanced.',
146
- });
147
- }
148
-
149
- // 3) Bad prop / option that threw at render time.
150
- if (/\.map is not a function|is not iterable|reading '|undefined \(reading/i.test(message)) {
151
- return makeIssue({
152
- category: 'invalid-props',
153
- file,
154
- title: 'A component received an invalid value',
155
- detail,
156
- hint: 'Check the props/options you passed to a component on this page.',
157
- });
158
- }
159
-
160
- // 4) Anything else that threw while rendering.
161
- return makeIssue({
162
- category: 'render-crash',
163
- file,
164
- title: 'This page failed to render',
165
- detail,
166
- hint: 'Set VELU_DEBUG=1 for the full stack trace.',
167
- });
168
- }
169
-
170
- export default extractMdxError;
1
+ // Normalize a thrown error — from a Vite/MDX transform, an SSR render, or a
2
+ // React error boundary — into the shared `issue` shape (see ./issues.js).
3
+ //
4
+ // Isomorphic: no Node `path` import (path handling is string-based) so the
5
+ // browser ErrorBoundary can reuse it. The single hard rule is PATH SAFETY:
6
+ // never surface an absolute path that isn't under the user's project — those
7
+ // are Velu/Vite internals and must be stripped.
8
+ import { makeIssue, suggestComponent } from './issues.js';
9
+
10
+ // Unwrap a few layers of `err.cause` when the outer message is generic.
11
+ function unwrap(err) {
12
+ let e = err;
13
+ let depth = 0;
14
+ while (e && e.cause && depth < 3) {
15
+ // Stop if the current layer already carries useful location info.
16
+ if (e.loc || e.line || /`[^`]+` to be defined/.test(e.message || '')) break;
17
+ e = e.cause;
18
+ depth += 1;
19
+ }
20
+ return e || err;
21
+ }
22
+
23
+ const toPosix = (p) => String(p).replace(/\\/g, '/');
24
+
25
+ // Make an absolute path project-relative; return null for anything that isn't
26
+ // inside the project (i.e. our internals — never shown).
27
+ function rel(rawPath, projectDir) {
28
+ if (!rawPath) return null;
29
+ let p = toPosix(rawPath).replace(/[?#].*$/, ''); // drop ?query / #hash
30
+ const root = projectDir ? toPosix(projectDir).replace(/\/+$/, '') : '';
31
+ if (root && p.toLowerCase().startsWith(root.toLowerCase())) {
32
+ return p.slice(root.length).replace(/^\/+/, '');
33
+ }
34
+ // Already-relative, project-owned path (no drive letter, no node_modules).
35
+ if (!/^([a-zA-Z]:\/|\/)/.test(p) && !/node_modules/.test(p)) return p;
36
+ return null; // absolute and outside the project → hide it
37
+ }
38
+
39
+ // Strip any absolute path (and node_modules refs) from a message so internals
40
+ // never leak; collapse them to "…".
41
+ function cleanMessage(msg) {
42
+ if (!msg) return '';
43
+ return String(msg)
44
+ .replace(/([a-zA-Z]:\\|\/)[^\s'"()]+/g, (m) => (/node_modules|[\\/]vite[\\/]|@veluai|velu-cli|velu-ui/.test(m) ? '…' : m))
45
+ .trim();
46
+ }
47
+
48
+ // Pull a "(line:col)" / "(line:col-line:col)" position out of a message tail.
49
+ // MDX/vfile errors often carry the location only in the message string, with
50
+ // err.line/err.loc left undefined.
51
+ function parseLocFromMessage(msg) {
52
+ const m = /\((\d+):(\d+)(?:-\d+:\d+)?\)\s*$/.exec(String(msg || ''));
53
+ return m ? { line: Number(m[1]), column: Number(m[2]) } : null;
54
+ }
55
+
56
+ // Drop a trailing "(line:col-…)" from a message once we've surfaced it as a
57
+ // separate location, so it isn't shown twice.
58
+ function stripLocSuffix(msg) {
59
+ return String(msg || '').replace(/\s*\(\d+:\d+(?:-\d+:\d+)?\)\s*$/, '').trim();
60
+ }
61
+
62
+ // Phrases that mark a genuine MDX *parse* error (vs a runtime throw).
63
+ const MDX_SYNTAX_RE =
64
+ /closing tag|unexpected closing|could not parse (?:expression|import|export)|unexpected character|unexpected end of|expected a closing|expected the closing|unexpected `|in expression|misnested|before name/i;
65
+
66
+ // Keep a code frame only when it clearly belongs to a project file; otherwise
67
+ // drop it (an internal frame would leak paths and confuse the author).
68
+ function safeFrame(frame, fileIsProjectOwned) {
69
+ if (!frame || !fileIsProjectOwned) return null;
70
+ const text = String(frame);
71
+ if (/node_modules|[\\/]vite[\\/]|@veluai[\\/]/.test(text)) return null;
72
+ return text;
73
+ }
74
+
75
+ export function extractMdxError(rawErr, opts = {}) {
76
+ const { projectDir = '', knownComponents = [], file: fileHint = null } = opts;
77
+
78
+ // A component (runtime) or the compile-time prop check attaches a ready-made
79
+ // issue. Trust it directly — it already carries plain-language wording, a
80
+ // suggestion, and (from the compile-time check) a file:line. Walk the cause
81
+ // chain since Vite/rollup may re-wrap the thrown error.
82
+ let tagged = null;
83
+ for (let e = rawErr, depth = 0; e && depth < 6; e = e.cause, depth += 1) {
84
+ if (e.veluIssue) {
85
+ tagged = e.veluIssue;
86
+ break;
87
+ }
88
+ }
89
+ if (tagged) return makeIssue({ ...tagged, file: tagged.file || fileHint });
90
+
91
+ const err = unwrap(rawErr) || {};
92
+ const message = err.message || String(rawErr || '');
93
+
94
+ // 1) Unknown component (MDX render: `_missingMdxReference`). The message
95
+ // tail carries the spot: "...referenced in your code at `7:1-7:54` in
96
+ // `<abs path>`" — pull the line/column + file out so the author knows
97
+ // exactly where to look (path relative-ized for safety).
98
+ const missing = /Expected component `([^`]+)` to be defined/.exec(message);
99
+ if (missing) {
100
+ const name = missing[1];
101
+ const at = /referenced in your code at `(\d+):(\d+)/.exec(message);
102
+ const inFile = /\bin `([^`]+)`/.exec(message);
103
+ const relFile = inFile ? rel(inFile[1], projectDir) : null;
104
+ return makeIssue({
105
+ category: 'unknown-component',
106
+ file: relFile || fileHint,
107
+ line: at ? Number(at[1]) : null,
108
+ column: at ? Number(at[2]) : null,
109
+ title: `<${name}> is not a built-in component`,
110
+ detail: '',
111
+ hint: 'Components are built in — check the spelling and capitalization (you don’t import them).',
112
+ suggestion: suggestComponent(name, knownComponents),
113
+ });
114
+ }
115
+
116
+ // 2) Compile error carrying a source location (Vite plugin / MDX / vfile).
117
+ // The location may be on err.loc, on err.line/column, or only inside the
118
+ // message text — try all three.
119
+ const loc =
120
+ err.loc ||
121
+ (err.line != null ? { line: err.line, column: err.column, file: err.file } : null) ||
122
+ parseLocFromMessage(err.reason || message);
123
+ const rawFile = err.id || (loc && loc.file) || err.file || null;
124
+ const file = rel(rawFile, projectDir) || fileHint;
125
+ const fileIsProjectOwned = Boolean(file) && rel(rawFile, projectDir) != null;
126
+ const frame = safeFrame(err.frame, fileIsProjectOwned || Boolean(fileHint));
127
+ const detail = cleanMessage(stripLocSuffix(err.reason || message));
128
+ const isSyntax = MDX_SYNTAX_RE.test(message);
129
+ const isFrontmatter =
130
+ err.source === 'remark-frontmatter' ||
131
+ /\byaml\b|frontmatter/i.test(message) ||
132
+ (loc && loc.line === 1 && /unexpected|expected/i.test(message) && /---/.test(message));
133
+
134
+ if (loc || isSyntax || (frame && fileIsProjectOwned)) {
135
+ return makeIssue({
136
+ category: isFrontmatter ? 'frontmatter' : 'mdx-syntax',
137
+ file,
138
+ line: loc ? loc.line : null,
139
+ column: loc ? loc.column : null,
140
+ frame,
141
+ title: detail || (isFrontmatter ? 'Invalid frontmatter' : 'MDX syntax error'),
142
+ detail: '',
143
+ hint: isFrontmatter
144
+ ? 'Check the YAML between the --- markers — indentation, quotes, and colons.'
145
+ : 'Make sure every <Component> has a matching closing tag and that { } braces are balanced.',
146
+ });
147
+ }
148
+
149
+ // 3) Bad prop / option that threw at render time.
150
+ if (/\.map is not a function|is not iterable|reading '|undefined \(reading/i.test(message)) {
151
+ return makeIssue({
152
+ category: 'invalid-props',
153
+ file,
154
+ title: 'A component received an invalid value',
155
+ detail,
156
+ hint: 'Check the props/options you passed to a component on this page.',
157
+ });
158
+ }
159
+
160
+ // 4) Anything else that threw while rendering.
161
+ return makeIssue({
162
+ category: 'render-crash',
163
+ file,
164
+ title: 'This page failed to render',
165
+ detail,
166
+ hint: 'Set VELU_DEBUG=1 for the full stack trace.',
167
+ });
168
+ }
169
+
170
+ export default extractMdxError;