| 16 | * Wrap a native GPT-Vis config in standalone HTML. |
| 17 | */ |
| 18 | export function wrapConfigInHTML(config: ChartConfig): string { |
| 19 | // JSON.parse preserves __proto__ as data; escape script terminators and JS line separators. |
| 20 | const serialized = JSON.stringify(JSON.stringify(config)) |
| 21 | .replace(/</g, '\\u003c') |
| 22 | .replace(/\u2028/g, '\\u2028') |
| 23 | .replace(/\u2029/g, '\\u2029'); |
| 24 | |
| 25 | return `<!DOCTYPE html> |
| 26 | <html> |
| 27 | <head> |
| 28 | <meta charset="UTF-8"> |
| 29 | <title>Data Visualization</title> |
| 30 | <script src="https://registry.npmmirror.com/@antv/gpt-vis/1.3.1/files/dist/umd/index.min.js"></script> |
| 31 | <style> |
| 32 | html, body, #container { |
| 33 | margin: 0; |
| 34 | padding: 0; |
| 35 | font-family: Arial, sans-serif; |
| 36 | width: 100%; |
| 37 | height: 100%; |
| 38 | } |
| 39 | </style> |
| 40 | </head> |
| 41 | <body> |
| 42 | <div id="container"></div> |
| 43 | <script> |
| 44 | const gptVis = new GPTVis.GPTVis({ |
| 45 | container: '#container', |
| 46 | }); |
| 47 | |
| 48 | const visConfig = JSON.parse(${serialized}); |
| 49 | |
| 50 | gptVis.render(visConfig); |
| 51 | </script> |
| 52 | </body> |
| 53 | </html>`; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Generate a config matching the selected GPT-Vis chart schema. |