Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

feat: redesign HTML export β€” minimal line dividers layout

Luis Ortizc6288a57e8c4
diff --git a/src/core/export/html-export.ts b/src/core/export/html-export.ts
index 829d771..2d188f8 100644
--- a/src/core/export/html-export.ts
+++ b/src/core/export/html-export.ts
@@ -5,13 +5,35 @@ function blobToBase64(blob: Blob): Promise<string> {
const reader = new FileReader();
reader.onload = () => {
const result = reader.result as string;
- resolve(result.split(',')[1]); // strip data:...;base64, prefix
+ resolve(result.split(',')[1]);
};
reader.onerror = reject;
reader.readAsDataURL(blob);
});
}
+function escapeHtml(text: string): string {
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
+}
+
+function extractDomain(steps: Step[]): string {
+ const firstUrl = steps[0]?.url;
+ if (!firstUrl) return '';
+ try {
+ return new URL(firstUrl).hostname.replace(/^www\./, '');
+ } catch {
+ return '';
+ }
+}
+
+function formatDate(timestamp: number): string {
+ return new Date(timestamp).toLocaleDateString('en-US', {
+ month: 'short',
+ day: '2-digit',
+ year: 'numeric',
+ });
+}
+
export async function exportGuideAsHTML(
guide: Guide,
steps: Step[],
@@ -24,39 +46,52 @@ export async function exportGuideAsHTML(
let imgHtml = '';
if (screenshot) {
const b64 = await blobToBase64(screenshot.blob);
- imgHtml = `<img src="data:${screenshot.mimeType};base64,${b64}" alt="Step ${step.index + 1}" style="max-width:100%;border-radius:8px;margin:12px 0;" />`;
+ imgHtml = `<img src="data:${screenshot.mimeType};base64,${b64}" alt="Step ${step.index + 1}" style="max-width:100%;border-radius:8px;box-shadow:0 1px 4px rgba(30,27,75,0.06);margin-top:16px;" />`;
}
+
+ const stepNumber = String(step.index + 1).padStart(2, '0');
+
stepSections.push(`
- <div style="margin-bottom:32px;">
- <div style="display:flex;align-items:center;gap:8px;margin-bottom:8px;">
- <span style="display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:50%;background:#2563eb;color:#fff;font-size:14px;font-weight:bold;">${step.index + 1}</span>
- <p style="margin:0;font-size:16px;">${escapeHtml(step.description)}</p>
+ <div style="border-top:2px solid #C7D2FE;padding-top:24px;margin-bottom:40px;">
+ <div style="display:flex;gap:16px;align-items:flex-start;">
+ <span style="font-size:32px;font-weight:700;color:#C7D2FE;line-height:1;flex-shrink:0;min-width:48px;">${stepNumber}</span>
+ <div style="flex:1;min-width:0;">
+ <p style="margin:0;font-size:16px;line-height:1.6;color:#1E1B4B;">${escapeHtml(step.description)}</p>
+ ${imgHtml}
+ </div>
</div>
- ${imgHtml}
</div>`);
}
+ const domain = extractDomain(steps);
+ const domainHtml = domain ? `<span style="color:#4338CA;">${escapeHtml(domain)}</span>` : '';
+ const metaSeparator = domain ? ' &middot; ' : '';
+
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${escapeHtml(guide.title)}</title>
+ <link rel="preconnect" href="https://fonts.googleapis.com">
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+ <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
<style>
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 800px; margin: 0 auto; padding: 24px; color: #1f2937; }
- h1 { font-size: 24px; margin-bottom: 8px; }
- .meta { font-size: 12px; color: #6b7280; margin-bottom: 24px; }
+ * { margin: 0; padding: 0; box-sizing: border-box; }
+ body { font-family: 'Poppins', sans-serif; max-width: 800px; margin: 0 auto; padding: 48px 24px; color: #1E1B4B; background: #fff; }
</style>
</head>
<body>
- <h1>${escapeHtml(guide.title)}</h1>
- <p class="meta">${steps.length} steps &middot; Created ${new Date(guide.createdAt).toLocaleDateString()}</p>
+ <div style="margin-bottom:48px;">
+ <span style="display:inline-block;background:#4F46E5;color:#fff;font-size:13px;font-weight:600;padding:4px 14px;border-radius:999px;margin-bottom:20px;">${steps.length} step${steps.length === 1 ? '' : 's'}</span>
+ <div style="height:2px;background:linear-gradient(to right,#4F46E5,#C7D2FE,#38BDF8);border-radius:1px;margin-bottom:24px;"></div>
+ <h1 style="font-size:28px;font-weight:700;color:#1E1B4B;line-height:1.3;margin-bottom:20px;">${escapeHtml(guide.title)}</h1>
+ <div style="background:#EEF2FF;border-radius:8px;padding:14px 20px;font-size:14px;color:#4338CA;">
+ Created ${formatDate(guide.createdAt)}${metaSeparator}${domainHtml}
+ </div>
+ </div>
+
${stepSections.join('\n')}
- <footer style="margin-top:48px;padding-top:16px;border-top:1px solid #e5e7eb;font-size:11px;color:#9ca3af;">Generated by Mimik</footer>
</body>
</html>`;
}
-
-function escapeHtml(text: string): string {
- return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
-}
diff --git a/src/core/export/pdf-export.ts b/src/core/export/pdf-export.ts
index d48d13d..425dccc 100644
--- a/src/core/export/pdf-export.ts
+++ b/src/core/export/pdf-export.ts
@@ -11,6 +11,24 @@ function blobToDataUrl(blob: Blob): Promise<string> {
});
}
+function extractDomain(steps: Step[]): string {
+ const firstUrl = steps[0]?.url;
+ if (!firstUrl) return '';
+ try {
+ return new URL(firstUrl).hostname.replace(/^www\./, '');
+ } catch {
+ return '';
+ }
+}
+
+function formatDate(timestamp: number): string {
+ return new Date(timestamp).toLocaleDateString('en-US', {
+ month: 'short',
+ day: '2-digit',
+ year: 'numeric',
+ });
+}
+
export async function exportGuideAsPDF(
guide: Guide,
steps: Step[],
@@ -18,64 +36,129 @@ export async function exportGuideAsPDF(
): Promise<Blob> {
const doc = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' });
const pageWidth = doc.internal.pageSize.getWidth();
- const margin = 15;
+ const pageHeight = doc.internal.pageSize.getHeight();
+ const margin = 20;
const contentWidth = pageWidth - margin * 2;
- let y = margin;
+ const totalPages = 1 + Math.max(1, steps.length);
+
+ let y = pageHeight / 2 - 30;
- doc.setFontSize(20);
+ const badgeText = `${steps.length} Steps`;
+ doc.setFontSize(9);
doc.setFont('helvetica', 'bold');
- doc.text(guide.title, margin, y + 7);
- y += 14;
+ const badgeWidth = doc.getTextWidth(badgeText) + 8;
+ const badgeHeight = 7;
+ const badgeX = margin;
+ doc.setFillColor(79, 70, 229);
+ doc.roundedRect(badgeX, y, badgeWidth, badgeHeight, 2, 2, 'F');
+ doc.setTextColor(255, 255, 255);
+ doc.text(badgeText, badgeX + 4, y + 4.8);
+ y += badgeHeight + 6;
+
+ const gradientY = y;
+ const segmentWidth = contentWidth / 3;
+ doc.setFillColor(139, 92, 246);
+ doc.rect(margin, gradientY, segmentWidth, 1.2, 'F');
+ doc.setFillColor(167, 139, 250);
+ doc.rect(margin + segmentWidth, gradientY, segmentWidth, 1.2, 'F');
+ doc.setFillColor(125, 211, 252);
+ doc.rect(margin + segmentWidth * 2, gradientY, segmentWidth, 1.2, 'F');
+ y += 8;
+
+ doc.setFontSize(22);
+ doc.setFont('helvetica', 'bold');
+ doc.setTextColor(30, 27, 75);
+ const titleLines = doc.splitTextToSize(guide.title, contentWidth);
+ doc.text(titleLines, margin, y);
+ y += titleLines.length * 9 + 10;
+
+ const cardPadding = 6;
+ const domain = extractDomain(steps);
+ const dateStr = formatDate(guide.createdAt);
+
+ let cardHeight = cardPadding * 2 + 10;
+ if (domain) cardHeight += 14;
+
+ doc.setFillColor(238, 242, 255);
+ doc.roundedRect(margin, y, contentWidth, cardHeight, 3, 3, 'F');
+
+ let cardY = y + cardPadding;
+ doc.setFontSize(7);
+ doc.setFont('helvetica', 'bold');
+ doc.setTextColor(107, 114, 128);
+ doc.text('CREATED', margin + cardPadding, cardY + 4);
doc.setFontSize(10);
doc.setFont('helvetica', 'normal');
- doc.setTextColor(107, 114, 128);
- doc.text(`${steps.length} steps β€” Created ${new Date(guide.createdAt).toLocaleDateString()}`, margin, y);
- doc.setTextColor(0, 0, 0);
- y += 10;
-
- for (const step of steps) {
- if (y > doc.internal.pageSize.getHeight() - 60) {
- doc.addPage();
- y = margin;
- }
+ doc.setTextColor(30, 27, 75);
+ doc.text(dateStr, margin + cardPadding, cardY + 10);
+
+ if (domain) {
+ cardY += 14;
+ doc.setFontSize(7);
+ doc.setFont('helvetica', 'bold');
+ doc.setTextColor(107, 114, 128);
+ doc.text('SOURCE', margin + cardPadding, cardY + 4);
+ doc.setFontSize(10);
+ doc.setFont('helvetica', 'normal');
+ doc.setTextColor(79, 70, 229);
+ doc.text(domain, margin + cardPadding, cardY + 10);
+ }
+
+ const stepIndent = 16;
+ const maxImgHeight = 90;
+ const stepSpacing = 6;
+
+ for (let i = 0; i < steps.length; i++) {
+ const step = steps[i];
+ doc.addPage();
+ y = margin;
+
+ doc.setDrawColor(199, 210, 254);
+ doc.setLineWidth(0.3);
+ doc.line(margin, y, margin + contentWidth, y);
+ y += 6;
+ const stepNum = String(step.index + 1).padStart(2, '0');
doc.setFontSize(12);
doc.setFont('helvetica', 'bold');
- doc.text(`${step.index + 1}.`, margin, y + 4);
+ doc.setTextColor(199, 210, 254);
+ doc.text(stepNum, margin, y + 4);
+
+ doc.setFontSize(11);
doc.setFont('helvetica', 'normal');
- const descLines = doc.splitTextToSize(step.description, contentWidth - 10);
- doc.text(descLines, margin + 8, y + 4);
- y += descLines.length * 5 + 4;
+ doc.setTextColor(30, 27, 75);
+ const descWidth = contentWidth - stepIndent;
+ const descLines = doc.splitTextToSize(step.description, descWidth);
+ doc.text(descLines, margin + stepIndent, y + 4);
+ y += descLines.length * 5 + 6;
const screenshot = screenshots.get(step.id);
if (screenshot) {
try {
const dataUrl = await blobToDataUrl(screenshot.blob);
- const imgWidth = contentWidth;
- const imgHeight = (screenshot.height / screenshot.width) * imgWidth;
- const maxImgHeight = 100; // mm β€” cap height to prevent single image filling entire page
- const finalHeight = Math.min(imgHeight, maxImgHeight);
+ const imgWidth = contentWidth - stepIndent;
+ const imgHeight = Math.min((screenshot.height / screenshot.width) * imgWidth, maxImgHeight);
- if (y + finalHeight > doc.internal.pageSize.getHeight() - margin) {
+ if (y + imgHeight > pageHeight - margin) {
doc.addPage();
y = margin;
}
- doc.addImage(dataUrl, 'JPEG', margin, y, imgWidth, finalHeight);
- y += finalHeight + 8;
+ doc.addImage(dataUrl, 'JPEG', margin + stepIndent, y, imgWidth, imgHeight);
+ y += imgHeight + stepSpacing;
} catch (err) {
- logger.warn(' PDF: failed to embed screenshot for step', step.index, err);
- y += 4;
+ logger.warn('PDF: failed to embed screenshot for step', step.index, err);
+ y += stepSpacing;
}
}
- y += 4; // spacing between steps
+ const currentPage = doc.getNumberOfPages();
+ doc.setFontSize(8);
+ doc.setFont('helvetica', 'normal');
+ doc.setTextColor(107, 114, 128);
+ doc.text(`${currentPage - 1} of ${totalPages - 1}`, pageWidth - margin, pageHeight - margin, { align: 'right' });
}
- doc.setFontSize(8);
- doc.setTextColor(156, 163, 175);
- doc.text('Generated by Mimik', margin, doc.internal.pageSize.getHeight() - 8);
-
return doc.output('blob');
}