···50 * Checks if the record is a pub.leaflet.document
51 */
52export function isLeafletDocument(
53- record: unknown
54): record is PubLeafletDocument.Record {
55 if (!record || typeof record !== "object") return false;
56 const r = record as Record<string, unknown>;
···65 * Checks if the record is a site.standard.document
66 */
67export function isStandardDocument(
68- record: unknown
69): record is SiteStandardDocument.Record {
70 if (!record || typeof record !== "object") return false;
71 const r = record as Record<string, unknown>;
···76 * Checks if the record is a pub.leaflet.publication
77 */
78export function isLeafletPublication(
79- record: unknown
80): record is PubLeafletPublication.Record {
81 if (!record || typeof record !== "object") return false;
82 const r = record as Record<string, unknown>;
···91 * Checks if the record is a site.standard.publication
92 */
93export function isStandardPublication(
94- record: unknown
95): record is SiteStandardPublication.Record {
96 if (!record || typeof record !== "object") return false;
97 const r = record as Record<string, unknown>;
···106 | $Typed<PubLeafletThemeColor.Rgba>
107 | $Typed<PubLeafletThemeColor.Rgb>
108 | { $type: string }
109- | undefined
110): { r: number; g: number; b: number } | undefined {
111 if (!color || typeof color !== "object") return undefined;
112 const c = color as Record<string, unknown>;
···124 * Converts a pub.leaflet theme to a site.standard.theme.basic format
125 */
126export function leafletThemeToBasicTheme(
127- theme: PubLeafletPublication.Theme | undefined
128): SiteStandardThemeBasic.Main | undefined {
129 if (!theme) return undefined;
130131 const background = extractRgb(theme.backgroundColor);
132- const accent = extractRgb(theme.accentBackground) || extractRgb(theme.primary);
0133 const accentForeground = extractRgb(theme.accentText);
134135 // If we don't have the required colors, return undefined
···160 * @param uri - Optional document URI, used to extract the rkey for the path field when normalizing pub.leaflet records
161 * @returns A normalized document in site.standard format, or null if invalid/unrecognized
162 */
163-export function normalizeDocument(record: unknown, uri?: string): NormalizedDocument | null {
000164 if (!record || typeof record !== "object") return null;
165166 // Pass through site.standard records directly (theme is already in correct format if present)
···219 * @returns A normalized publication in site.standard format, or null if invalid/unrecognized
220 */
221export function normalizePublication(
222- record: unknown
223): NormalizedPublication | null {
224 if (!record || typeof record !== "object") return null;
225···268 showComments: record.preferences.showComments,
269 showMentions: record.preferences.showMentions,
270 showPrevNext: record.preferences.showPrevNext,
0271 }
272 : undefined;
273···290 * Type guard to check if a normalized document has leaflet content
291 */
292export function hasLeafletContent(
293- doc: NormalizedDocument
294): doc is NormalizedDocument & {
295 content: $Typed<PubLeafletContent.Main>;
296} {
···304 * Gets the pages array from a normalized document, handling both formats
305 */
306export function getDocumentPages(
307- doc: NormalizedDocument
308): PubLeafletContent.Main["pages"] | undefined {
309 if (!doc.content) return undefined;
310
···50 * Checks if the record is a pub.leaflet.document
51 */
52export function isLeafletDocument(
53+ record: unknown,
54): record is PubLeafletDocument.Record {
55 if (!record || typeof record !== "object") return false;
56 const r = record as Record<string, unknown>;
···65 * Checks if the record is a site.standard.document
66 */
67export function isStandardDocument(
68+ record: unknown,
69): record is SiteStandardDocument.Record {
70 if (!record || typeof record !== "object") return false;
71 const r = record as Record<string, unknown>;
···76 * Checks if the record is a pub.leaflet.publication
77 */
78export function isLeafletPublication(
79+ record: unknown,
80): record is PubLeafletPublication.Record {
81 if (!record || typeof record !== "object") return false;
82 const r = record as Record<string, unknown>;
···91 * Checks if the record is a site.standard.publication
92 */
93export function isStandardPublication(
94+ record: unknown,
95): record is SiteStandardPublication.Record {
96 if (!record || typeof record !== "object") return false;
97 const r = record as Record<string, unknown>;
···106 | $Typed<PubLeafletThemeColor.Rgba>
107 | $Typed<PubLeafletThemeColor.Rgb>
108 | { $type: string }
109+ | undefined,
110): { r: number; g: number; b: number } | undefined {
111 if (!color || typeof color !== "object") return undefined;
112 const c = color as Record<string, unknown>;
···124 * Converts a pub.leaflet theme to a site.standard.theme.basic format
125 */
126export function leafletThemeToBasicTheme(
127+ theme: PubLeafletPublication.Theme | undefined,
128): SiteStandardThemeBasic.Main | undefined {
129 if (!theme) return undefined;
130131 const background = extractRgb(theme.backgroundColor);
132+ const accent =
133+ extractRgb(theme.accentBackground) || extractRgb(theme.primary);
134 const accentForeground = extractRgb(theme.accentText);
135136 // If we don't have the required colors, return undefined
···161 * @param uri - Optional document URI, used to extract the rkey for the path field when normalizing pub.leaflet records
162 * @returns A normalized document in site.standard format, or null if invalid/unrecognized
163 */
164+export function normalizeDocument(
165+ record: unknown,
166+ uri?: string,
167+): NormalizedDocument | null {
168 if (!record || typeof record !== "object") return null;
169170 // Pass through site.standard records directly (theme is already in correct format if present)
···223 * @returns A normalized publication in site.standard format, or null if invalid/unrecognized
224 */
225export function normalizePublication(
226+ record: unknown,
227): NormalizedPublication | null {
228 if (!record || typeof record !== "object") return null;
229···272 showComments: record.preferences.showComments,
273 showMentions: record.preferences.showMentions,
274 showPrevNext: record.preferences.showPrevNext,
275+ showRecommends: record.preferences.showRecommends,
276 }
277 : undefined;
278···295 * Type guard to check if a normalized document has leaflet content
296 */
297export function hasLeafletContent(
298+ doc: NormalizedDocument,
299): doc is NormalizedDocument & {
300 content: $Typed<PubLeafletContent.Main>;
301} {
···309 * Gets the pages array from a normalized document, handling both formats
310 */
311export function getDocumentPages(
312+ doc: NormalizedDocument,
313): PubLeafletContent.Main["pages"] | undefined {
314 if (!doc.content) return undefined;
315