import type { JsonRenderDockRenderer } from '@devframes/json-render/hub' import css from '../.generated/css' import { createJsonRenderDockRenderer } from '../dock-renderer' // The prebuilt renderer module the hub serves at // `__renderers/json-render.mjs` (registered via `jsonRenderUiRenderer()` // from `@devframes/json-render-ui/hub`). Self-contained by design: Vue, the // upstream renderer, the `@antfu/design` component ports, and the compiled // stylesheet all ride inside this one file, so any viewer can import it // natively at runtime with no build step. const STYLE_MARKER = 'data-devframes-json-render' /** * The theme contract: the viewer mirrors a live `dark` class onto the mount * container (or an ancestor in the same tree). Falls back to the page root's * class for hand-rolled hosts that only theme ``. */ function isDarkFor(container: HTMLElement): boolean { if (container.closest('.dark')) return true if (container.closest('.light')) return false return document.documentElement.classList.contains('dark') } const inner = createJsonRenderDockRenderer() /** * The self-styling `'json-render'` dock renderer. It attaches its own shadow * root inside the viewer's container and adopts the compiled stylesheet * there, fully styled in a light-DOM host page and inside a viewer's shadow * root alike, without leaking the reset or any global rule into the page. */ const jsonRenderDockRenderer: JsonRenderDockRenderer = async ({ entry, container, context }) => { const shadow = container.shadowRoot ?? container.attachShadow({ mode: 'open' }) if (!shadow.querySelector(`style[${STYLE_MARKER}]`)) { const style = document.createElement('style') style.setAttribute(STYLE_MARKER, '') // The bundled `.vue` components' own `