@polycrest/document-core
v0.4.0
Published
Framework-neutral structured document model, operations, validation, and agent context. Zero runtime dependencies.
Readme
@polycrest/document-core
The public component + agent API surface: canonical StructuredDocument
model with stable IDs, styles, element policies, commands,
DocumentChangeSet operations with typed conflicts, structural validation, a
pure JSON reference implementation of change-set application (the parity
oracle), queries/outline/search, and semantic agent context.
Framework-neutral. Zero runtime dependencies. No editor-engine type ever appears here.
import {
applyChangeSetToDocument, // pure apply — the reference semantics
validateChangeSet, // dry-run of the same engine
createChangeSet, normalizeChangeSetIds,
createSeededIdGenerator, createRandomIdGenerator,
createAgentContext, getOutline, searchDocument,
type StructuredDocument, type DocumentChangeSet, type DocumentEditor,
} from "@polycrest/document-core";Key rules encoded here:
- move/edit preserve node IDs; copies mint new IDs +
copiedFromId - change sets are all-or-nothing; conflicts are typed, never silent
- text offsets are UTF-16 units over a block's concatenated plain text
expectedText/expectedRegionRevisionguard edits of existing content
