···2828export type NormalizedDocument = SiteStandardDocument.Record & {
2929 // Keep the original theme for components that need leaflet-specific styling
3030 theme?: PubLeafletPublication.Theme;
3131+ preferences?: SiteStandardPublication.Preferences;
3132};
32333334// Normalized publication type - uses the generated site.standard.publication type
···5051 * Checks if the record is a pub.leaflet.document
5152 */
5253export function isLeafletDocument(
5353- record: unknown
5454+ record: unknown,
5455): record is PubLeafletDocument.Record {
5556 if (!record || typeof record !== "object") return false;
5657 const r = record as Record<string, unknown>;
···6566 * Checks if the record is a site.standard.document
6667 */
6768export function isStandardDocument(
6868- record: unknown
6969+ record: unknown,
6970): record is SiteStandardDocument.Record {
7071 if (!record || typeof record !== "object") return false;
7172 const r = record as Record<string, unknown>;
···7677 * Checks if the record is a pub.leaflet.publication
7778 */
7879export function isLeafletPublication(
7979- record: unknown
8080+ record: unknown,
8081): record is PubLeafletPublication.Record {
8182 if (!record || typeof record !== "object") return false;
8283 const r = record as Record<string, unknown>;
···9192 * Checks if the record is a site.standard.publication
9293 */
9394export function isStandardPublication(
9494- record: unknown
9595+ record: unknown,
9596): record is SiteStandardPublication.Record {
9697 if (!record || typeof record !== "object") return false;
9798 const r = record as Record<string, unknown>;
···106107 | $Typed<PubLeafletThemeColor.Rgba>
107108 | $Typed<PubLeafletThemeColor.Rgb>
108109 | { $type: string }
109109- | undefined
110110+ | undefined,
110111): { r: number; g: number; b: number } | undefined {
111112 if (!color || typeof color !== "object") return undefined;
112113 const c = color as Record<string, unknown>;
···124125 * Converts a pub.leaflet theme to a site.standard.theme.basic format
125126 */
126127export function leafletThemeToBasicTheme(
127127- theme: PubLeafletPublication.Theme | undefined
128128+ theme: PubLeafletPublication.Theme | undefined,
128129): SiteStandardThemeBasic.Main | undefined {
129130 if (!theme) return undefined;
130131131132 const background = extractRgb(theme.backgroundColor);
132132- const accent = extractRgb(theme.accentBackground) || extractRgb(theme.primary);
133133+ const accent =
134134+ extractRgb(theme.accentBackground) || extractRgb(theme.primary);
133135 const accentForeground = extractRgb(theme.accentText);
134136135137 // If we don't have the required colors, return undefined
···160162 * @param uri - Optional document URI, used to extract the rkey for the path field when normalizing pub.leaflet records
161163 * @returns A normalized document in site.standard format, or null if invalid/unrecognized
162164 */
163163-export function normalizeDocument(record: unknown, uri?: string): NormalizedDocument | null {
165165+export function normalizeDocument(
166166+ record: unknown,
167167+ uri?: string,
168168+): NormalizedDocument | null {
164169 if (!record || typeof record !== "object") return null;
165170166171 // Pass through site.standard records directly (theme is already in correct format if present)
167172 if (isStandardDocument(record)) {
173173+ const preferences = record.preferences as
174174+ | SiteStandardPublication.Preferences
175175+ | undefined;
168176 return {
169177 ...record,
170178 theme: record.theme,
179179+ preferences,
171180 } as NormalizedDocument;
172181 }
173182···194203 }
195204 : undefined;
196205206206+ // Extract preferences if present (available after lexicon rebuild)
207207+ const leafletPrefs = (record as Record<string, unknown>)
208208+ .preferences as SiteStandardPublication.Preferences | undefined;
209209+197210 return {
198211 $type: "site.standard.document",
199212 title: record.title,
···206219 bskyPostRef: record.postRef,
207220 content,
208221 theme: record.theme,
222222+ preferences: leafletPrefs
223223+ ? { ...leafletPrefs, $type: "site.standard.publication#preferences" as const }
224224+ : undefined,
209225 };
210226 }
211227···219235 * @returns A normalized publication in site.standard format, or null if invalid/unrecognized
220236 */
221237export function normalizePublication(
222222- record: unknown
238238+ record: unknown,
223239): NormalizedPublication | null {
224240 if (!record || typeof record !== "object") return null;
225241···268284 showComments: record.preferences.showComments,
269285 showMentions: record.preferences.showMentions,
270286 showPrevNext: record.preferences.showPrevNext,
287287+ showRecommends: record.preferences.showRecommends,
271288 }
272289 : undefined;
273290···290307 * Type guard to check if a normalized document has leaflet content
291308 */
292309export function hasLeafletContent(
293293- doc: NormalizedDocument
310310+ doc: NormalizedDocument,
294311): doc is NormalizedDocument & {
295312 content: $Typed<PubLeafletContent.Main>;
296313} {
···304321 * Gets the pages array from a normalized document, handling both formats
305322 */
306323export function getDocumentPages(
307307- doc: NormalizedDocument
324324+ doc: NormalizedDocument,
308325): PubLeafletContent.Main["pages"] | undefined {
309326 if (!doc.content) return undefined;
310327