ok-canvas-export 1.0.5 → 1.1.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.
@@ -1,141 +0,0 @@
1
- import { calculateSvgDimensions, } from './calculateDimensions';
2
- import { renderHighQuality, } from './renderHighQuality';
3
- import { serializeSvg, createSvgUrl, prepareSvgForExport, } from './utils/serializer';
4
- import { downloadBlob, generateFileName, canvasToBlob, } from './utils/download';
5
- /**
6
- * Exports the complete SVG diagram regardless of the
7
- * visible viewport.
8
- *
9
- * The export process is:
10
- *
11
- * 1. Render all diagram content.
12
- * 2. Calculate the real SVG content bounds.
13
- * 3. Create an independent SVG clone.
14
- * 4. Set a viewBox covering the complete content.
15
- * 5. Convert the SVG to PNG when requested.
16
- */
17
- export const exportDiagram = async (params, options = {}) => {
18
- const { svgRef, diagramData, getTableHeight, projectName, setExportAllTables, showToast, } = params;
19
- const { format = 'png', background = 'white', scale = 2, margin = 100, fileName, onProgress, } = options;
20
- if (!svgRef.current) {
21
- onProgress?.({
22
- type: 'error',
23
- message: 'SVG reference not available',
24
- });
25
- return;
26
- }
27
- let objectUrl = null;
28
- try {
29
- onProgress?.({
30
- type: 'preparing',
31
- });
32
- showToast?.('Preparing export...', 'info');
33
- /*
34
- * Tell the consuming application to render all
35
- * currently virtualized/cullable content.
36
- */
37
- setExportAllTables?.(true);
38
- /*
39
- * Give React time to render the complete diagram.
40
- */
41
- await new Promise((resolve) => {
42
- setTimeout(resolve, 300);
43
- });
44
- onProgress?.({
45
- type: 'rendering',
46
- });
47
- const sourceSvg = svgRef.current;
48
- /*
49
- * IMPORTANT:
50
- *
51
- * Do NOT use calculateDimensions() here.
52
- *
53
- * calculateDimensions() exists for diagram-data based
54
- * compatibility.
55
- *
56
- * For a generic SVG export we need the real SVG bounds.
57
- */
58
- const dimensions = calculateSvgDimensions(sourceSvg, margin);
59
- const { x, y, width, height, } = dimensions;
60
- /*
61
- * Prepare a completely independent SVG clone.
62
- */
63
- const exportSvg = prepareSvgForExport(sourceSvg, width, height, background, margin, x, y);
64
- onProgress?.({
65
- type: 'serializing',
66
- });
67
- /*
68
- * Serialize the prepared SVG.
69
- */
70
- const svgMarkup = serializeSvg(exportSvg);
71
- /*
72
- * SVG export does not require canvas.
73
- */
74
- if (format === 'svg') {
75
- const blob = new Blob([svgMarkup], {
76
- type: 'image/svg+xml;charset=utf-8',
77
- });
78
- const finalFileName = fileName ||
79
- generateFileName(projectName, 'svg');
80
- downloadBlob(blob, finalFileName);
81
- onProgress?.({
82
- type: 'complete',
83
- });
84
- showToast?.('Export completed successfully', 'success');
85
- return;
86
- }
87
- /*
88
- * Create an object URL for the SVG.
89
- */
90
- const image = new Image();
91
- objectUrl = createSvgUrl(svgMarkup);
92
- await new Promise((resolve, reject) => {
93
- image.onload = () => {
94
- resolve();
95
- };
96
- image.onerror = () => {
97
- reject(new Error('Failed to load SVG image'));
98
- };
99
- image.src = objectUrl;
100
- });
101
- /*
102
- * Render the complete SVG into a high-quality canvas.
103
- */
104
- const canvas = await renderHighQuality(image, width, height, scale, background);
105
- onProgress?.({
106
- type: 'downloading',
107
- });
108
- /*
109
- * Convert the canvas to PNG.
110
- */
111
- const blob = await canvasToBlob(canvas);
112
- const finalFileName = fileName ||
113
- generateFileName(projectName, 'png');
114
- downloadBlob(blob, finalFileName);
115
- onProgress?.({
116
- type: 'complete',
117
- });
118
- showToast?.('Export completed successfully', 'success');
119
- }
120
- catch (error) {
121
- console.error('Export error:', error);
122
- onProgress?.({
123
- type: 'error',
124
- message: 'Export failed',
125
- });
126
- showToast?.('Failed to export file', 'error');
127
- }
128
- finally {
129
- /*
130
- * Always restore the normal rendering state.
131
- */
132
- setExportAllTables?.(false);
133
- /*
134
- * Always release the object URL.
135
- */
136
- if (objectUrl) {
137
- URL.revokeObjectURL(objectUrl);
138
- }
139
- }
140
- };
141
- //# sourceMappingURL=exportDiagram.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exportDiagram.js","sourceRoot":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E5B,OAAO,EACL,aAAa,GACd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,aAAa,EACb,YAAY,EACZ,aAAa,EACb,WAAW,EACX,cAAc,GACf,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,gBAAgB,IAAI,OAAO,GAC5B,MAAM,oBAAoB,CAAC"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Renders an SVG image to a high-quality canvas.
3
- */
4
- export declare const renderHighQuality: (image: HTMLImageElement, width: number, height: number, scale?: number, background?: "white" | "transparent") => Promise<HTMLCanvasElement>;
5
- //# sourceMappingURL=renderHighQuality.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderHighQuality.d.ts","sourceRoot":"","sources":["../src/renderHighQuality.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC5B,OAAO,gBAAgB,EACvB,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,QAAO,MAAU,EACjB,aAAY,OAAO,GAAG,aAA6B,KAClD,OAAO,CAAC,iBAAiB,CAuG3B,CAAC"}
@@ -1,46 +0,0 @@
1
- /**
2
- * Renders an SVG image to a high-quality canvas.
3
- */
4
- export const renderHighQuality = async (image, width, height, scale = 2, background = 'transparent') => {
5
- const MAX_CANVAS_SIZE = 16384;
6
- const safeWidth = Math.max(1, width);
7
- const safeHeight = Math.max(1, height);
8
- const safeScale = Math.max(0.1, scale);
9
- const effectiveScale = Math.min(safeScale, MAX_CANVAS_SIZE /
10
- Math.max(safeWidth, safeHeight, 1));
11
- const canvas = document.createElement('canvas');
12
- canvas.width = Math.max(1, Math.floor(safeWidth *
13
- effectiveScale));
14
- canvas.height = Math.max(1, Math.floor(safeHeight *
15
- effectiveScale));
16
- const context = canvas.getContext('2d', {
17
- alpha: background !== 'white',
18
- });
19
- if (!context) {
20
- throw new Error('Unable to create 2D canvas context');
21
- }
22
- context.imageSmoothingEnabled =
23
- true;
24
- context.imageSmoothingQuality =
25
- 'high';
26
- /*
27
- * Background.
28
- */
29
- if (background === 'white') {
30
- context.fillStyle =
31
- '#ffffff';
32
- context.fillRect(0, 0, canvas.width, canvas.height);
33
- }
34
- else {
35
- context.clearRect(0, 0, canvas.width, canvas.height);
36
- }
37
- /*
38
- * The canvas already contains the scaled dimensions,
39
- * so we draw using the original SVG dimensions.
40
- */
41
- context.drawImage(image, 0, 0, safeWidth *
42
- effectiveScale, safeHeight *
43
- effectiveScale);
44
- return canvas;
45
- };
46
- //# sourceMappingURL=renderHighQuality.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"renderHighQuality.js","sourceRoot":"","sources":["../src/renderHighQuality.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,KAAuB,EACvB,KAAa,EACb,MAAc,EACd,QAAgB,CAAC,EACjB,aAAsC,aAAa,EACvB,EAAE;IAC9B,MAAM,eAAe,GAAG,KAAK,CAAC;IAE9B,MAAM,SAAS,GACb,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAErB,MAAM,UAAU,GACd,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAEtB,MAAM,SAAS,GACb,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAEvB,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAC7B,SAAS,EACT,eAAe;QACb,IAAI,CAAC,GAAG,CACN,SAAS,EACT,UAAU,EACV,CAAC,CACF,CACJ,CAAC;IAEF,MAAM,MAAM,GACV,QAAQ,CAAC,aAAa,CACpB,QAAQ,CACT,CAAC;IAEJ,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CACrB,CAAC,EACD,IAAI,CAAC,KAAK,CACR,SAAS;QACP,cAAc,CACjB,CACF,CAAC;IAEF,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CACtB,CAAC,EACD,IAAI,CAAC,KAAK,CACR,UAAU;QACR,cAAc,CACjB,CACF,CAAC;IAEF,MAAM,OAAO,GACX,MAAM,CAAC,UAAU,CACf,IAAI,EACJ;QACE,KAAK,EACH,UAAU,KAAK,OAAO;KACzB,CACF,CAAC;IAEJ,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,oCAAoC,CACrC,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,qBAAqB;QAC3B,IAAI,CAAC;IAEP,OAAO,CAAC,qBAAqB;QAC3B,MAAM,CAAC;IAET;;OAEG;IACH,IACE,UAAU,KAAK,OAAO,EACtB,CAAC;QACD,OAAO,CAAC,SAAS;YACf,SAAS,CAAC;QAEZ,OAAO,CAAC,QAAQ,CACd,CAAC,EACD,CAAC,EACD,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,MAAM,CACd,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,SAAS,CACf,CAAC,EACD,CAAC,EACD,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,MAAM,CACd,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,SAAS,CACf,KAAK,EACL,CAAC,EACD,CAAC,EACD,SAAS;QACP,cAAc,EAChB,UAAU;QACR,cAAc,CACjB,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
package/dist/types.d.ts DELETED
@@ -1,39 +0,0 @@
1
- export interface ExportOptions {
2
- format?: 'png' | 'svg';
3
- background?: 'white' | 'transparent';
4
- scale?: number;
5
- margin?: number;
6
- fileName?: string;
7
- onProgress?: (status: ExportStatus) => void;
8
- }
9
- export interface DiagramData {
10
- tables: Array<{
11
- id: string;
12
- x: number;
13
- y: number;
14
- fields: any[];
15
- }>;
16
- relationships: any[];
17
- }
18
- export type ExportStatus = {
19
- type: 'preparing';
20
- } | {
21
- type: 'rendering';
22
- } | {
23
- type: 'serializing';
24
- } | {
25
- type: 'downloading';
26
- } | {
27
- type: 'complete';
28
- } | {
29
- type: 'error';
30
- message: string;
31
- };
32
- export interface GetTableHeight {
33
- (fields: any[]): number;
34
- }
35
- export interface ExportContext {
36
- isExporting: boolean;
37
- exportDiagram: (options?: ExportOptions) => Promise<void>;
38
- }
39
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAEvB,UAAU,CAAC,EACP,OAAO,GACP,aAAa,CAAC;IAElB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,UAAU,CAAC,EAAE,CACX,MAAM,EAAE,YAAY,KACjB,IAAI,CAAC;CACX;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,KAAK,CAAC;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,MAAM,EAAE,GAAG,EAAE,CAAC;KACf,CAAC,CAAC;IAEH,aAAa,EAAE,GAAG,EAAE,CAAC;CACtB;AAED,MAAM,MAAM,YAAY,GACpB;IACE,IAAI,EAAE,WAAW,CAAC;CACnB,GACD;IACE,IAAI,EAAE,WAAW,CAAC;CACnB,GACD;IACE,IAAI,EAAE,aAAa,CAAC;CACrB,GACD;IACE,IAAI,EAAE,aAAa,CAAC;CACrB,GACD;IACE,IAAI,EAAE,UAAU,CAAC;CAClB,GACD;IACE,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEN,MAAM,WAAW,cAAc;IAC7B,CACE,MAAM,EAAE,GAAG,EAAE,GACZ,MAAM,CAAC;CACX;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,OAAO,CAAC;IAErB,aAAa,EAAE,CACb,OAAO,CAAC,EAAE,aAAa,KACpB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB"}
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,18 +0,0 @@
1
- import type { ExportContext, DiagramData, GetTableHeight } from './types';
2
- export interface UseDiagramExportParams {
3
- svgRef: React.RefObject<SVGSVGElement>;
4
- diagramData?: DiagramData | null;
5
- getTableHeight?: GetTableHeight;
6
- projectName?: string;
7
- }
8
- /**
9
- * Hook that provides SVG diagram export functionality.
10
- *
11
- * The exporter automatically calculates the real SVG content bounds,
12
- * so diagramData is optional for generic SVG usage.
13
- */
14
- export declare const useDiagramExport: ({ svgRef, diagramData, getTableHeight, projectName, }: UseDiagramExportParams) => ExportContext & {
15
- exportAllTables: boolean;
16
- setExportAllTables: (value: boolean) => void;
17
- };
18
- //# sourceMappingURL=useDiagramExport.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDiagramExport.d.ts","sourceRoot":"","sources":["../src/useDiagramExport.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EACX,cAAc,EACf,MAAM,SAAS,CAAC;AAMjB,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAEvC,WAAW,CAAC,EACR,WAAW,GACX,IAAI,CAAC;IAET,cAAc,CAAC,EACb,cAAc,CAAC;IAEjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,uDAK9B,sBAAsB,KAAG,aAAa,GAAG;IAC1C,eAAe,EAAE,OAAO,CAAC;IACzB,kBAAkB,EAAE,CAClB,KAAK,EAAE,OAAO,KACX,IAAI,CAAC;CAqDX,CAAC"}
@@ -1,40 +0,0 @@
1
- import { useState, useCallback, } from 'react';
2
- import { exportDiagram, } from './exportDiagram';
3
- /**
4
- * Hook that provides SVG diagram export functionality.
5
- *
6
- * The exporter automatically calculates the real SVG content bounds,
7
- * so diagramData is optional for generic SVG usage.
8
- */
9
- export const useDiagramExport = ({ svgRef, diagramData, getTableHeight, projectName, }) => {
10
- const [isExporting, setIsExporting,] = useState(false);
11
- const [exportAllTables, setExportAllTables,] = useState(false);
12
- const handleExport = useCallback(async (options = {}) => {
13
- setIsExporting(true);
14
- try {
15
- await exportDiagram({
16
- svgRef,
17
- diagramData,
18
- getTableHeight,
19
- projectName,
20
- setExportAllTables,
21
- }, options);
22
- }
23
- finally {
24
- setIsExporting(false);
25
- setExportAllTables(false);
26
- }
27
- }, [
28
- svgRef,
29
- diagramData,
30
- getTableHeight,
31
- projectName,
32
- ]);
33
- return {
34
- isExporting,
35
- exportDiagram: handleExport,
36
- exportAllTables,
37
- setExportAllTables,
38
- };
39
- };
40
- //# sourceMappingURL=useDiagramExport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDiagramExport.js","sourceRoot":"","sources":["../src/useDiagramExport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,GACZ,MAAM,OAAO,CAAC;AASf,OAAO,EACL,aAAa,GACd,MAAM,iBAAiB,CAAC;AAezB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,MAAM,EACN,WAAW,EACX,cAAc,EACd,WAAW,GACY,EAKvB,EAAE;IACF,MAAM,CACJ,WAAW,EACX,cAAc,EACf,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEpB,MAAM,CACJ,eAAe,EACf,kBAAkB,EACnB,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEpB,MAAM,YAAY,GAChB,WAAW,CACT,KAAK,EACH,UAAyB,EAAE,EAC3B,EAAE;QACF,cAAc,CAAC,IAAI,CAAC,CAAC;QAErB,IAAI,CAAC;YACH,MAAM,aAAa,CACjB;gBACE,MAAM;gBACN,WAAW;gBACX,cAAc;gBACd,WAAW;gBACX,kBAAkB;aACnB,EACD,OAAO,CACR,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,cAAc,CAAC,KAAK,CAAC,CAAC;YAEtB,kBAAkB,CAChB,KAAK,CACN,CAAC;QACJ,CAAC;IACH,CAAC,EACD;QACE,MAAM;QACN,WAAW;QACX,cAAc;QACd,WAAW;KACZ,CACF,CAAC;IAEJ,OAAO;QACL,WAAW;QACX,aAAa,EACX,YAAY;QACd,eAAe;QACf,kBAAkB;KACnB,CAAC;AACJ,CAAC,CAAC"}
@@ -1,13 +0,0 @@
1
- /**
2
- * Downloads a Blob as a file.
3
- */
4
- export declare const downloadBlob: (blob: Blob, fileName: string) => void;
5
- /**
6
- * Generates a safe filename.
7
- */
8
- export declare const generateFileName: (projectName: string | undefined, format: "png" | "svg") => string;
9
- /**
10
- * Converts a canvas to a PNG Blob.
11
- */
12
- export declare const canvasToBlob: (canvas: HTMLCanvasElement) => Promise<Blob>;
13
- //# sourceMappingURL=download.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/utils/download.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,YAAY,GACvB,MAAM,IAAI,EACV,UAAU,MAAM,KACf,IAqCF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAC3B,aACI,MAAM,GACN,SAAS,EACb,QACI,KAAK,GACL,KAAK,KACR,MAiBF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GACvB,QAAQ,iBAAiB,KACxB,OAAO,CAAC,IAAI,CA2Cd,CAAC"}
@@ -1,60 +0,0 @@
1
- /**
2
- * Downloads a Blob as a file.
3
- */
4
- export const downloadBlob = (blob, fileName) => {
5
- const url = URL.createObjectURL(blob);
6
- const link = document.createElement('a');
7
- link.href = url;
8
- link.download = fileName;
9
- try {
10
- document.body?.appendChild(link);
11
- link.click();
12
- document.body?.removeChild(link);
13
- }
14
- catch {
15
- link.click();
16
- }
17
- /*
18
- * Give the browser a chance to start the download before
19
- * revoking the object URL.
20
- */
21
- setTimeout(() => {
22
- URL.revokeObjectURL(url);
23
- }, 100);
24
- };
25
- /**
26
- * Generates a safe filename.
27
- */
28
- export const generateFileName = (projectName, format) => {
29
- const safeName = (projectName ||
30
- 'diagram')
31
- .replace(/\s+/g, '_')
32
- .toLowerCase()
33
- .replace(/[^a-z0-9_-]/g, '');
34
- return `${safeName}.${format}`;
35
- };
36
- /**
37
- * Converts a canvas to a PNG Blob.
38
- */
39
- export const canvasToBlob = (canvas) => {
40
- return new Promise((resolve, reject) => {
41
- try {
42
- if (typeof canvas.toBlob !==
43
- 'function') {
44
- reject(new Error('Canvas.toBlob is not supported'));
45
- return;
46
- }
47
- canvas.toBlob((blob) => {
48
- if (!blob) {
49
- reject(new Error('Failed to create PNG blob'));
50
- return;
51
- }
52
- resolve(blob);
53
- }, 'image/png');
54
- }
55
- catch (error) {
56
- reject(error);
57
- }
58
- });
59
- };
60
- //# sourceMappingURL=download.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"download.js","sourceRoot":"","sources":["../../src/utils/download.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,IAAU,EACV,QAAgB,EACV,EAAE;IACR,MAAM,GAAG,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,EAAE;gBACF,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,MAAM,CACJ,IAAI,KAAK,CACP,2BAA2B,CAC5B,CACF,CAAC;oBAEF,OAAO;gBACT,CAAC;gBAED,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC,EACD,WAAW,CACZ,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC,CAAC"}
@@ -1,23 +0,0 @@
1
- /**
2
- * Downloads are handled elsewhere.
3
- *
4
- * This file contains SVG serialization and preparation utilities.
5
- */
6
- /**
7
- * Serializes an SVG element to a string.
8
- *
9
- * CSS custom properties are resolved using the current document styles.
10
- */
11
- export declare const serializeSvg: (svg: SVGSVGElement) => string;
12
- /**
13
- * Creates a Blob URL from SVG markup.
14
- */
15
- export declare const createSvgUrl: (svgMarkup: string) => string;
16
- /**
17
- * Creates a clean SVG clone for export.
18
- *
19
- * sourceX/sourceY represent the origin of the exported
20
- * coordinate system.
21
- */
22
- export declare const prepareSvgForExport: (sourceSvg: SVGSVGElement, width: number, height: number, background: "white" | "transparent", margin?: number, sourceX?: number, sourceY?: number) => SVGSVGElement;
23
- //# sourceMappingURL=serializer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../src/utils/serializer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,eAAO,MAAM,YAAY,GACvB,KAAK,aAAa,KACjB,MAwDF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GACvB,WAAW,MAAM,KAChB,MAUF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,WAAW,aAAa,EACxB,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,YAAY,OAAO,GAAG,aAAa,EACnC,SAAQ,MAAU,EAClB,UAAS,MAAU,EACnB,UAAS,MAAU,KAClB,aAuIF,CAAC"}
@@ -1,115 +0,0 @@
1
- /**
2
- * Downloads are handled elsewhere.
3
- *
4
- * This file contains SVG serialization and preparation utilities.
5
- */
6
- /**
7
- * Serializes an SVG element to a string.
8
- *
9
- * CSS custom properties are resolved using the current document styles.
10
- */
11
- export const serializeSvg = (svg) => {
12
- const serializer = new XMLSerializer();
13
- const styles = typeof document !== 'undefined'
14
- ? getComputedStyle(document.documentElement)
15
- : null;
16
- let markup = serializer.serializeToString(svg);
17
- /*
18
- * Resolve CSS custom properties.
19
- */
20
- if (styles) {
21
- markup = markup.replace(/var\(--([^)]+)\)/g, (_match, name) => {
22
- const value = styles
23
- .getPropertyValue(`--${name}`)
24
- ?.trim();
25
- return (value ||
26
- `var(--${name})`);
27
- });
28
- }
29
- /*
30
- * Ensure SVG has the proper namespace.
31
- */
32
- if (!markup.includes('xmlns="http://www.w3.org/2000/svg"')) {
33
- markup = markup.replace('<svg', '<svg xmlns="http://www.w3.org/2000/svg"');
34
- }
35
- return markup;
36
- };
37
- /**
38
- * Creates a Blob URL from SVG markup.
39
- */
40
- export const createSvgUrl = (svgMarkup) => {
41
- return URL.createObjectURL(new Blob([svgMarkup], {
42
- type: 'image/svg+xml;charset=utf-8',
43
- }));
44
- };
45
- /**
46
- * Creates a clean SVG clone for export.
47
- *
48
- * sourceX/sourceY represent the origin of the exported
49
- * coordinate system.
50
- */
51
- export const prepareSvgForExport = (sourceSvg, width, height, background, margin = 0, sourceX = 0, sourceY = 0) => {
52
- const clone = sourceSvg.cloneNode(true);
53
- /*
54
- * Remove viewport/background elements.
55
- */
56
- const bgNodes = clone.querySelectorAll('[data-export-bg="canvas"]');
57
- bgNodes.forEach((node) => {
58
- node.remove();
59
- });
60
- /*
61
- * Set final dimensions.
62
- */
63
- clone.setAttribute('width', String(width));
64
- clone.setAttribute('height', String(height));
65
- /*
66
- * The viewBox is what allows us to export content
67
- * that exists outside the original viewport.
68
- */
69
- clone.setAttribute('viewBox', `${sourceX} ${sourceY} ${width} ${height}`);
70
- /*
71
- * Prevent unexpected aspect-ratio behavior.
72
- */
73
- clone.setAttribute('preserveAspectRatio', 'xMinYMin meet');
74
- /*
75
- * Add explicit background.
76
- */
77
- if (background === 'white') {
78
- const whiteRect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
79
- whiteRect.setAttribute('x', String(sourceX));
80
- whiteRect.setAttribute('y', String(sourceY));
81
- whiteRect.setAttribute('width', String(width));
82
- whiteRect.setAttribute('height', String(height));
83
- whiteRect.setAttribute('fill', '#ffffff');
84
- /*
85
- * Keep background behind the diagram.
86
- */
87
- clone.insertBefore(whiteRect, clone.firstChild);
88
- }
89
- /*
90
- * Backwards compatibility:
91
- *
92
- * Older consumers/tests may call this function without
93
- * sourceX/sourceY and expect the old margin behavior.
94
- *
95
- * In the real export flow sourceX/sourceY are provided,
96
- * so we do NOT modify existing transforms.
97
- */
98
- if (margin > 0 &&
99
- sourceX === 0 &&
100
- sourceY === 0) {
101
- const scaledGroup = clone.querySelector('g[transform*="scale"]');
102
- if (scaledGroup) {
103
- const existingTransform = scaledGroup.getAttribute('transform') || '';
104
- /*
105
- * Preserve the original scale/transform.
106
- *
107
- * We prepend translate instead of replacing
108
- * the transform entirely.
109
- */
110
- scaledGroup.setAttribute('transform', `translate(${margin / 2}, ${margin / 2}) ${existingTransform}`);
111
- }
112
- }
113
- return clone;
114
- };
115
- //# sourceMappingURL=serializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../src/utils/serializer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,GAAkB,EACV,EAAE;IACV,MAAM,UAAU,GACd,IAAI,aAAa,EAAE,CAAC;IAEtB,MAAM,MAAM,GACV,OAAO,QAAQ,KAAK,WAAW;QAC7B,CAAC,CAAC,gBAAgB,CACd,QAAQ,CAAC,eAAe,CACzB;QACH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