import App from '@/App.vue'; import '@/assets/styles.scss'; import { demoPayload } from '@/components/demo/demo-payload'; import { pinia } from '@/plugins/pinia'; import { version } from '@/plugins/version'; import { i18n } from '@/plugins/vue-i18n'; import { vuetify } from '@/plugins/vuetify'; import { useDownloadStore } from '@/stores/download.store'; import { quit, registerVersion } from '@3cr/sdk-browser'; import { ViewerOptions, ViewerPayload } from '@3cr/viewer-types-ts'; import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; import Notifications from '@kyvg/vue3-notification'; import { App as VueApp, createApp } from 'vue'; const injectedStyleId = '__3cr-viewer-injected-style__'; let app: VueApp | null = null; let mounted: InstanceType | null = null; export async function mountViewer( host: Element | string, sdkVersion: string, load3CrPackage: boolean = true, ): Promise { if (!app) { if (load3CrPackage) await registerVersion(sdkVersion); app = createApp(App); app.component('font-awesome-icon', FontAwesomeIcon); app.use(i18n); app.use(pinia); useDownloadStore().initCrossTab(); app.use(version); app.use(vuetify); app.use(Notifications); mounted = app.mount(host) as InstanceType; } else { throw new Error('Please call `unmountViewer` before registering again'); } } export async function loadViewer( payload: ViewerPayload = demoPayload, options: ViewerOptions = {}, ): Promise { if (mounted) { await mounted.loadViewer(payload, options); } else { throw new Error('Please call `mountViewer` first'); } } export async function loadSession(url: string): Promise { if (mounted) { await mounted.loadSession(url); } else { throw new Error('Please call `mountViewer` first'); } } export async function unmountViewer(): Promise { if (app) { document.getElementById(injectedStyleId)?.remove(); app.unmount(); mounted = null; app = null; try { await quit(); } catch (e) {} } else { throw new Error('Please call `mountViewer` first'); } }