When using @axhub/annotation in a standalone web project, use this skill. It only covers runtime integration: the page already has annotation data, and you only need to display markers, the annotation panel, the table of contents, and status controls.
Reference cases
| Host | Usage | File |
|---|---|---|
| React | AnnotationViewer component |
references/react-example.tsx |
| Plain HTML / DOM | browser bundle + window.AxhubAnnotation.createAnnotationViewer |
references/axhub-annotation.global.js + references/html-example.html |
| Data source | AnnotationSourceDocument JSON |
references/annotation-source.json |
Integration prerequisites
- Annotation data uses a single
AnnotationSourceDocument, either statically imported or returned by the host loader. - Annotated elements should preferably have stable attributes, for example
data-annotation-id。 - Modern hosts such as React 18 / Vite can install
@axhub/annotationand use ESM. - For plain HTML, DOM-only, React 17, Vue, Angular, managed injection, or
file://static pages, prefer the standalone browser bundle; the host is not required to install React / ReactDOM / antd.
Entry point selection
- When the user explicitly says React 18, Vite, ESM, or an existing frontend project, use
AnnotationVieweror ESMcreateAnnotationViewer。 - When the user says plain HTML, static HTML, DOM, no build,
file://, or just wants to open the HTML to see the result, you must use the browser bundle, which can be copied from this skill'sreferences/axhub-annotation.global.jsor from the npm package / local build output'sdist/browser/axhub-annotation.global.js. - HTML mode only integrates the runtime provided by the package:
window.AxhubAnnotation.createAnnotationViewer(...)。 - Do not hand-write equivalent UI for markers, floating panels, table of contents, Markdown rendering, or status controls in the host; if the browser bundle is missing, build or copy the bundle first instead of redoing the UI.
React integration
- Mount
AnnotationViewer。 - For multiple pages, pass
options.currentPageId。 - Table of contents
routeinoptions.onDirectoryRouteto let the host switch pages. - For status annotations use
useProtoDevState()to read thecontrolsvalue. - After publishing as HTML with source code, the published output will inject
sourceReference, pointing tosource/manifest.json; the host integration code does not need to generate it.
Plain HTML integration
- Copy the browser bundle from the npm package, local build output, or this skill's
references/axhub-annotation.global.jsto the static assets directory; the npm / local build path isdist/browser/axhub-annotation.global.js。 - Load
<script src="./axhub-annotation.global.js"></script>in the page first; adjust the actual path according to the static assets directory. - Use
window.AxhubAnnotation.createAnnotationViewer()to create the runtime. - Use
getCurrentPageIdto return the current page. - After switching pages, call
viewer.refresh()。 - Status controls can subscribe to
window.__AXHUB_PROTO_DEV__, read values fromgetState(), and update the DOM. - If the page must be opened directly with
file://, avoid relying on cross-file fetch/import; the runtime must still come from the browser bundle.
Data key points
directory.nodesPutfolder/route/markdown/link, no need forlocator。type: "markdown"Table of contents documents can directly writemarkdownbody text.- When the table of contents document needs to be split into
.mdfiles, you can writemarkdownPath, for exampledocs/prd-03-status.md; this is a build-side convention, and the runtime still reads the inlinedmarkdown。 markdownPathis only used for table of contents documents, not for marker annotation nodes.data.nodes[]Put page markers, and there must be alocator。- When markers belong only to certain pages or states, write
pageId。 - For long body text use
hasMarkdown: true+markdownMap[node.id]。 - For status annotations write node
controls; in JSON, only put serializable fields. - When the page has a dialog or overlay, inspect the actual DOM and write the active layer root selector containing the content into
presentation.layerSelectors。 sourceReferenceis not placed in the JSON data source; only describe the source manifest location in the published package, and do not inline source files.
Acceptance
- Start the host preview.
- Confirm that the marker appears on the target element.
- Click the marker and verify that the short annotation or Markdown body is visible.
- Open the directory and verify
route、markdown、link。 - Modify the state control and confirm that React state or plain DOM changes synchronously.
- Check whether the console has import, peer dependency, or locator errors.
Common mistakes
- Do not write functions into JSON controls.
- Do not hand-write annotation UI just to make a static page visible; HTML mode must also use
@axhub/annotation's browser runtime. - Do not jump to Vite/ESM integration first in plain HTML mode; the shortest path is browser bundle +
window.AxhubAnnotation.createAnnotationViewer(...)。 - Do not rely on fragile generated CSS selectors; if you can add
data-annotation-id, add it. - Do not expect
routeto redirect automatically; the host must handle it inonDirectoryRoute.