import type { HistoireEmbedPanel } from '@histoire/protocol' import { getEmbedRelativeUrl, validateEmbedPanels } from '@histoire/protocol' /** Formats offered by the shared embed dialog. */ export type EmbedSnippetFormat = 'iframe' | 'javascript' | 'vue' /** Captured target and user-selected presentation, never runtime state. */ export interface EmbedSnippetOptions { /** Absolute source base, independent of current workbench URL. */ bookUrl: string /** Exact captured story ID. */ storyId: string /** Exact variant ID; omission embeds story switcher. */ variantId?: string /** Accessible iframe name. */ title: string /** Enabled optional panels. */ panels: readonly HistoireEmbedPanel[] /** Positive finite outer height in CSS pixels. */ height: number } /** Escape attributes for HTML/Vue output, without changing actual target values. */ function attribute(value: string): string { return value.replace(/[&"<>]/g, character => ({ '&': '&', '"': '"', '<': '<', '>': '>' })[character]!) } /** Safe JavaScript literal inside a module script or Vue SFC. */ function literal(value: unknown): string { return JSON.stringify(value).replace(/` if (format === 'javascript') { return `
` } return ` ` }