mviz 1.6.7 → 1.7.0-pre.0
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/dist/cli.js +15 -4
- package/dist/core/fragment.d.ts +28 -0
- package/dist/core/fragment.js +658 -0
- package/dist/core/linter.js +89 -70
- package/dist/core/serializer.d.ts +3 -1
- package/dist/core/serializer.js +3 -2
- package/dist/layout/dispatcher.d.ts +7 -2
- package/dist/layout/dispatcher.js +12 -16
- package/dist/layout/markdown-parser.js +6 -0
- package/dist/layout/parser-types.d.ts +7 -0
- package/dist/layout/parser.d.ts +2 -2
- package/dist/layout/parser.js +12 -6
- package/dist/layout/renderer.d.ts +3 -0
- package/dist/layout/renderer.js +33 -10
- package/dist/layout/templates.d.ts +2 -2
- package/dist/layout/templates.js +74 -35
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -110,6 +110,8 @@ async function main() {
|
|
|
110
110
|
console.log(' --lint, -l Validate input without generating output');
|
|
111
111
|
console.log(' --theme, -t <file> Load custom theme from YAML file');
|
|
112
112
|
console.log(' --allow-errors Continue generating output even with lint errors');
|
|
113
|
+
console.log(' --embed Strip page chrome (red bar, title, theme toggle) for embedding');
|
|
114
|
+
console.log(' --fragment Emit an HTML fragment (no DOCTYPE/html/head/body); implies --embed');
|
|
113
115
|
console.log(' --help, -h Show this help message');
|
|
114
116
|
console.log('');
|
|
115
117
|
console.log('Examples:');
|
|
@@ -123,9 +125,16 @@ async function main() {
|
|
|
123
125
|
// Parse flags
|
|
124
126
|
const lintOnly = args.includes('--lint') || args.includes('-l');
|
|
125
127
|
const allowErrors = args.includes('--allow-errors');
|
|
128
|
+
const fragmentFlag = args.includes('--fragment');
|
|
129
|
+
// Fragment mode implies embed — no chrome inside a fragment.
|
|
130
|
+
const embedFlag = fragmentFlag || args.includes('--embed');
|
|
126
131
|
const { themeFile, remainingArgs: afterTheme } = parseThemeFlag(args);
|
|
127
132
|
const { outputFile, remainingArgs } = parseOutputFlag(afterTheme);
|
|
128
|
-
const filteredArgs = remainingArgs.filter((a) => a !== '--lint' &&
|
|
133
|
+
const filteredArgs = remainingArgs.filter((a) => a !== '--lint' &&
|
|
134
|
+
a !== '-l' &&
|
|
135
|
+
a !== '--allow-errors' &&
|
|
136
|
+
a !== '--embed' &&
|
|
137
|
+
a !== '--fragment');
|
|
129
138
|
// Load custom theme if specified
|
|
130
139
|
let customTheme;
|
|
131
140
|
if (themeFile) {
|
|
@@ -168,6 +177,8 @@ async function main() {
|
|
|
168
177
|
console.error(' --lint, -l Validate input without generating output');
|
|
169
178
|
console.error(' --theme, -t <file> Load custom theme from YAML file');
|
|
170
179
|
console.error(' --allow-errors Continue generating output even with lint errors');
|
|
180
|
+
console.error(' --embed Strip page chrome (red bar, title, theme toggle) for embedding');
|
|
181
|
+
console.error(' --fragment Emit an HTML fragment (no DOCTYPE/html/head/body); implies --embed');
|
|
171
182
|
console.error(' --help, -h Show this help message');
|
|
172
183
|
process.exit(1);
|
|
173
184
|
}
|
|
@@ -182,11 +193,11 @@ async function main() {
|
|
|
182
193
|
// JSON input - lint then generate
|
|
183
194
|
const spec = JSON.parse(trimmed);
|
|
184
195
|
lintSpec(spec, lintMode);
|
|
185
|
-
html = await generateChartAsync(spec);
|
|
196
|
+
html = await generateChartAsync(spec, { fragment: fragmentFlag });
|
|
186
197
|
}
|
|
187
198
|
else if (trimmed.startsWith('---') || trimmed.includes('```')) {
|
|
188
199
|
// Markdown input - parser handles linting internally (async for mermaid)
|
|
189
|
-
const result = await parseMarkdownToDashboardAsync(input, 'light', baseDir, false, false, customTheme, lintMode);
|
|
200
|
+
const result = await parseMarkdownToDashboardAsync(input, 'light', baseDir, false, false, customTheme, lintMode, embedFlag, fragmentFlag);
|
|
190
201
|
html = result.html;
|
|
191
202
|
errors = result.errors;
|
|
192
203
|
}
|
|
@@ -194,7 +205,7 @@ async function main() {
|
|
|
194
205
|
// Try JSON anyway - lint then generate
|
|
195
206
|
const spec = JSON.parse(trimmed);
|
|
196
207
|
lintSpec(spec, lintMode);
|
|
197
|
-
html = await generateChartAsync(spec);
|
|
208
|
+
html = await generateChartAsync(spec, { fragment: fragmentFlag });
|
|
198
209
|
}
|
|
199
210
|
// Check for errors (unless --allow-errors is set)
|
|
200
211
|
if (errors.length > 0 && !allowErrors) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fragment mode (issue #247)
|
|
3
|
+
*
|
|
4
|
+
* Convert a full mviz HTML document into a self-contained HTML fragment with
|
|
5
|
+
* no `<!DOCTYPE>`, `<html>`, `<head>`, or `<body>` wrappers. The fragment is
|
|
6
|
+
* suitable for embedding inside hosts that forbid document wrappers — most
|
|
7
|
+
* notably claude.ai's `visualize:show_widget` tool, which renders inline
|
|
8
|
+
* HTML/SVG widgets in the chat conversation.
|
|
9
|
+
*
|
|
10
|
+
* Both `wrapHtml` (single-chart standalone) and `generateDashboardHtml`
|
|
11
|
+
* (markdown dashboard) emit a fixed document structure:
|
|
12
|
+
*
|
|
13
|
+
* <!DOCTYPE html><html …><head>…</head><body …>…</body></html>
|
|
14
|
+
*
|
|
15
|
+
* `toFragment` strips the wrapper tags and concatenates the `<head>` and
|
|
16
|
+
* `<body>` contents at the top level. The order is preserved so external
|
|
17
|
+
* `<script src=…>` tags still load before the inline `<script>` that uses
|
|
18
|
+
* the global. The `<body class="theme-…">` class is dropped — hosts provide
|
|
19
|
+
* their own theme context.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Strip document wrappers from an mviz HTML document, returning a fragment.
|
|
23
|
+
*
|
|
24
|
+
* Idempotent: if the input doesn't have the wrappers (already a fragment),
|
|
25
|
+
* it's returned unchanged.
|
|
26
|
+
*/
|
|
27
|
+
export declare function toFragment(html: string): string;
|
|
28
|
+
//# sourceMappingURL=fragment.d.ts.map
|