UNPKG

wxt

Version:

⚡ Next-gen Web Extension Framework

32 lines (31 loc) 735 B
import { applyPosition, createMountFunctions, mountUi } from "./shared.mjs"; export function createIntegratedUi(ctx, options) { const wrapper = document.createElement(options.tag || "div"); let mounted = void 0; const mount = () => { applyPosition(wrapper, void 0, options); mountUi(wrapper, options); mounted = options.onMount?.(wrapper); }; const remove = () => { options.onRemove?.(mounted); wrapper.replaceChildren(); wrapper.remove(); mounted = void 0; }; const mountFunctions = createMountFunctions( { mount, remove }, options ); ctx.onInvalidated(remove); return { get mounted() { return mounted; }, wrapper, ...mountFunctions }; }