ok-canvas-export 1.0.4 → 1.0.6
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/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +166 -0
- package/dist/index.d.ts +166 -9
- package/dist/index.js +1 -7
- package/dist/index.js.map +1 -1
- package/package.json +12 -5
- package/dist/calculateDimensions.d.ts +0 -47
- package/dist/calculateDimensions.d.ts.map +0 -1
- package/dist/calculateDimensions.js +0 -184
- package/dist/calculateDimensions.js.map +0 -1
- package/dist/exportDiagram.d.ts +0 -23
- package/dist/exportDiagram.d.ts.map +0 -1
- package/dist/exportDiagram.js +0 -141
- package/dist/exportDiagram.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/renderHighQuality.d.ts +0 -5
- package/dist/renderHighQuality.d.ts.map +0 -1
- package/dist/renderHighQuality.js +0 -46
- package/dist/renderHighQuality.js.map +0 -1
- package/dist/types.d.ts +0 -39
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/useDiagramExport.d.ts +0 -18
- package/dist/useDiagramExport.d.ts.map +0 -1
- package/dist/useDiagramExport.js +0 -40
- package/dist/useDiagramExport.js.map +0 -1
- package/dist/utils/download.d.ts +0 -13
- package/dist/utils/download.d.ts.map +0 -1
- package/dist/utils/download.js +0 -60
- package/dist/utils/download.js.map +0 -1
- package/dist/utils/serializer.d.ts +0 -23
- package/dist/utils/serializer.d.ts.map +0 -1
- package/dist/utils/serializer.js +0 -115
- package/dist/utils/serializer.js.map +0 -1
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
const TABLE_WIDTH = 280;
|
|
2
|
-
const TABLE_PADDING = 40;
|
|
3
|
-
/**
|
|
4
|
-
* Calculates dimensions based on diagram data.
|
|
5
|
-
*
|
|
6
|
-
* This function is kept compatible with the original API and tests.
|
|
7
|
-
*
|
|
8
|
-
* It calculates the total diagram size from the table coordinates,
|
|
9
|
-
* assuming the table width is 280px plus the configured padding.
|
|
10
|
-
*/
|
|
11
|
-
export const calculateDimensions = (diagramData, getTableHeight, margin = 100) => {
|
|
12
|
-
if (!diagramData?.tables?.length) {
|
|
13
|
-
return {
|
|
14
|
-
width: 100 + margin * 2,
|
|
15
|
-
height: 100 + margin * 2,
|
|
16
|
-
x: -margin,
|
|
17
|
-
y: -margin,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
const minX = Math.min(...diagramData.tables.map((table) => table.x));
|
|
21
|
-
const minY = Math.min(...diagramData.tables.map((table) => table.y));
|
|
22
|
-
const maxX = Math.max(...diagramData.tables.map((table) => table.x + TABLE_WIDTH + TABLE_PADDING));
|
|
23
|
-
const maxY = Math.max(...diagramData.tables.map((table) => table.y +
|
|
24
|
-
getTableHeight(table.fields) +
|
|
25
|
-
TABLE_PADDING));
|
|
26
|
-
/*
|
|
27
|
-
* Keep the original expected behavior:
|
|
28
|
-
*
|
|
29
|
-
* width = maxX - minX
|
|
30
|
-
* height = maxY - minY
|
|
31
|
-
*
|
|
32
|
-
* with margin added on both sides.
|
|
33
|
-
*/
|
|
34
|
-
return {
|
|
35
|
-
x: minX - margin,
|
|
36
|
-
y: minY - margin,
|
|
37
|
-
width: Math.max(100, maxX - minX + margin * 2),
|
|
38
|
-
height: Math.max(100, maxY - minY + margin * 2),
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Calculates the visible bounds of an SVG's graphical content.
|
|
43
|
-
*
|
|
44
|
-
* This function is intended for generic SVG exports.
|
|
45
|
-
*
|
|
46
|
-
* It does NOT rely on:
|
|
47
|
-
*
|
|
48
|
-
* - width
|
|
49
|
-
* - height
|
|
50
|
-
* - viewport
|
|
51
|
-
* - scroll container
|
|
52
|
-
*
|
|
53
|
-
* Instead, it attempts to determine the real graphical bounds.
|
|
54
|
-
*/
|
|
55
|
-
export const getSvgContentBounds = (svg) => {
|
|
56
|
-
const elements = Array.from(svg.querySelectorAll('g, path, rect, circle, ellipse, line, polyline, polygon, text, use, image'));
|
|
57
|
-
let minX = Infinity;
|
|
58
|
-
let minY = Infinity;
|
|
59
|
-
let maxX = -Infinity;
|
|
60
|
-
let maxY = -Infinity;
|
|
61
|
-
const updateBounds = (x, y, width, height) => {
|
|
62
|
-
if (!Number.isFinite(x) ||
|
|
63
|
-
!Number.isFinite(y) ||
|
|
64
|
-
!Number.isFinite(width) ||
|
|
65
|
-
!Number.isFinite(height)) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (width < 0 || height < 0) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
minX = Math.min(minX, x);
|
|
72
|
-
minY = Math.min(minY, y);
|
|
73
|
-
maxX = Math.max(maxX, x + width);
|
|
74
|
-
maxY = Math.max(maxY, y + height);
|
|
75
|
-
};
|
|
76
|
-
for (const element of elements) {
|
|
77
|
-
/*
|
|
78
|
-
* Ignore the artificial canvas background.
|
|
79
|
-
*/
|
|
80
|
-
if (element.matches('[data-export-bg="canvas"]') ||
|
|
81
|
-
element.closest('[data-export-bg="canvas"]')) {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
try {
|
|
85
|
-
const bbox = element.getBBox();
|
|
86
|
-
updateBounds(bbox.x, bbox.y, bbox.width, bbox.height);
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
/*
|
|
90
|
-
* getBBox() can fail in environments where the SVG
|
|
91
|
-
* has not been rendered yet.
|
|
92
|
-
*/
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (!Number.isFinite(minX) ||
|
|
96
|
-
!Number.isFinite(minY) ||
|
|
97
|
-
!Number.isFinite(maxX) ||
|
|
98
|
-
!Number.isFinite(maxY)) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
x: minX,
|
|
103
|
-
y: minY,
|
|
104
|
-
width: Math.max(1, maxX - minX),
|
|
105
|
-
height: Math.max(1, maxY - minY),
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Calculates the dimensions that should be used for a real SVG export.
|
|
110
|
-
*
|
|
111
|
-
* The content bounds are preferred.
|
|
112
|
-
*
|
|
113
|
-
* The returned x/y values are important because the content does not
|
|
114
|
-
* necessarily start at 0,0.
|
|
115
|
-
*/
|
|
116
|
-
export const calculateSvgDimensions = (svg, margin = 100) => {
|
|
117
|
-
const bounds = getSvgContentBounds(svg);
|
|
118
|
-
if (bounds) {
|
|
119
|
-
return {
|
|
120
|
-
x: bounds.x - margin,
|
|
121
|
-
y: bounds.y - margin,
|
|
122
|
-
width: bounds.width + margin * 2,
|
|
123
|
-
height: bounds.height + margin * 2,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
/*
|
|
127
|
-
* Fallback to the SVG viewBox.
|
|
128
|
-
*/
|
|
129
|
-
const viewBox = svg.viewBox?.baseVal;
|
|
130
|
-
if (viewBox &&
|
|
131
|
-
Number.isFinite(viewBox.width) &&
|
|
132
|
-
Number.isFinite(viewBox.height) &&
|
|
133
|
-
viewBox.width > 0 &&
|
|
134
|
-
viewBox.height > 0) {
|
|
135
|
-
return {
|
|
136
|
-
x: viewBox.x - margin,
|
|
137
|
-
y: viewBox.y - margin,
|
|
138
|
-
width: viewBox.width + margin * 2,
|
|
139
|
-
height: viewBox.height + margin * 2,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
/*
|
|
143
|
-
* Final fallback to width/height attributes.
|
|
144
|
-
*/
|
|
145
|
-
const width = Number(svg.getAttribute('width')) ||
|
|
146
|
-
svg.clientWidth ||
|
|
147
|
-
1;
|
|
148
|
-
const height = Number(svg.getAttribute('height')) ||
|
|
149
|
-
svg.clientHeight ||
|
|
150
|
-
1;
|
|
151
|
-
return {
|
|
152
|
-
x: -margin,
|
|
153
|
-
y: -margin,
|
|
154
|
-
width: width + margin * 2,
|
|
155
|
-
height: height + margin * 2,
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Calculates dimensions based on an SVG element and its scroll container.
|
|
160
|
-
*
|
|
161
|
-
* Kept for backwards compatibility.
|
|
162
|
-
*/
|
|
163
|
-
export const getScrollDimensions = (svg) => {
|
|
164
|
-
const scrollContainer = svg.parentElement ||
|
|
165
|
-
svg.closest('.overflow-auto') ||
|
|
166
|
-
svg.closest('.overflow-scroll');
|
|
167
|
-
let width = Number(svg.getAttribute('width')) ||
|
|
168
|
-
svg.clientWidth ||
|
|
169
|
-
1;
|
|
170
|
-
let height = Number(svg.getAttribute('height')) ||
|
|
171
|
-
svg.clientHeight ||
|
|
172
|
-
1;
|
|
173
|
-
if (scrollContainer) {
|
|
174
|
-
width = Math.max(width, scrollContainer.scrollWidth);
|
|
175
|
-
height = Math.max(height, scrollContainer.scrollHeight);
|
|
176
|
-
}
|
|
177
|
-
return {
|
|
178
|
-
x: 0,
|
|
179
|
-
y: 0,
|
|
180
|
-
width,
|
|
181
|
-
height,
|
|
182
|
-
};
|
|
183
|
-
};
|
|
184
|
-
//# sourceMappingURL=calculateDimensions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculateDimensions.js","sourceRoot":"","sources":["../src/calculateDimensions.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,aAAa,GAAG,EAAE,CAAC;AASzB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,WAA2C,EAC3C,cAA8B,EAC9B,SAAiB,GAAG,EACR,EAAE;IACd,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QACjC,OAAO;YACL,KAAK,EAAE,GAAG,GAAG,MAAM,GAAG,CAAC;YACvB,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,CAAC;YACxB,CAAC,EAAE,CAAC,MAAM;YACV,CAAC,EAAE,CAAC,MAAM;SACX,CA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CAAC;IAEJ,IAAI,eAAe,EAAE,CAAC;QACpB,KAAK,GAAG,IAAI,CAAC,GAAG,CACd,KAAK,EACL,eAAe,CAAC,WAAW,CAC5B,CAAC;QAEF,MAAM,GAAG,IAAI,CAAC,GAAG,CACf,MAAM,EACN,eAAe,CAAC,YAAY,CAC7B,CAAC;IACJ,CAAC;IAED,OAAO;QACL,CAAC,EAAE,CAAC;QACJ,CAAC,EAAE,CAAC;QACJ,KAAK;QACL,MAAM;KACP,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/exportDiagram.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { ExportOptions, DiagramData, GetTableHeight } from './types';
|
|
2
|
-
export interface ExportDiagramParams {
|
|
3
|
-
svgRef: React.RefObject<SVGSVGElement>;
|
|
4
|
-
diagramData: DiagramData;
|
|
5
|
-
getTableHeight: GetTableHeight;
|
|
6
|
-
projectName?: string;
|
|
7
|
-
setExportAllTables?: (value: boolean) => void;
|
|
8
|
-
showToast?: (message: string, type?: string) => void;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Exports the complete SVG diagram regardless of the
|
|
12
|
-
* visible viewport.
|
|
13
|
-
*
|
|
14
|
-
* The export process is:
|
|
15
|
-
*
|
|
16
|
-
* 1. Render all diagram content.
|
|
17
|
-
* 2. Calculate the real SVG content bounds.
|
|
18
|
-
* 3. Create an independent SVG clone.
|
|
19
|
-
* 4. Set a viewBox covering the complete content.
|
|
20
|
-
* 5. Convert the SVG to PNG when requested.
|
|
21
|
-
*/
|
|
22
|
-
export declare const exportDiagram: (params: ExportDiagramParams, options?: ExportOptions) => Promise<void>;
|
|
23
|
-
//# sourceMappingURL=exportDiagram.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exportDiagram.d.ts","sourceRoot":"","sources":["../src/exportDiagram.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,cAAc,EACf,MAAM,SAAS,CAAC;AAsBjB,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACvC,WAAW,EAAE,WAAW,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9C,SAAS,CAAC,EAAE,CACV,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,KACV,IAAI,CAAC;CACX;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACxB,QAAQ,mBAAmB,EAC3B,UAAS,aAAkB,KAC1B,OAAO,CAAC,IAAI,CAoPd,CAAC"}
|
package/dist/exportDiagram.js
DELETED
|
@@ -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":"","sources":["../src/exportDiagram.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,sBAAsB,GACvB,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;AAc1B;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAChC,MAA2B,EAC3B,UAAyB,EAAE,EACZ,EAAE;IACjB,MAAM,EACJ,MAAM,EACN,WAAW,EACX,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,SAAS,GACV,GAAG,MAAM,CAAC;IAEX,MAAM,EACJ,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,OAAO,EACpB,KAAK,GAAG,CAAC,EACT,MAAM,GAAG,GAAG,EACZ,QAAQ,EACR,UAAU,GACX,GAAG,OAAO,CAAC;IAEZ,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,UAAU,EAAE,CAAC;YACX,IAAI,EAAE,OAAO;YACb,OAAO,EAAE,6BAA6B;SACvC,CAAC,CAAC;QAEH,OAAO;IACT,CAAC;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C,CAAC;QAEH,SAAS,EAAE,CACT,uBAAuB,EACvB,OAAO,CACR,CAAC;IACJ,CAAC;YAAS,CAAC;QACT;;WAEG;QACH,kBAAkB,EAAE,CAClB,KAAK,CACN,CAAC;QAEF;;WAEG;QACH,IAAI,SAAS,EAAE,CAAC;YACd,GAAG,CAAC,eAAe,CACjB,SAAS,CACV,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAE5B,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
|
package/dist/types.d.ts.map
DELETED
|
@@ -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
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"}
|
package/dist/useDiagramExport.js
DELETED
|
@@ -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"}
|
package/dist/utils/download.d.ts
DELETED
|
@@ -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"}
|
package/dist/utils/download.js
DELETED
|
@@ -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,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