Skip to content

feat(annotations): add external annotation system (Issue #57)#73

Merged
JSv4 merged 1 commit intomainfrom
feature/external-annotations-issue-57
Dec 5, 2025
Merged

feat(annotations): add external annotation system (Issue #57)#73
JSv4 merged 1 commit intomainfrom
feature/external-annotations-issue-57

Conversation

@JSv4
Copy link
Copy Markdown
Owner

@JSv4 JSv4 commented Dec 4, 2025

Summary

Implements External Annotation Storage and Projection System - a parallel annotation system that stores annotations externally as JSON without modifying the source DOCX file.

  • External storage: Annotations stored as JSON, not embedded in DOCX
  • Document binding: SHA256 hash validates annotations against source document
  • Character offset targeting: Precise text targeting with search fallback
  • HTML projection: Annotations rendered as styled spans on converted HTML
  • OpenContracts compatible: Extends existing OpenContractDocExport format

Key Components

Component Purpose
ExternalAnnotationSet Extends OpenContractDocExport with document binding
ExternalAnnotationManager Hash, validation, annotation creation, serialization
ExternalAnnotationProjector Projects annotations onto HTML as styled spans

API Additions

C# / .NET:

  • ExternalAnnotationManager.ComputeDocumentHash()
  • ExternalAnnotationManager.CreateAnnotationSet()
  • ExternalAnnotationManager.CreateAnnotation() / CreateAnnotationFromSearch()
  • ExternalAnnotationManager.Validate()
  • ExternalAnnotationProjector.ProjectAnnotations() / ConvertWithAnnotations()

TypeScript/npm:

  • computeDocumentHash()
  • createExternalAnnotationSet()
  • validateExternalAnnotations()
  • convertDocxToHtmlWithExternalAnnotations()
  • searchTextOffsets()

Label Display Modes

Mode Description
Above Superscript label before highlight
Inline Label inline before highlight
Tooltip Label shown on hover
None Highlight only, no label

Test plan

  • 21 C# unit tests for core functionality (hash, create, validate, serialize, project)
  • 11 Playwright browser tests for WASM integration
  • Visual demo test shows annotations + JSON panel with hover interactions
  • Full test suite passes (dotnet test + npx playwright test)

Screenshots

The visual demo shows:

  • Document with colored annotation highlights
  • Side panel with raw annotation JSON
  • Tooltips on hover
  • JSON highlighting on annotation hover

Closes #57

Add a parallel annotation system that stores annotations externally as
JSON without modifying the source DOCX file. Annotations are validated
against a SHA256 document hash and projected onto HTML during rendering.

Core components:
- ExternalAnnotationSet: extends OpenContractDocExport with document
  binding (documentId, documentHash, timestamps, label definitions)
- ExternalAnnotationManager: hash computation, annotation creation from
  offsets or text search, validation, JSON serialization
- ExternalAnnotationProjector: projects annotations onto HTML as styled
  spans with configurable label modes (Above, Inline, Tooltip, None)

WASM layer:
- AOT-safe JSON deserialization using source-generated JsonContext
- camelCase property naming for JavaScript interop
- JSExport methods: ComputeDocumentHash, CreateExternalAnnotationSet,
  ValidateExternalAnnotations, ConvertDocxToHtmlWithExternalAnnotations,
  SearchTextOffsets

TypeScript/npm:
- Full type definitions for external annotation types
- Wrapper functions matching WASM exports
- Client-side helpers for annotation creation
- Test harness with external annotation API

Testing:
- 21 C# unit tests for core functionality
- 11 Playwright browser tests including visual demo
- Visual demo renders document with annotations and JSON panel

Closes #57
@JSv4 JSv4 force-pushed the feature/external-annotations-issue-57 branch from 084e645 to 3250f93 Compare December 5, 2025 08:29
@JSv4 JSv4 merged commit 88e88b5 into main Dec 5, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: External annotation storage and projection system

1 participant