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(export): offer a shareable Mimik file with its privacy controls

davbio528622069340
diff --git a/src/core/export/__tests__/options.test.ts b/src/core/export/__tests__/options.test.ts
index aa44974..79b371a 100644
--- a/src/core/export/__tests__/options.test.ts
+++ b/src/core/export/__tests__/options.test.ts
@@ -30,9 +30,22 @@ describe('normaliseExportOptions', () => {
stepDescriptions: DEFAULT_EXPORT_OPTIONS.stepDescriptions,
resolution: DEFAULT_EXPORT_OPTIONS.resolution,
gifQuality: DEFAULT_EXPORT_OPTIONS.gifQuality,
+ bundleStripInputs: DEFAULT_EXPORT_OPTIONS.bundleStripInputs,
+ bundleUrls: DEFAULT_EXPORT_OPTIONS.bundleUrls,
});
});
+ it('rejects an unknown bundle url mode', () => {
+ expect(normaliseExportOptions({ bundleUrls: 'everything' }).bundleUrls).toBe(DEFAULT_EXPORT_OPTIONS.bundleUrls);
+ expect(normaliseExportOptions({ bundleUrls: 'origin' }).bundleUrls).toBe('origin');
+ });
+
+ it('keeps typed text stripped unless it is explicitly turned off', () => {
+ expect(normaliseExportOptions({}).bundleStripInputs).toBe(true);
+ expect(normaliseExportOptions({ bundleStripInputs: 'no' }).bundleStripInputs).toBe(true);
+ expect(normaliseExportOptions({ bundleStripInputs: false }).bundleStripInputs).toBe(false);
+ });
+
it('rejects an unknown gif quality so the encoder never gets bogus dimensions', () => {
expect(normaliseExportOptions({ gifQuality: 'huge' }).gifQuality).toBe(DEFAULT_EXPORT_OPTIONS.gifQuality);
});
diff --git a/src/core/export/options.ts b/src/core/export/options.ts
index 567c3dc..28ddda3 100644
--- a/src/core/export/options.ts
+++ b/src/core/export/options.ts
@@ -1,5 +1,8 @@
+import type { BundleUrlMode } from '@/core/transfer/bundle';
import { localStorage } from '@/lib/browser-api';
+export type { BundleUrlMode };
+
export type ImageScale = 'small' | 'medium' | 'large';
export const IMAGE_SCALE_FACTORS: Record<ImageScale, number> = {
@@ -28,6 +31,8 @@ export const GIF_SPECS: Record<GifQuality, GifSpec> = {
export const GIF_QUALITIES: GifQuality[] = ['low', 'medium', 'high'];
+export const BUNDLE_URL_MODES: BundleUrlMode[] = ['origin', 'path', 'full'];
+
export interface ExportOptions {
cover: boolean;
screenshots: boolean;
@@ -36,6 +41,8 @@ export interface ExportOptions {
stepDescriptions: boolean;
resolution: VideoResolution;
gifQuality: GifQuality;
+ bundleStripInputs: boolean;
+ bundleUrls: BundleUrlMode;
}
export const DEFAULT_EXPORT_OPTIONS: ExportOptions = {
@@ -46,6 +53,8 @@ export const DEFAULT_EXPORT_OPTIONS: ExportOptions = {
stepDescriptions: true,
resolution: '720p',
gifQuality: 'medium',
+ bundleStripInputs: true,
+ bundleUrls: 'path',
};
const bool = (value: unknown, fallback: boolean) => (typeof value === 'boolean' ? value : fallback);
@@ -64,6 +73,10 @@ export function normaliseExportOptions(value: unknown): ExportOptions {
? (raw.resolution as VideoResolution)
: DEFAULT_EXPORT_OPTIONS.resolution,
gifQuality: raw.gifQuality && raw.gifQuality in GIF_SPECS ? raw.gifQuality : DEFAULT_EXPORT_OPTIONS.gifQuality,
+ bundleStripInputs: bool(raw.bundleStripInputs, DEFAULT_EXPORT_OPTIONS.bundleStripInputs),
+ bundleUrls: BUNDLE_URL_MODES.includes(raw.bundleUrls as BundleUrlMode)
+ ? (raw.bundleUrls as BundleUrlMode)
+ : DEFAULT_EXPORT_OPTIONS.bundleUrls,
};
}
diff --git a/src/ui/fullview/ExportPreviewModal.tsx b/src/ui/fullview/ExportPreviewModal.tsx
index 79e6d91..dab2e27 100644
--- a/src/ui/fullview/ExportPreviewModal.tsx
+++ b/src/ui/fullview/ExportPreviewModal.tsx
@@ -1,9 +1,10 @@
-import { FileCode, FileDown, FileImage, FileText, Loader2, Video } from 'lucide-react';
-import { lazy, Suspense, useEffect, useRef, useState } from 'react';
+import { FileCode, FileDown, FileImage, FileText, Loader2, Package, TriangleAlert, Video } from 'lucide-react';
+import { lazy, Suspense, useEffect, useMemo, useRef, useState } from 'react';
import { i18n } from '#imports';
import { downloadBlob, downloadText, safeFilename } from '@/core/export/download';
import { exportGuideAsHTML } from '@/core/export/html-export';
import {
+ BUNDLE_URL_MODES,
DEFAULT_EXPORT_OPTIONS,
type ExportOptions,
GIF_QUALITIES,
@@ -17,6 +18,7 @@ import { paginatePreview, withPreviewStyles } from '@/core/export/preview';
import type { VideoChapter } from '@/core/export/video-export';
import { canExportVideo, STEP_SECONDS } from '@/core/export/video-support';
import type { Guide, Screenshot, Step } from '@/core/guides/types';
+import { BUNDLE_EXTENSION } from '@/core/transfer/schema';
import { Button } from '@/ui/components/ui/button';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/ui/components/ui/dialog';
@@ -33,7 +35,7 @@ interface ExportPreviewModalProps {
screenshots: Map<string, Screenshot>;
}
-type ExportFormat = 'docx' | 'gif' | 'html' | 'markdown' | 'pdf' | 'video';
+type ExportFormat = 'bundle' | 'docx' | 'gif' | 'html' | 'markdown' | 'pdf' | 'video';
type PreviewMode = 'document' | 'video';
export default function ExportPreviewModal({ open, onOpenChange, guide, steps, screenshots }: ExportPreviewModalProps) {
@@ -66,7 +68,19 @@ export default function ExportPreviewModal({ open, onOpenChange, guide, steps, s
}, []);
const videoPending = steps.length > VIDEO_AUTOPLAY_STEP_LIMIT && !videoRequested;
- const { cover, stepDescriptions, resolution } = options;
+ // Stripping the stored value cannot touch the pixels: a screenshot taken while a
+ // field held the text still shows it. Count the screenshots that will actually
+ // ship, not the steps β€” a typed step whose screenshot was deleted shows nothing.
+ const typedStepCount = steps.filter((step) => step.inputValue && screenshots.has(step.id)).length;
+ const { cover, stepDescriptions, resolution, screenshots: withScreenshots, stepUrls, imageScale } = options;
+
+ // Only the settings the HTML actually reflects. The bundle settings cannot
+ // change the preview, and re-encoding every screenshot when one is toggled
+ // blanks the pane for seconds on a long guide.
+ const previewOptions = useMemo<ExportOptions>(
+ () => ({ ...DEFAULT_EXPORT_OPTIONS, cover, screenshots: withScreenshots, stepUrls, imageScale, stepDescriptions }),
+ [cover, withScreenshots, stepUrls, imageScale, stepDescriptions],
+ );
useEffect(() => {
if (!open) setVideoRequested(false);
@@ -77,7 +91,7 @@ export default function ExportPreviewModal({ open, onOpenChange, guide, steps, s
let cancelled = false;
setRendering(true);
const timer = setTimeout(async () => {
- const html = await exportGuideAsHTML(guide, steps, screenshots, options);
+ const html = await exportGuideAsHTML(guide, steps, screenshots, previewOptions);
if (cancelled) return;
setPreview(withPreviewStyles(html));
setRendering(false);
@@ -86,7 +100,7 @@ export default function ExportPreviewModal({ open, onOpenChange, guide, steps, s
cancelled = true;
clearTimeout(timer);
};
- }, [open, mode, guide, steps, screenshots, options]);
+ }, [open, mode, guide, steps, screenshots, previewOptions]);
useEffect(() => {
if (!open || mode !== 'video' || videoPending) return;
@@ -163,6 +177,13 @@ export default function ExportPreviewModal({ open, onOpenChange, guide, steps, s
onProgress: (encoded, frames) => setDownloadProgress(frames > 0 ? encoded / frames : 0),
});
downloadBlob(blob, safeFilename(guide.title, extension));
+ } else if (format === 'bundle') {
+ const { exportGuideAsBundle } = await import('@/core/transfer/bundle');
+ const blob = await exportGuideAsBundle(guide, steps, screenshots, {
+ stripInputValues: options.bundleStripInputs,
+ urls: options.bundleUrls,
+ });
+ downloadBlob(blob, safeFilename(guide.title, BUNDLE_EXTENSION));
} else {
const { exportGuideAsMarkdown } = await import('@/core/export/markdown-export');
const md = await exportGuideAsMarkdown(guide, steps, screenshots);
@@ -199,6 +220,7 @@ export default function ExportPreviewModal({ open, onOpenChange, guide, steps, s
{ key: 'markdown', icon: FileText, label: i18n.t('exportMenu.markdown') },
{ key: 'gif', icon: FileImage, label: i18n.t('exportMenu.gif') },
...(videoSupported ? [{ key: 'video' as const, icon: Video, label: i18n.t('exportMenu.video') }] : []),
+ { key: 'bundle', icon: Package, label: i18n.t('exportMenu.bundle') },
];
return (
@@ -301,6 +323,76 @@ export default function ExportPreviewModal({ open, onOpenChange, guide, steps, s
</div>
</div>
+ <div className="pt-3 border-t border-border">
+ <div className="text-[12px] font-semibold text-foreground">{i18n.t('exportPreview.bundle')}</div>
+ <div className="text-[10px] text-muted-foreground leading-snug mt-0.5">
+ {i18n.t('exportPreview.bundleHint')}
+ </div>
+
+ <div className="flex items-start justify-between gap-3 mt-3">
+ <div>
+ <div className="text-[12px] font-semibold text-foreground">
+ {i18n.t('exportPreview.bundleStripInputs')}
+ </div>
+ <div className="text-[10px] text-muted-foreground leading-snug">
+ {i18n.t('exportPreview.bundleStripInputsHint')}
+ </div>
+ </div>
+ <button
+ type="button"
+ aria-label={i18n.t('exportPreview.bundleStripInputs')}
+ aria-pressed={options.bundleStripInputs}
+ onClick={() => update({ bundleStripInputs: !options.bundleStripInputs })}
+ className={`w-9 h-5 rounded-full transition-colors relative shrink-0 mt-0.5 ${
+ options.bundleStripInputs ? 'bg-accent' : 'bg-border'
+ }`}
+ >
+ <span
+ className={`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white shadow-sm transition-transform ${
+ options.bundleStripInputs ? 'translate-x-4' : 'translate-x-0'
+ }`}
+ />
+ </button>
+ </div>
+
+ <div className="mt-3">
+ <div className="text-[12px] font-semibold text-foreground mb-2">
+ {i18n.t('exportPreview.bundleUrls')}
+ </div>
+ <div className="flex gap-1.5">
+ {BUNDLE_URL_MODES.map((value) => (
+ <button
+ key={value}
+ type="button"
+ onClick={() => update({ bundleUrls: value })}
+ className={`flex-1 px-2 py-1.5 rounded-lg border text-[11px] transition-colors ${
+ options.bundleUrls === value
+ ? 'border-accent text-accent'
+ : 'border-border text-muted-foreground hover:border-accent hover:text-foreground'
+ }`}
+ >
+ {i18n.t(`exportPreview.url_${value}`)}
+ </button>
+ ))}
+ </div>
+ </div>
+
+ <p className="text-[10px] text-muted-foreground leading-snug mt-3">
+ {i18n.t('exportPreview.bundleRedactionNote')}
+ </p>
+
+ {typedStepCount > 0 && (
+ <p className="flex items-start gap-1.5 text-[10px] leading-snug mt-2 text-foreground">
+ <TriangleAlert size={12} className="shrink-0 mt-px text-accent" />
+ <span>
+ {typedStepCount === 1
+ ? i18n.t('exportPreview.bundleTypedWarning', [String(typedStepCount)])
+ : i18n.t('exportPreview.bundleTypedWarningPlural', [String(typedStepCount)])}
+ </span>
+ </p>
+ )}
+ </div>
+
<div className="pt-3 border-t border-border space-y-1.5">
{formats.map(({ key, icon: Icon, label }) => {
const cancellable = exporting === key && (key === 'video' || key === 'gif');