diff --git a/src/mount.ts b/src/mount.ts new file mode 100644 index 0000000..4ebdc8a --- /dev/null +++ b/src/mount.ts @@ -0,0 +1,90 @@ +import { h, render } from 'preact'; +import { Widget } from './ui/widget.js'; +import type { WidgetConfig } from './config.js'; + +export type MountMode = 'classic' | 'shadow'; + +export type MountHandle = { + root: HTMLElement; + shadowRoot?: ShadowRoot; +}; + +const ROOT_ID = 'messenzy-root'; +const SHADOW_INNER_ID = 'messenzy-shadow-inner'; +const SHADOW_STYLE_ID = 'messenzy-shadow-style'; + +/** + * Mount the widget into the DOM. + * + * - classic mode: renders Preact directly into the host div in the light DOM. + * The caller is responsible for ensuring CSS is in document.head. + * - shadow mode: attaches an open shadow root, injects CSS inside the shadow + * tree (constructable stylesheets when supported,