components.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { uiPackageName, uiVersion } from '@/config/site';
  2. export const generateIframeContent = ({
  3. html,
  4. wrapper,
  5. plugins = [],
  6. backgroundColor = '',
  7. }) => {
  8. const pluginsHtml = plugins
  9. .map((plugin) => {
  10. return `<link href="https://cdn.jsdelivr.net/npm/${uiPackageName}@${uiVersion}/dist/css/tabler-${plugin}.min.css" rel="stylesheet"/>`;
  11. })
  12. .join('\n');
  13. html = (
  14. html ||
  15. '<a href="#" class="btn">Button</a><a href="#" class="btn btn-primary">Primary button</a><a href="#" class="btn btn-danger">Danger button</a>'
  16. ).replace(/href="#"/g, 'href="javascript:void(0)"');
  17. const code = `
  18. <!doctype html>
  19. <html>
  20. <head>
  21. <link href="https://cdn.jsdelivr.net/npm/${uiPackageName}@${uiVersion}/dist/css/tabler.min.css" rel="stylesheet"/>
  22. ${pluginsHtml}
  23. </head>
  24. <body class="h-100 p-3 overflow-auto${
  25. backgroundColor ? ` bg-${backgroundColor}` : ''
  26. }">
  27. <div class="d-flex h-100 align-items-center">
  28. <div class="w-100 d-flex flex-column justify-content-center space-x-2">
  29. ${wrapper ? `<div class="${wrapper}">${html}</div>` : html}
  30. </div>
  31. </div>
  32. <script src="https://cdn.jsdelivr.net/npm/${uiPackageName}@${uiVersion}/dist/js/tabler.min.js"></script>
  33. </body>
  34. </html>
  35. `;
  36. return code.replace(/\t+/g, ' ').replace(/\s+/g, ' ');
  37. };