diff --git a/src/utils/chat.ts b/src/utils/chat.ts index 9cc8cdd..8c06726 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -1,8 +1,7 @@ import html2canvas from 'html2canvas'; -// import jsPDF from 'jspdf'; import { ChatInterface } from '@type/chat'; -import { Theme } from '@type/theme'; +// Function to convert HTML to an image using html2canvas export const htmlToImg = async (html: HTMLDivElement) => { const needResize = window.innerWidth >= 1024; const initialWidth = html.style.width; @@ -15,6 +14,7 @@ export const htmlToImg = async (html: HTMLDivElement) => { return dataURL; }; +// Function to download the image as a file export const downloadImg = (imgData: string, fileName: string) => { const link = document.createElement('a'); link.href = imgData; @@ -23,42 +23,7 @@ export const downloadImg = (imgData: string, fileName: string) => { link.remove(); }; -// export const downloadPDF = ( -// imageData: string, -// theme: Theme, -// fileName: string -// ) => { -// const pdf = new jsPDF('p', 'mm'); -// const imageProps = pdf.getImageProperties(imageData); -// const pageHeight = pdf.internal.pageSize.getHeight(); -// const pageWidth = pdf.internal.pageSize.getWidth(); -// const imgHeight = (imageProps.height * pageWidth) / imageProps.width; -// let heightLeft = imgHeight; -// let position = 0; - -// pdf.addImage(imageData, 'PNG', 0, position, pageWidth, imgHeight); -// heightLeft -= pageHeight; - -// while (heightLeft >= 0) { -// position -= pageHeight; -// heightLeft -= pageHeight; -// pdf.addPage(); -// pdf.addImage(imageData, 'PNG', 0, position, pageWidth, imgHeight); -// } - -// if (heightLeft < 0) { -// heightLeft = -heightLeft; -// if (theme === 'dark') { -// pdf.setFillColor(52, 53, 65); -// } else { -// pdf.setFillColor(255, 255, 255); -// } -// pdf.rect(0, pageHeight - heightLeft - 3, pageWidth, heightLeft + 3, 'F'); -// } - -// pdf.save(fileName); -// }; - +// Function to convert a chat object to markdown format export const chatToMarkdown = (chat: ChatInterface) => { let markdown = `# ${chat.title}\n\n`; chat.messages.forEach((message) => { @@ -67,6 +32,7 @@ export const chatToMarkdown = (chat: ChatInterface) => { return markdown; }; +// Function to download the markdown content as a file export const downloadMarkdown = (markdown: string, fileName: string) => { const link = document.createElement('a'); const markdownFile = new Blob([markdown], { type: 'text/markdown' });