Skip to content

Commit b720032

Browse files
committed
Add SVG compat presets and Export SVG (LaTeX) menu item
1 parent 50cc620 commit b720032

6 files changed

Lines changed: 106 additions & 26 deletions

File tree

src/lib/components/contextMenuBuilders.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,18 @@ function buildCanvasMenu(
415415
console.error('SVG export failed:', e);
416416
}
417417
}
418+
},
419+
{
420+
label: 'Export SVG (LaTeX)',
421+
icon: 'image',
422+
action: async () => {
423+
try {
424+
const svg = await exportToSVG({ compat: 'inkscape' });
425+
downloadSvg(svg, 'pathview-graph-latex.svg');
426+
} catch (e) {
427+
console.error('SVG export (LaTeX) failed:', e);
428+
}
429+
}
418430
}
419431
];
420432

src/lib/export/dom2svg/index.d.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ interface FontConfig {
66
}
77
/** Font mapping: family name → URL string, single config, or array of configs for multiple weights/styles */
88
type FontMapping = Record<string, string | FontConfig | FontConfig[]>;
9+
/** SVG compatibility configuration flags */
10+
interface SvgCompatConfig {
11+
useClipPathForOverflow: boolean;
12+
stripFilters: boolean;
13+
stripBoxShadows: boolean;
14+
stripMaskImage: boolean;
15+
stripTextShadows: boolean;
16+
avoidStyleAttributes: boolean;
17+
stripXmlSpace: boolean;
18+
}
19+
/** SVG compatibility preset */
20+
type SvgCompat = 'full' | 'inkscape' | SvgCompatConfig;
921
/** Options for domToSvg() */
1022
interface DomToSvgOptions {
1123
/** Map of font-family → URL or FontConfig for text-to-path conversion */
@@ -26,6 +38,8 @@ interface DomToSvgOptions {
2638
* with nested CSS transforms (e.g. SvelteFlow, React Flow) where
2739
* the default behaviour would double-apply transforms. */
2840
flattenTransforms?: boolean;
41+
/** SVG compatibility preset or custom config (default: 'full') */
42+
compat?: SvgCompat;
2943
}
3044
/** Internal render context passed through the tree */
3145
interface RenderContext {
@@ -37,6 +51,8 @@ interface RenderContext {
3751
idGenerator: IdGenerator;
3852
/** Options from the caller */
3953
options: DomToSvgOptions;
54+
/** Resolved SVG compatibility config */
55+
compat: SvgCompatConfig;
4056
/** Font cache (available when textToPath is enabled) */
4157
fontCache?: FontCache;
4258
/** Current inherited opacity */
@@ -72,4 +88,4 @@ interface DomToSvgResult {
7288
*/
7389
declare function domToSvg(element: Element, options?: DomToSvgOptions): Promise<DomToSvgResult>;
7490

75-
export { type DomToSvgOptions, type DomToSvgResult, type FontConfig, type FontMapping, domToSvg };
91+
export { type DomToSvgOptions, type DomToSvgResult, type FontConfig, type FontMapping, type SvgCompat, type SvgCompatConfig, domToSvg };

src/lib/export/dom2svg/index.js

Lines changed: 69 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/export/dom2svg/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/export/svg/renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ export async function exportToSVG(options: ExportOptions = {}): Promise<string>
173173
exclude: EXCLUDE_SELECTORS,
174174
flattenTransforms: true,
175175
textToPath: true,
176-
fonts: KATEX_FONTS
176+
fonts: KATEX_FONTS,
177+
compat: opts.compat
177178
});
178179

179180
// Crop SVG to the content area

src/lib/export/svg/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
*/
44

55
import { EXPORT_PADDING } from '$lib/constants/dimensions';
6+
import type { SvgCompat } from '../dom2svg/index.js';
67

78
/** SVG export options */
89
export interface ExportOptions {
910
/** Background style: 'transparent' or 'solid' */
1011
background?: 'transparent' | 'solid';
1112
/** Padding around content in pixels */
1213
padding?: number;
14+
/** SVG compatibility preset (default: 'full') */
15+
compat?: SvgCompat;
1316
}
1417

1518
/** Default export options */
1619
export const DEFAULT_OPTIONS: Required<ExportOptions> = {
1720
background: 'transparent',
18-
padding: EXPORT_PADDING
21+
padding: EXPORT_PADDING,
22+
compat: 'full'
1923
};

0 commit comments

Comments
 (0)