export {}; const prosefly = window.__prosefly ??= {}; const proseflyLotus = (prosefly.lotus ??= {}); interface InkeepSettings { defaultView?: string; baseSettings: Record; modalSettings?: Record; searchSettings?: Record; aiChatSettings?: Record; } function parseSettings(value: string | undefined): InkeepSettings | undefined { if (!value) { return undefined; } try { const parsed = JSON.parse(value); if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) { return parsed as InkeepSettings; } } catch { return undefined; } return undefined; } function loadScript(src: string): Promise { if (window.Inkeep) { return Promise.resolve(); } const existing = document.querySelector(`script[data-inkeep-script="${src}"]`); if (existing) { return new Promise((resolve, reject) => { existing.addEventListener('load', () => resolve(), { once: true }); existing.addEventListener('error', () => reject(new Error(`Unable to load Inkeep script: ${src}`)), { once: true }); }); } return new Promise((resolve, reject) => { const script = document.createElement('script'); script.async = true; script.dataset.inkeepScript = src; script.defer = true; script.src = src; script.type = 'module'; script.addEventListener('load', () => resolve(), { once: true }); script.addEventListener('error', () => reject(new Error(`Unable to load Inkeep script: ${src}`)), { once: true }); document.head.append(script); }); } function withLotusColorMode(settings: InkeepSettings): InkeepSettings { return { ...settings, baseSettings: { ...settings.baseSettings, colorMode: settings.baseSettings.colorMode ?? { sync: { target: document.documentElement, attributes: ['data-theme'], isDarkMode: (attributes: Record) => { if (attributes['data-theme'] === 'dark') { return true; } if (attributes['data-theme'] === 'light') { return false; } return window.matchMedia('(prefers-color-scheme: dark)').matches; }, }, }, }, }; } async function initInkeepAssistant(): Promise { const element = document.querySelector('[data-inkeep]'); if (!element) { return; } const settings = parseSettings(element.dataset.inkeepSettings); const scriptUrl = element.dataset.inkeepScriptUrl; if (!settings || !scriptUrl) { return; } await loadScript(scriptUrl); if (!window.Inkeep) { return; } window.Inkeep.ModalSearchAndChat(withLotusColorMode(settings)); } if (!proseflyLotus.inkeepAssistantReady) { proseflyLotus.inkeepAssistantReady = true; proseflyLotus.initInkeepAssistant = initInkeepAssistant; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { void proseflyLotus.initInkeepAssistant?.(); }, { once: true }); } else { void proseflyLotus.initInkeepAssistant?.(); } }