Mosaic Mosaic 0.9.4

@ssolu/mosaic-devtool

A small browser-side inspector for pages rendered from a [Mosaic](https://github.com/slavasolutions/mosaic) folder. Drop the script in, get a floating button that opens a panel with up to six tabs:

A small browser-side inspector for pages rendered from a Mosaic folder. Drop the script in, get a floating button that opens a panel with up to six tabs:

Zero runtime dependencies. ~12 kB minified IIFE. Shadow-DOM isolated — does not inherit from or leak to your page styles.

Drop-in install

Copy dist/mosaic-devtool.js into your site's public assets, then:

<script type="application/json" id="mosaic-record">…resolved-record JSON…</script>
<!-- optional, only if your adapter exposes the pre-cascade record -->
<script type="application/json" id="mosaic-raw-record">…raw JSON…</script>
<!-- optional, enables the Tree tab -->
<script type="application/json" id="mosaic-tree">
  { "entries": [{ "path": "pages/about.json" }, { "path": "index.json" }],
    "activePath": "pages/about.json" }
</script>
<!-- optional, overrides the default Sites pill row -->
<script type="application/json" id="mosaic-sites">
  [ { "label": "Home", "url": "/" }, { "label": "Blog", "url": "/blog/" } ]
</script>

<script src="/mosaic-devtool.js" defer></script>

The IIFE mounts on DOMContentLoaded. Calling the script twice is fine — it replaces the existing UI.

Production toggle

The devtool mounts unconditionally if its script is loaded. Example sites in this repo load the devtool on every render and let visitors opt out with ?nodebug=1 on the URL:

<script is:inline>
  (function () {
    if (location.search.indexOf('nodebug=1') !== -1) return;
    var s = document.createElement('script');
    s.src = '/_mosaic-devtool/mosaic-devtool.js';
    s.defer = true;
    document.head.appendChild(s);
  })();
</script>

Adapters that prefer an opt-in gate can invert the check (e.g. require ?debug=1) — the IIFE itself is unconditional once it loads.

ESM API

For tests or tooling that wants to call the devtool directly:

import { mount, buildJsonLd } from '@ssolu/mosaic-devtool';
mount(); // attach the UI to document.body
const ld = buildJsonLd(record); // null when @type missing

Development

npm run build --workspace=packages/devtool   # tsc → dist/esm + esbuild → dist/mosaic-devtool.js
npm test --workspace=packages/devtool        # vitest in jsdom

License: Apache-2.0.